minor
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / navigator / handler / RemotingChangeAcceptedTaxonToSynonymHandler.java
1 /**
2 *
3 */
4 package eu.etaxonomy.taxeditor.navigation.navigator.handler;
5
6 import java.util.ArrayList;
7 import java.util.List;
8 import java.util.UUID;
9
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;
17
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;
25
26 /**
27 * <p>ChangeAcceptedTaxonToSynonymHandler class.</p>
28 *
29 * @author n.hoffmann
30 * @created Jan 4, 2010
31 * @version 1.0
32 */
33 public class RemotingChangeAcceptedTaxonToSynonymHandler extends RemotingCdmHandler {
34
35 private static final Logger logger = Logger
36 .getLogger(RemotingChangeAcceptedTaxonToSynonymHandler.class);
37
38
39 private TaxonNode oldTaxonNode;
40
41 /**
42 * @param label
43 */
44 public RemotingChangeAcceptedTaxonToSynonymHandler() {
45 super(TaxonNavigatorLabels.CHANGE_ACCEPTED_TAXON_TO_SYNONYM_LABEL);
46 }
47 /* (non-Javadoc)
48 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#allowOperations(org.eclipse.core.commands.ExecutionEvent)
49 */
50 @Override
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);
58 }
59
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);
65 }
66
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;
71 } else {
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);
76 }
77 return new Status(IStatus.ERROR,
78 "unknown", //$NON-NLS-1$
79 TaxonNavigatorLabels.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE);
80 }
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);
86
87 }
88
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);
95 }
96
97 return Status.OK_STATUS;
98 }
99 /* (non-Javadoc)
100 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#doOperations(org.eclipse.core.commands.ExecutionEvent)
101 */
102 @Override
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,
109 excludeTaxa,
110 oldTaxonNode,
111 oldTaxonNode.getClassification());
112
113 if (newAcceptedTaxonNode == null) {
114 return null;
115 }
116
117 RemotingChangeAcceptedTaxonToSynonymOperation rcattso =
118 new RemotingChangeAcceptedTaxonToSynonymOperation(event.getTrigger(),
119 false,
120 oldTaxonNode.getUuid(),
121 newAcceptedTaxonNode.getUuid());
122
123 return rcattso;
124 }
125
126 /* (non-Javadoc)
127 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#onComplete(org.eclipse.core.commands.ExecutionEvent)
128 */
129 @Override
130 public void onComplete() {
131 // TODO Auto-generated method stub
132
133 }
134
135
136
137
138 }