Project

General

Profile

Download (4.33 KB) Statistics
| Branch: | Tag: | Revision:
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.e4.handler;
10

    
11
import org.eclipse.core.commands.operations.AbstractOperation;
12
import org.eclipse.core.runtime.IStatus;
13
import org.eclipse.core.runtime.Status;
14
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
15
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
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.swt.widgets.Shell;
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.taxeditor.model.AbstractUtility;
25
import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigatorLabels;
26
import eu.etaxonomy.taxeditor.navigation.navigator.operation.SetSecundumForSubtreeOperation;
27
import eu.etaxonomy.taxeditor.operation.e4.RemotingCdmHandlerE4;
28
import eu.etaxonomy.taxeditor.ui.dialog.configurator.SetSecundumForSubtreeConfigurationWizard;
29

    
30
/**
31
 * @author k.luther
32
 * @author pplitzner
33
 * @date 10.02.2017
34
 *
35
 */
36
public class SetSecReferenceForSubtreeHandlerE4 extends RemotingCdmHandlerE4 {
37

    
38
       private ITaxonTreeNode taxonNode;
39
       private SetSecundumForSubtreeConfigurator configurator;
40

    
41
       public SetSecReferenceForSubtreeHandlerE4() {
42
           super(TaxonNavigatorLabels.CHANGE_SECUNDUM_FOR_SUBTREE);
43
       }
44

    
45
       @Override
46
       public IStatus allowOperations(TreeSelection selection,
47
               Shell shell,
48
               MPart activePart,
49
               MHandledMenuItem menuItem) {
50
           // check that only a single taxon tree node has been selected
51
           if(selection.size() > 1) {  }
52

    
53
           // check for no taxon tree node selected
54
           if(selection.size() == 0) {
55
               return new Status(IStatus.ERROR,
56
                       "unknown", //$NON-NLS-1$
57
                       TaxonNavigatorLabels.NO_TAXON_SELECTION_MESSAGE);
58
           }
59

    
60
           // check that selected object is a taxon node
61
           Object obj = selection.iterator().next();
62
           if(obj instanceof ITaxonTreeNode) {
63
               if (obj instanceof Classification){
64
                   taxonNode = ((Classification)obj).getRootNode();
65
               }else{
66
                   taxonNode = (ITaxonTreeNode)obj;
67
               }
68
          } else{
69
               return new Status(IStatus.ERROR,
70
                       "unknown", //$NON-NLS-1$
71
                       TaxonNavigatorLabels.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE);
72
           }
73

    
74

    
75
           // check if corresponding name editor is closed
76
           //FIXME E4 migrate
77
//           boolean editorClosed = NavigatorHandlerUtils.closeObsoleteEditor(event, (TaxonNode) taxonNode);
78
//           if(editorClosed != true) {
79
//               return new Status(IStatus.ERROR,
80
//                       "unknown", //$NON-NLS-1$
81
//                       TaxonNavigatorLabels.RELATED_EDITOR_NOT_CLOSED_MESSAGE);
82
//           }
83

    
84
           configurator = new SetSecundumForSubtreeConfigurator(taxonNode.getUuid());
85
           SetSecundumForSubtreeConfigurationWizard wizard = new SetSecundumForSubtreeConfigurationWizard(configurator);
86

    
87
           WizardDialog dialog = new WizardDialog(AbstractUtility.getShell(), wizard);
88

    
89
           if (dialog.open() == Window.OK) {
90
              return Status.OK_STATUS;
91
           }else{
92
               return Status.CANCEL_STATUS;
93
           }
94

    
95
       }
96

    
97
       @Override
98
       public AbstractOperation prepareOperation(TreeSelection selection,
99
               Shell shell,
100
               MPart activePart,
101
               MHandledMenuItem menuItem) {
102
          SetSecundumForSubtreeOperation operation =
103
                   new SetSecundumForSubtreeOperation(getTrigger(),
104
                           false,
105
                           taxonNode.getUuid(),
106
                           configurator);
107

    
108
           return operation;
109
       }
110

    
111
       @Override
112
       public void onComplete() {
113
       }
114

    
115
       /**
116
     * {@inheritDoc}
117
     */
118
    @Override
119
    protected Object getTrigger() {
120
        return this;
121
    }
122

    
123
}
(11-11/11)