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
.l10n
.Messages
;
28 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.TaxonNavigatorLabels
;
29 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.TreeNodeDropAdapter
.MovingType
;
30 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.operation
.RemotingMoveTaxonOperation
;
31 import eu
.etaxonomy
.taxeditor
.operation
.RemotingCdmHandler
;
32 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
33 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.TaxonNodeSelectionDialog
;
40 public class RemotingMoveTaxonNodeHandler
extends RemotingCdmHandler
{
42 private TaxonNode oldTaxonNode
;
44 public RemotingMoveTaxonNodeHandler() {
45 super(TaxonNavigatorLabels
.MOVE_TAXON_LABEL
);
49 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#allowOperations(org.eclipse.core.commands.ExecutionEvent)
52 public IStatus
allowOperations(ExecutionEvent event
) {
53 TreeSelection selection
= (TreeSelection
) HandlerUtil
.getCurrentSelection(event
);
54 // check that only a single taxon tree node has been selected
55 if(selection
.size() > 1) {
56 return new Status(IStatus
.ERROR
,
57 "unknown", //$NON-NLS-1$
58 TaxonNavigatorLabels
.SINGLE_TAXON_SELECTION_MESSAGE
);
61 // check for no taxon tree node selected
62 if(selection
.size() == 0) {
63 return new Status(IStatus
.ERROR
,
64 "unknown", //$NON-NLS-1$
65 TaxonNavigatorLabels
.NO_TAXON_SELECTION_MESSAGE
);
67 // check that selected object is a taxon node
68 Object obj
= selection
.iterator().next();
69 if(obj
instanceof TaxonNode
) {
70 oldTaxonNode
= (TaxonNode
)obj
;
72 return new Status(IStatus
.ERROR
,
73 "unknown", //$NON-NLS-1$
74 TaxonNavigatorLabels
.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE
);
76 return Status
.OK_STATUS
;
81 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#prepareOperation(org.eclipse.core.commands.ExecutionEvent)
84 public AbstractOperation
prepareOperation(ExecutionEvent event
) {
85 Shell activeShell
= HandlerUtil
.getActiveShell(event
);
86 TaxonNode parentTaxonNode
;
88 List
<UUID
> excludeTaxa
= new ArrayList
<UUID
>();
89 excludeTaxa
.add(oldTaxonNode
.getTaxon().getUuid());
91 MovingType moveToNewParent
= MovingType
.CHILD
;
93 if (PreferencesUtil
.getSortNodesNaturally()){
96 parentTaxonNode
= TaxonNodeSelectionDialog
.select(activeShell
,
97 new ConversationHolderMock(),
98 Messages
.RemotingMoveTaxonNodeHandler_CHOOSE_TAXON
,
101 oldTaxonNode
.getClassification());
102 String
[] buttonLables
= {Messages
.RemotingMoveTaxonNodeHandler_CHILD
, Messages
.RemotingMoveTaxonNodeHandler_BEHIND
,Messages
.RemotingMoveTaxonNodeHandler_CANCEL
};
103 MessageDialog dialog
= new MessageDialog(null, Messages
.RemotingMoveTaxonNodeHandler_TARGET_NODE
, null, Messages
.RemotingMoveTaxonNodeHandler_TARGET_NODE_MESSAGE
, MessageDialog
.QUESTION_WITH_CANCEL
, buttonLables
, 0);
105 int returnCode
= dialog
.getReturnCode();
106 if (returnCode
== 0){
107 moveToNewParent
= MovingType
.CHILD
;
108 } else if (returnCode
== 1){
109 moveToNewParent
= MovingType
.BEHIND
;
112 parentTaxonNode
= TaxonNodeSelectionDialog
.select(activeShell
,
113 new ConversationHolderMock(),
114 Messages
.RemotingMoveTaxonNodeHandler_CHOOSE_PARENT
,
117 oldTaxonNode
.getClassification());
121 if(parentTaxonNode
!= null){
122 if(NavigationUtil
.isDirty(parentTaxonNode
)){
123 MessageDialog
.openWarning(activeShell
,
124 Messages
.RemotingMoveTaxonNodeHandler_UNSAVED_PARENT
,
125 Messages
.RemotingMoveTaxonNodeHandler_UNSAVED_PARENT_MESSAGE
);
129 return new RemotingMoveTaxonOperation(event
.getTrigger(),
131 oldTaxonNode
.getUuid(),
132 parentTaxonNode
.getUuid(),
140 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#onComplete()
143 public void onComplete() {
144 // TODO Auto-generated method stub