3 * Copyright (C) 2015 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.navigation
.navigator
.handler
;
12 import java
.util
.ArrayList
;
13 import java
.util
.List
;
14 import java
.util
.UUID
;
16 import org
.eclipse
.core
.commands
.ExecutionEvent
;
17 import org
.eclipse
.core
.commands
.operations
.AbstractOperation
;
18 import org
.eclipse
.core
.runtime
.IStatus
;
19 import org
.eclipse
.core
.runtime
.Status
;
20 import org
.eclipse
.jface
.viewers
.TreeSelection
;
21 import org
.eclipse
.swt
.widgets
.Display
;
22 import org
.eclipse
.ui
.PartInitException
;
23 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
25 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolderMock
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.ITaxonTreeNode
;
27 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
28 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
29 import eu
.etaxonomy
.taxeditor
.editor
.MultiPageTaxonEditor
;
30 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
31 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
32 import eu
.etaxonomy
.taxeditor
.navigation
.NavigationUtil
;
33 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.TaxonNavigatorLabels
;
34 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.operation
.RemotingMoveFactualDataOperation
;
35 import eu
.etaxonomy
.taxeditor
.operation
.RemotingCdmHandler
;
36 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.TaxonNodeSelectionDialog
;
43 public class RemotingMoveFactualDataHandler
extends RemotingCdmHandler
{
46 private TaxonNode sourceTaxonNode
;
47 private TaxonNode targetTaxonNode
;
51 public RemotingMoveFactualDataHandler() {
52 super(TaxonNavigatorLabels
.MOVE_FACTUAL_DATA_LABEL
);
56 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#allowOperations(org.eclipse.core.commands.ExecutionEvent)
59 public IStatus
allowOperations(ExecutionEvent event
) {
60 TreeSelection selection
= (TreeSelection
) HandlerUtil
.getCurrentSelection(event
);
61 // check that only a single taxon tree node has been selected
62 if(selection
.size() > 1) {
63 return new Status(IStatus
.ERROR
,
65 TaxonNavigatorLabels
.SINGLE_TAXON_SELECTION_MESSAGE
);
68 // check for no taxon tree node selected
69 if(selection
.size() == 0) {
70 return new Status(IStatus
.ERROR
,
72 TaxonNavigatorLabels
.NO_TAXON_SELECTION_MESSAGE
);
75 // check that selected object is a taxon node
76 Object obj
= selection
.iterator().next();
77 if(obj
instanceof ITaxonTreeNode
) {
78 sourceTaxonNode
= (TaxonNode
)obj
;
80 return new Status(IStatus
.ERROR
,
82 TaxonNavigatorLabels
.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE
);
85 if(NavigationUtil
.isDirty(sourceTaxonNode
)) {
86 return new Status(IStatus
.ERROR
,
88 TaxonNavigatorLabels
.UNSAVED_CHANGES_MESSAGE
);
91 List
<UUID
> excludeTaxa
= new ArrayList
<UUID
>();
92 excludeTaxa
.add(sourceTaxonNode
.getTaxon().getUuid());
94 targetTaxonNode
= TaxonNodeSelectionDialog
.select(HandlerUtil
.getActiveShell(event
),
95 new ConversationHolderMock(),
96 "Choose the accepted taxon",
99 sourceTaxonNode
.getClassification());
101 if(targetTaxonNode
== null) {
102 return new Status(IStatus
.CANCEL
,
106 if(NavigationUtil
.isDirty(targetTaxonNode
)){
107 return new Status(IStatus
.ERROR
,
109 TaxonNavigatorLabels
.UNSAVED_CHANGES_MESSAGE
);
111 return Status
.OK_STATUS
;
115 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#prepareOperation(org.eclipse.core.commands.ExecutionEvent)
118 public AbstractOperation
prepareOperation(ExecutionEvent event
) {
119 return new RemotingMoveFactualDataOperation(event
.getTrigger(),
121 sourceTaxonNode
.getTaxon().getUuid(),
122 targetTaxonNode
.getTaxon().getUuid());
126 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#onComplete()
129 public void onComplete() {
130 Display
.getDefault().asyncExec(new Runnable(){
134 //close and re-open to refresh factual data view
135 MultiPageTaxonEditor sourceEditor
= (MultiPageTaxonEditor
) EditorUtil
.findEditorByTaxonNodeUuid(sourceTaxonNode
.getUuid());
136 MultiPageTaxonEditor targetEditor
= (MultiPageTaxonEditor
) EditorUtil
.findEditorByTaxonNodeUuid(targetTaxonNode
.getUuid());
137 if(targetEditor
!= null){
138 AbstractUtility
.close(sourceEditor
);
139 AbstractUtility
.close(targetEditor
);
141 EditorUtil
.openTaxonNode(sourceTaxonNode
.getUuid());
142 EditorUtil
.openTaxonNode(targetTaxonNode
.getUuid());
143 } catch (PartInitException e
) {
144 MessagingUtils
.error(this.getClass(), e
);
145 throw new RuntimeException(e
);
146 } catch (Exception e
) {
147 MessagingUtils
.warningDialog("Could not create Taxon", this, e
.getMessage());