Merge branch 'release/4.7.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / navigator / handler / SetSecReferenceForSubtreeHandler.java
1 /**
2 * Copyright (C) 2017 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9 package eu.etaxonomy.taxeditor.navigation.navigator.handler;
10
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;
20
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;
30
31 /**
32 * @author k.luther
33 * @date 10.02.2017
34 *
35 */
36 public class SetSecReferenceForSubtreeHandler extends RemotingCdmHandler {
37
38 private static final Logger logger = Logger
39 .getLogger(SetSecReferenceForSubtreeHandler.class);
40
41
42 private ITaxonTreeNode taxonNode;
43 private SetSecundumForSubtreeConfigurator configurator;
44
45 /**
46 * @param label
47 */
48 public SetSecReferenceForSubtreeHandler() {
49 super(TaxonNavigatorLabels.CHANGE_SECUNDUM_FOR_SUBTREE);
50 }
51 /* (non-Javadoc)
52 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#allowOperations(org.eclipse.core.commands.ExecutionEvent)
53 */
54 @Override
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) { }
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 ITaxonTreeNode) {
70 if (obj instanceof Classification){
71 taxonNode = ((Classification)obj).getRootNode();
72 }else{
73 taxonNode = (ITaxonTreeNode)obj;
74 }
75 } else{
76 return new Status(IStatus.ERROR,
77 "unknown", //$NON-NLS-1$
78 TaxonNavigatorLabels.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE);
79 }
80
81
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);
88 }
89
90 configurator = new SetSecundumForSubtreeConfigurator(taxonNode.getUuid());
91 SetSecundumForSubtreeConfigurationWizard wizard = new SetSecundumForSubtreeConfigurationWizard(configurator);
92
93 WizardDialog dialog = new WizardDialog(StoreUtil.getShell(), wizard);
94
95 if (dialog.open() == Window.OK) {
96 return Status.OK_STATUS;
97 }else{
98 return Status.CANCEL_STATUS;
99 }
100
101 // if(!SetSecundumForSubtreeConfigurationWizard.openConfirmWithConfigurator(configurator)){
102 //
103 // return Status.CANCEL_STATUS;
104 // }
105 //
106 //
107 // return Status.OK_STATUS;
108 }
109 /* (non-Javadoc)
110 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#doOperations(org.eclipse.core.commands.ExecutionEvent)
111 */
112 @Override
113 public AbstractOperation prepareOperation(ExecutionEvent event) {
114 SetSecundumForSubtreeOperation operation =
115 new SetSecundumForSubtreeOperation(event.getTrigger(),
116 false,
117 taxonNode.getUuid(),
118 configurator);
119
120 return operation;
121 }
122
123 /* (non-Javadoc)
124 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#onComplete(org.eclipse.core.commands.ExecutionEvent)
125 */
126 @Override
127 public void onComplete() {
128 // TODO Auto-generated method stub
129
130 }
131
132
133
134
135
136
137 }