Project

General

Profile

Download (4.66 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 javax.inject.Named;
12

    
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.e4.core.di.annotations.CanExecute;
17
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
18
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
19
import org.eclipse.e4.ui.services.IServiceConstants;
20
import org.eclipse.jface.viewers.TreeSelection;
21
import org.eclipse.jface.window.Window;
22
import org.eclipse.jface.wizard.WizardDialog;
23
import org.eclipse.swt.widgets.Shell;
24

    
25
import eu.etaxonomy.cdm.io.common.SetSecundumForSubtreeConfigurator;
26
import eu.etaxonomy.cdm.model.taxon.Classification;
27
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
28
import eu.etaxonomy.taxeditor.model.AbstractUtility;
29
import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigatorLabels;
30
import eu.etaxonomy.taxeditor.navigation.navigator.operation.SetSecundumForSubtreeOperation;
31
import eu.etaxonomy.taxeditor.operation.e4.RemotingCdmHandlerE4;
32
import eu.etaxonomy.taxeditor.ui.dialog.configurator.SetSecundumForSubtreeConfigurationWizard;
33

    
34
/**
35
 * @author k.luther
36
 * @author pplitzner
37
 * @date 10.02.2017
38
 *
39
 */
40
public class SetSecReferenceForSubtreeHandlerE4 extends RemotingCdmHandlerE4 {
41

    
42
       private ITaxonTreeNode taxonNode;
43
       private SetSecundumForSubtreeConfigurator configurator;
44

    
45
       public SetSecReferenceForSubtreeHandlerE4() {
46
           super(TaxonNavigatorLabels.CHANGE_SECUNDUM_FOR_SUBTREE);
47
       }
48

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

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

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

    
78

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

    
88
           configurator = new SetSecundumForSubtreeConfigurator(taxonNode.getUuid());
89
           SetSecundumForSubtreeConfigurationWizard wizard = new SetSecundumForSubtreeConfigurationWizard(configurator);
90

    
91
           WizardDialog dialog = new WizardDialog(AbstractUtility.getShell(), wizard);
92

    
93
           if (dialog.open() == Window.OK) {
94
              return Status.OK_STATUS;
95
           }else{
96
               return Status.CANCEL_STATUS;
97
           }
98
       }
99

    
100
       @CanExecute
101
       private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection){
102
           return selection.getFirstElement() instanceof ITaxonTreeNode;
103
       }
104

    
105
       @Override
106
       public AbstractOperation prepareOperation(TreeSelection selection,
107
               Shell shell,
108
               MPart activePart,
109
               MHandledMenuItem menuItem) {
110
          SetSecundumForSubtreeOperation operation =
111
                   new SetSecundumForSubtreeOperation(getTrigger(),
112
                           false,
113
                           taxonNode.getUuid(),
114
                           configurator);
115

    
116
           return operation;
117
       }
118

    
119
       @Override
120
       public void onComplete() {
121
       }
122

    
123
       /**
124
     * {@inheritDoc}
125
     */
126
    @Override
127
    protected Object getTrigger() {
128
        return this;
129
    }
130

    
131
}
(11-11/11)