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
.viewers
.TreeSelection
;
20 import org
.eclipse
.swt
.widgets
.Display
;
21 import org
.eclipse
.ui
.PartInitException
;
22 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
24 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolderMock
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.ITaxonTreeNode
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
27 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
28 import eu
.etaxonomy
.taxeditor
.editor
.MultiPageTaxonEditor
;
29 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
30 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
31 import eu
.etaxonomy
.taxeditor
.navigation
.NavigationUtil
;
32 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.TaxonNavigatorLabels
;
33 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.operation
.RemotingMoveFactualDataOperation
;
34 import eu
.etaxonomy
.taxeditor
.operation
.RemotingCdmHandler
;
35 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.TaxonNodeSelectionDialog
;
42 public class RemotingMoveFactualDataHandler
extends RemotingCdmHandler
{
45 private TaxonNode sourceTaxonNode
;
46 private TaxonNode targetTaxonNode
;
50 public RemotingMoveFactualDataHandler() {
51 super(TaxonNavigatorLabels
.MOVE_FACTUAL_DATA_LABEL
);
55 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#allowOperations(org.eclipse.core.commands.ExecutionEvent)
58 public IStatus
allowOperations(ExecutionEvent event
) {
59 TreeSelection selection
= (TreeSelection
) HandlerUtil
.getCurrentSelection(event
);
60 // check that only a single taxon tree node has been selected
61 if(selection
.size() > 1) {
62 return new Status(IStatus
.ERROR
,
64 TaxonNavigatorLabels
.SINGLE_TAXON_SELECTION_MESSAGE
);
67 // check for no taxon tree node selected
68 if(selection
.size() == 0) {
69 return new Status(IStatus
.ERROR
,
71 TaxonNavigatorLabels
.NO_TAXON_SELECTION_MESSAGE
);
74 // check that selected object is a taxon node
75 Object obj
= selection
.iterator().next();
76 if(obj
instanceof ITaxonTreeNode
) {
77 sourceTaxonNode
= (TaxonNode
)obj
;
79 return new Status(IStatus
.ERROR
,
81 TaxonNavigatorLabels
.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE
);
84 if(NavigationUtil
.isDirty(sourceTaxonNode
)) {
85 return new Status(IStatus
.ERROR
,
87 TaxonNavigatorLabels
.UNSAVED_CHANGES_MESSAGE
);
90 List
<UUID
> excludeTaxa
= new ArrayList
<UUID
>();
91 excludeTaxa
.add(sourceTaxonNode
.getTaxon().getUuid());
93 targetTaxonNode
= TaxonNodeSelectionDialog
.select(HandlerUtil
.getActiveShell(event
),
94 new ConversationHolderMock(),
95 "Choose the accepted taxon",
98 sourceTaxonNode
.getClassification());
100 if(targetTaxonNode
== null) {
101 return new Status(IStatus
.CANCEL
,
105 if(NavigationUtil
.isDirty(targetTaxonNode
)){
106 return new Status(IStatus
.ERROR
,
108 TaxonNavigatorLabels
.UNSAVED_CHANGES_MESSAGE
);
110 return Status
.OK_STATUS
;
114 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#prepareOperation(org.eclipse.core.commands.ExecutionEvent)
117 public AbstractOperation
prepareOperation(ExecutionEvent event
) {
118 return new RemotingMoveFactualDataOperation(event
.getTrigger(),
120 sourceTaxonNode
.getTaxon().getUuid(),
121 targetTaxonNode
.getTaxon().getUuid());
125 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#onComplete()
128 public void onComplete() {
129 Display
.getDefault().asyncExec(new Runnable(){
133 //close and re-open to refresh factual data view
134 MultiPageTaxonEditor sourceEditor
= (MultiPageTaxonEditor
) EditorUtil
.findEditorByTaxonNodeUuid(sourceTaxonNode
.getUuid());
135 MultiPageTaxonEditor targetEditor
= (MultiPageTaxonEditor
) EditorUtil
.findEditorByTaxonNodeUuid(targetTaxonNode
.getUuid());
136 if(targetEditor
!= null){
137 AbstractUtility
.close(sourceEditor
);
138 AbstractUtility
.close(targetEditor
);
140 EditorUtil
.openTaxonNode(sourceTaxonNode
.getUuid());
141 EditorUtil
.openTaxonNode(targetTaxonNode
.getUuid());
142 } catch (PartInitException e
) {
143 MessagingUtils
.error(this.getClass(), e
);
144 throw new RuntimeException(e
);
145 } catch (Exception e
) {
146 MessagingUtils
.warningDialog("Could not create Taxon", this, e
.getMessage());