Project

General

Profile

Download (4.91 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.handler;
10

    
11
import java.util.ArrayList;
12
import java.util.List;
13
import java.util.UUID;
14

    
15
import org.apache.log4j.Logger;
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.jface.window.Window;
22
import org.eclipse.jface.wizard.WizardDialog;
23
import org.eclipse.ui.handlers.HandlerUtil;
24

    
25
import eu.etaxonomy.cdm.api.service.config.SetSecundumForSubtreeConfigurator;
26
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
27
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
28
import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigatorLabels;
29
import eu.etaxonomy.taxeditor.navigation.navigator.operation.SetSecundumForSubtreeOperation;
30
import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler;
31
import eu.etaxonomy.taxeditor.store.StoreUtil;
32
import eu.etaxonomy.taxeditor.ui.dialog.configurator.SetSecundumForSubtreeConfigurationWizard;
33

    
34
/**
35
 * @author k.luther
36
 * @date 10.02.2017
37
 *
38
 */
39
public class SetSecReferenceForSubtreeHandler extends RemotingCdmHandler {
40

    
41
       private static final Logger logger = Logger
42
               .getLogger(SetSecReferenceForSubtreeHandler.class);
43

    
44

    
45
       private ITaxonTreeNode taxonNode;
46
       private SetSecundumForSubtreeConfigurator configurator;
47

    
48
       /**
49
        * @param label
50
        */
51
       public SetSecReferenceForSubtreeHandler() {
52
           super(TaxonNavigatorLabels.CHANGE_SECUNDUM_FOR_SUBTREE);
53
       }
54
       /* (non-Javadoc)
55
        * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#allowOperations(org.eclipse.core.commands.ExecutionEvent)
56
        */
57
       @Override
58
       public IStatus allowOperations(ExecutionEvent event) {
59
           TreeSelection selection = (TreeSelection) HandlerUtil.getCurrentSelection(event);
60
           // check that only a single taxon tree node has been selected
61
           if(selection.size() > 1) {  }
62

    
63
           // check for no taxon tree node selected
64
           if(selection.size() == 0) {
65
               return new Status(IStatus.ERROR,
66
                       "unknown", //$NON-NLS-1$
67
                       TaxonNavigatorLabels.NO_TAXON_SELECTION_MESSAGE);
68
           }
69

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

    
80

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

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

    
92
           WizardDialog dialog = new WizardDialog(StoreUtil.getShell(), wizard);
93

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

    
100
//           if(!SetSecundumForSubtreeConfigurationWizard.openConfirmWithConfigurator(configurator)){
101
//
102
//               return Status.CANCEL_STATUS;
103
//           }
104
//
105
//
106
//           return Status.OK_STATUS;
107
       }
108
       /* (non-Javadoc)
109
        * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#doOperations(org.eclipse.core.commands.ExecutionEvent)
110
        */
111
       @Override
112
       public AbstractOperation prepareOperation(ExecutionEvent event) {
113
           List<UUID> excludeTaxa = new ArrayList<UUID>();
114
           excludeTaxa.add(((TaxonNode)taxonNode).getTaxon().getUuid());
115

    
116

    
117

    
118

    
119
           SetSecundumForSubtreeOperation operation =
120
                   new SetSecundumForSubtreeOperation(event.getTrigger(),
121
                           false,
122
                           taxonNode.getUuid(),
123
                           configurator);
124

    
125
           return operation;
126
       }
127

    
128
       /* (non-Javadoc)
129
        * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#onComplete(org.eclipse.core.commands.ExecutionEvent)
130
        */
131
       @Override
132
       public void onComplete() {
133
           // TODO Auto-generated method stub
134

    
135
       }
136

    
137

    
138

    
139

    
140

    
141

    
142
}
(16-16/17)