2 * Copyright (C) 2015 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.taxeditor
.navigation
.navigator
.handler
;
11 import java
.util
.ArrayList
;
12 import java
.util
.List
;
13 import java
.util
.UUID
;
15 import org
.eclipse
.core
.commands
.ExecutionEvent
;
16 import org
.eclipse
.core
.commands
.operations
.AbstractOperation
;
17 import org
.eclipse
.core
.runtime
.IStatus
;
18 import org
.eclipse
.core
.runtime
.Status
;
19 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
20 import org
.eclipse
.jface
.viewers
.TreeSelection
;
21 import org
.eclipse
.swt
.widgets
.Shell
;
22 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
24 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolderMock
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
26 import eu
.etaxonomy
.taxeditor
.navigation
.NavigationUtil
;
27 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.TaxonNavigatorLabels
;
28 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.TreeNodeDropAdapter
.MovingType
;
29 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.operation
.RemotingMoveTaxonOperation
;
30 import eu
.etaxonomy
.taxeditor
.operation
.RemotingCdmHandler
;
31 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
32 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.TaxonNodeSelectionDialog
;
39 public class RemotingMoveTaxonNodeHandler
extends RemotingCdmHandler
{
41 private TaxonNode oldTaxonNode
;
43 public RemotingMoveTaxonNodeHandler() {
44 super(TaxonNavigatorLabels
.MOVE_TAXON_LABEL
);
48 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#allowOperations(org.eclipse.core.commands.ExecutionEvent)
51 public IStatus
allowOperations(ExecutionEvent event
) {
52 TreeSelection selection
= (TreeSelection
) HandlerUtil
.getCurrentSelection(event
);
53 // check that only a single taxon tree node has been selected
54 if(selection
.size() > 1) {
55 return new Status(IStatus
.ERROR
,
57 TaxonNavigatorLabels
.SINGLE_TAXON_SELECTION_MESSAGE
);
60 // check for no taxon tree node selected
61 if(selection
.size() == 0) {
62 return new Status(IStatus
.ERROR
,
64 TaxonNavigatorLabels
.NO_TAXON_SELECTION_MESSAGE
);
66 // check that selected object is a taxon node
67 Object obj
= selection
.iterator().next();
68 if(obj
instanceof TaxonNode
) {
69 oldTaxonNode
= (TaxonNode
)obj
;
71 return new Status(IStatus
.ERROR
,
73 TaxonNavigatorLabels
.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE
);
75 return Status
.OK_STATUS
;
80 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#prepareOperation(org.eclipse.core.commands.ExecutionEvent)
83 public AbstractOperation
prepareOperation(ExecutionEvent event
) {
84 Shell activeShell
= HandlerUtil
.getActiveShell(event
);
85 TaxonNode parentTaxonNode
;
87 List
<UUID
> excludeTaxa
= new ArrayList
<UUID
>();
88 excludeTaxa
.add(oldTaxonNode
.getTaxon().getUuid());
90 MovingType moveToNewParent
= MovingType
.CHILD
;
92 if (PreferencesUtil
.getSortNodesNaturally()){
95 parentTaxonNode
= TaxonNodeSelectionDialog
.select(activeShell
,
96 new ConversationHolderMock(),
97 "Choose the taxon above the moved taxon.",
100 oldTaxonNode
.getClassification());
101 String
[] buttonLables
= {"Child", "Behind","Cancel"};
102 MessageDialog dialog
= new MessageDialog(null, "Target node", null, "Do you want to move the Taxonnode as child or behind the target node.", MessageDialog
.QUESTION_WITH_CANCEL
, buttonLables
, 0);
104 int returnCode
= dialog
.getReturnCode();
105 if (returnCode
== 0){
106 moveToNewParent
= MovingType
.CHILD
;
107 } else if (returnCode
== 1){
108 moveToNewParent
= MovingType
.BEHIND
;
111 parentTaxonNode
= TaxonNodeSelectionDialog
.select(activeShell
,
112 new ConversationHolderMock(),
116 oldTaxonNode
.getClassification());
120 if(parentTaxonNode
!= null){
121 if(NavigationUtil
.isDirty(parentTaxonNode
)){
122 MessageDialog
.openWarning(activeShell
,
123 "Unsaved Parent Taxon",
124 "There are unsaved changes in the parent taxon. Please save first.");
128 return new RemotingMoveTaxonOperation(event
.getTrigger(),
130 oldTaxonNode
.getUuid(),
131 parentTaxonNode
.getUuid(),
139 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#onComplete()
142 public void onComplete() {
143 // TODO Auto-generated method stub