Project

General

Profile

Download (4.53 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.ui.handlers.HandlerUtil;
22

    
23
import eu.etaxonomy.cdm.api.service.config.SetSecundumForSubtreeConfigurator;
24
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
25
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
26
import eu.etaxonomy.taxeditor.editor.Messages;
27
import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigatorLabels;
28
import eu.etaxonomy.taxeditor.navigation.navigator.operation.SetSecundumForSubtreeOperation;
29
import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler;
30
import eu.etaxonomy.taxeditor.ui.dialog.configurator.SetSecundumForSubtreeConfigurationDialog;
31

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

    
39
       private static final Logger logger = Logger
40
               .getLogger(SetSecReferenceForSubtreeHandler.class);
41

    
42

    
43
       private ITaxonTreeNode taxonNode;
44
       private SetSecundumForSubtreeConfigurator configurator;
45

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

    
61
           // check for no taxon tree node selected
62
           if(selection.size() == 0) {
63
               return new Status(IStatus.ERROR,
64
                       "unknown",
65
                       TaxonNavigatorLabels.NO_TAXON_SELECTION_MESSAGE);
66
           }
67

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

    
78

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

    
87
           configurator = new SetSecundumForSubtreeConfigurator(taxonNode.getUuid());
88
           if(!SetSecundumForSubtreeConfigurationDialog.openConfirmWithConfigurator(configurator, HandlerUtil.getActiveShell(event), Messages.SetSecundumHandler_confirm, Messages.SetSecundumHandler_configureSettings)){
89

    
90
               return Status.CANCEL_STATUS;
91
           }
92

    
93

    
94
           return Status.OK_STATUS;
95
       }
96
       /* (non-Javadoc)
97
        * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#doOperations(org.eclipse.core.commands.ExecutionEvent)
98
        */
99
       @Override
100
       public AbstractOperation prepareOperation(ExecutionEvent event) {
101
           List<UUID> excludeTaxa = new ArrayList<UUID>();
102
           excludeTaxa.add(((TaxonNode)taxonNode).getTaxon().getUuid());
103

    
104

    
105

    
106

    
107
           SetSecundumForSubtreeOperation operation =
108
                   new SetSecundumForSubtreeOperation(event.getTrigger(),
109
                           false,
110
                           taxonNode.getUuid(),
111
                           configurator);
112

    
113
           return operation;
114
       }
115

    
116
       /* (non-Javadoc)
117
        * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#onComplete(org.eclipse.core.commands.ExecutionEvent)
118
        */
119
       @Override
120
       public void onComplete() {
121
           // TODO Auto-generated method stub
122

    
123
       }
124

    
125

    
126

    
127

    
128

    
129

    
130
}
(16-16/17)