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
.TaxonNode
;
20 import eu
.etaxonomy
.taxeditor
.navigation
.l10n
.Messages
;
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 TaxonNode 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
,
56 "unknown", //$NON-NLS-1$
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
,
63 "unknown", //$NON-NLS-1$
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 TaxonNode
&& ((TaxonNode
)obj
).hasTaxon()) {
70 oldTaxonNode
= (TaxonNode
)obj
;
72 if (obj
instanceof TaxonNode
&& !((TaxonNode
)obj
).hasTaxon()){
73 return new Status(IStatus
.ERROR
,
74 "Operation not available for Classifications", //$NON-NLS-1$
75 TaxonNavigatorLabels
.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE
);
77 return new Status(IStatus
.ERROR
,
78 "unknown", //$NON-NLS-1$
79 TaxonNavigatorLabels
.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE
);
81 // check that the source taxon node does not have children
82 if(oldTaxonNode
.getCountChildren() > 0) {
83 return new Status(IStatus
.ERROR
,
84 "unknown", //$NON-NLS-1$
85 TaxonNavigatorLabels
.SOURCE_TAXON_HAS_CHILDREN_MESSAGE
);
89 // check if corresponding name editor is closed
90 boolean editorClosed
= NavigatorHandlerUtils
.closeObsoleteEditor(event
, oldTaxonNode
);
91 if(editorClosed
!= true) {
92 return new Status(IStatus
.ERROR
,
93 "unknown", //$NON-NLS-1$
94 TaxonNavigatorLabels
.RELATED_EDITOR_NOT_CLOSED_MESSAGE
);
97 return Status
.OK_STATUS
;
100 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#doOperations(org.eclipse.core.commands.ExecutionEvent)
103 public AbstractOperation
prepareOperation(ExecutionEvent event
) {
104 List
<UUID
> excludeTaxa
= new ArrayList
<UUID
>();
105 excludeTaxa
.add(oldTaxonNode
.getTaxon().getUuid());
106 TaxonNode newAcceptedTaxonNode
= TaxonNodeSelectionDialog
.select(HandlerUtil
.getActiveShell(event
),
107 new ConversationHolderMock(),
108 Messages
.RemotingChangeAcceptedTaxonToSynonymHandler_CHOOSE_TAXON
,
111 oldTaxonNode
.getClassification());
113 if (newAcceptedTaxonNode
== null) {
117 RemotingChangeAcceptedTaxonToSynonymOperation rcattso
=
118 new RemotingChangeAcceptedTaxonToSynonymOperation(event
.getTrigger(),
120 oldTaxonNode
.getUuid(),
121 newAcceptedTaxonNode
.getUuid());
127 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#onComplete(org.eclipse.core.commands.ExecutionEvent)
130 public void onComplete() {
131 // TODO Auto-generated method stub