3 * Copyright (C) 2015 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.navigation
.navigator
.handler
;
12 import java
.util
.ArrayList
;
13 import java
.util
.List
;
14 import java
.util
.UUID
;
16 import org
.eclipse
.core
.commands
.ExecutionEvent
;
17 import org
.eclipse
.core
.commands
.operations
.AbstractOperation
;
18 import org
.eclipse
.core
.runtime
.IStatus
;
19 import org
.eclipse
.core
.runtime
.Status
;
20 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
21 import org
.eclipse
.jface
.viewers
.TreeSelection
;
22 import org
.eclipse
.swt
.widgets
.Shell
;
23 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
25 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolderMock
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
27 import eu
.etaxonomy
.taxeditor
.navigation
.NavigationUtil
;
28 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.TaxonNavigatorLabels
;
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(((TaxonNode
)oldTaxonNode
).getTaxon().getUuid());
90 boolean moveToNewParent
= true;
92 if (PreferencesUtil
.getSortNodesNaturally()){
93 if(!MessageDialog
.openQuestion(activeShell
, "Target node", "The choosen target node should be the parent?")){
94 moveToNewParent
= false;
96 parentTaxonNode
= TaxonNodeSelectionDialog
.select(activeShell
,
97 new ConversationHolderMock(),
98 "Choose the taxon above the moved taxon.",
103 parentTaxonNode
= TaxonNodeSelectionDialog
.select(activeShell
,
104 new ConversationHolderMock(),
112 if(parentTaxonNode
!= null){
113 if(NavigationUtil
.isDirty(parentTaxonNode
)){
114 MessageDialog
.openWarning(activeShell
,
115 "Unsaved Parent Taxon",
116 "There are unsaved changes in the parent taxon. Please save first.");
120 return new RemotingMoveTaxonOperation(event
.getTrigger(),
122 oldTaxonNode
.getUuid(),
123 parentTaxonNode
.getUuid(),
131 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#onComplete()
134 public void onComplete() {
135 // TODO Auto-generated method stub