2 * Copyright (C) 2017 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 org
.apache
.log4j
.Logger
;
12 import org
.eclipse
.core
.commands
.ExecutionEvent
;
13 import org
.eclipse
.core
.commands
.operations
.AbstractOperation
;
14 import org
.eclipse
.core
.runtime
.IStatus
;
15 import org
.eclipse
.core
.runtime
.Status
;
16 import org
.eclipse
.jface
.viewers
.TreeSelection
;
17 import org
.eclipse
.jface
.window
.Window
;
18 import org
.eclipse
.jface
.wizard
.WizardDialog
;
19 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
21 import eu
.etaxonomy
.cdm
.io
.common
.SetSecundumForSubtreeConfigurator
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.ITaxonTreeNode
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
25 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.TaxonNavigatorLabels
;
26 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.operation
.SetSecundumForSubtreeOperation
;
27 import eu
.etaxonomy
.taxeditor
.operation
.RemotingCdmHandler
;
28 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
29 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.configurator
.SetSecundumForSubtreeConfigurationWizard
;
36 public class SetSecReferenceForSubtreeHandler
extends RemotingCdmHandler
{
38 private static final Logger logger
= Logger
39 .getLogger(SetSecReferenceForSubtreeHandler
.class);
42 private ITaxonTreeNode taxonNode
;
43 private SetSecundumForSubtreeConfigurator configurator
;
48 public SetSecReferenceForSubtreeHandler() {
49 super(TaxonNavigatorLabels
.CHANGE_SECUNDUM_FOR_SUBTREE
);
52 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#allowOperations(org.eclipse.core.commands.ExecutionEvent)
55 public IStatus
allowOperations(ExecutionEvent event
) {
56 TreeSelection selection
= (TreeSelection
) HandlerUtil
.getCurrentSelection(event
);
57 // check that only a single taxon tree node has been selected
58 if(selection
.size() > 1) { }
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 ITaxonTreeNode
) {
70 if (obj
instanceof Classification
){
71 taxonNode
= ((Classification
)obj
).getRootNode();
73 taxonNode
= (ITaxonTreeNode
)obj
;
76 return new Status(IStatus
.ERROR
,
77 "unknown", //$NON-NLS-1$
78 TaxonNavigatorLabels
.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE
);
82 // check if corresponding name editor is closed
83 boolean editorClosed
= NavigatorHandlerUtils
.closeObsoleteEditor(event
, (TaxonNode
) taxonNode
);
84 if(editorClosed
!= true) {
85 return new Status(IStatus
.ERROR
,
86 "unknown", //$NON-NLS-1$
87 TaxonNavigatorLabels
.RELATED_EDITOR_NOT_CLOSED_MESSAGE
);
90 configurator
= new SetSecundumForSubtreeConfigurator(taxonNode
.getUuid());
91 SetSecundumForSubtreeConfigurationWizard wizard
= new SetSecundumForSubtreeConfigurationWizard(configurator
);
93 WizardDialog dialog
= new WizardDialog(StoreUtil
.getShell(), wizard
);
95 if (dialog
.open() == Window
.OK
) {
96 return Status
.OK_STATUS
;
98 return Status
.CANCEL_STATUS
;
101 // if(!SetSecundumForSubtreeConfigurationWizard.openConfirmWithConfigurator(configurator)){
103 // return Status.CANCEL_STATUS;
107 // return Status.OK_STATUS;
110 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#doOperations(org.eclipse.core.commands.ExecutionEvent)
113 public AbstractOperation
prepareOperation(ExecutionEvent event
) {
114 SetSecundumForSubtreeOperation operation
=
115 new SetSecundumForSubtreeOperation(event
.getTrigger(),
124 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#onComplete(org.eclipse.core.commands.ExecutionEvent)
127 public void onComplete() {
128 // TODO Auto-generated method stub