4 package eu
.etaxonomy
.taxeditor
.navigation
.navigator
.handler
;
6 import java
.util
.ArrayList
;
10 import org
.apache
.log4j
.Logger
;
11 import org
.eclipse
.core
.commands
.ExecutionEvent
;
12 import org
.eclipse
.core
.commands
.operations
.AbstractOperation
;
13 import org
.eclipse
.core
.runtime
.IStatus
;
14 import org
.eclipse
.core
.runtime
.Status
;
15 import org
.eclipse
.jface
.viewers
.TreeSelection
;
16 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
18 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolderMock
;
19 import eu
.etaxonomy
.cdm
.model
.taxon
.ITaxonTreeNode
;
20 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
21 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.TaxonNavigatorLabels
;
22 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.operation
.RemotingChangeAcceptedTaxonToSynonymOperation
;
23 import eu
.etaxonomy
.taxeditor
.operation
.RemotingCdmHandler
;
24 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.TaxonNodeSelectionDialog
;
27 * <p>ChangeAcceptedTaxonToSynonymHandler class.</p>
30 * @created Jan 4, 2010
33 public class RemotingChangeAcceptedTaxonToSynonymHandler
extends RemotingCdmHandler
{
35 private static final Logger logger
= Logger
36 .getLogger(RemotingChangeAcceptedTaxonToSynonymHandler
.class);
39 private ITaxonTreeNode oldTaxonNode
;
44 public RemotingChangeAcceptedTaxonToSynonymHandler() {
45 super(TaxonNavigatorLabels
.CHANGE_ACCEPTED_TAXON_TO_SYNONYM_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
);
67 // check that selected object is a taxon node
68 Object obj
= selection
.iterator().next();
69 if(obj
instanceof ITaxonTreeNode
) {
70 oldTaxonNode
= (ITaxonTreeNode
)obj
;
72 return new Status(IStatus
.ERROR
,
74 TaxonNavigatorLabels
.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE
);
76 // check that the source taxon node does not have children
77 if(((TaxonNode
)oldTaxonNode
).getCountChildren() > 0) {
78 return new Status(IStatus
.ERROR
,
80 TaxonNavigatorLabels
.SOURCE_TAXON_HAS_CHILDREN_MESSAGE
);
84 // check if corresponding name editor is closed
85 boolean editorClosed
= NavigatorHandlerUtils
.closeObsoleteEditor(event
, (TaxonNode
) oldTaxonNode
);
86 if(editorClosed
!= true) {
87 return new Status(IStatus
.ERROR
,
89 TaxonNavigatorLabels
.RELATED_EDITOR_NOT_CLOSED_MESSAGE
);
92 return Status
.OK_STATUS
;
95 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#doOperations(org.eclipse.core.commands.ExecutionEvent)
98 public AbstractOperation
prepareOperation(ExecutionEvent event
) {
99 List
<UUID
> excludeTaxa
= new ArrayList
<UUID
>();
100 excludeTaxa
.add(oldTaxonNode
.getUuid());
101 TaxonNode newAcceptedTaxonNode
= TaxonNodeSelectionDialog
.select(HandlerUtil
.getActiveShell(event
),
102 new ConversationHolderMock(),
103 "Choose the accepted taxon",
106 ((TaxonNode
)oldTaxonNode
).getClassification());
108 if (newAcceptedTaxonNode
== null) {
112 RemotingChangeAcceptedTaxonToSynonymOperation rcattso
=
113 new RemotingChangeAcceptedTaxonToSynonymOperation(event
.getTrigger(),
115 oldTaxonNode
.getUuid(),
116 newAcceptedTaxonNode
.getUuid());
122 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#onComplete(org.eclipse.core.commands.ExecutionEvent)
125 public void onComplete() {
126 // TODO Auto-generated method stub