Project

General

Profile

Download (4.85 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2017 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.taxeditor.navigation.navigator.e4.handler;
11

    
12
import java.util.UUID;
13

    
14
import javax.inject.Named;
15

    
16
import org.eclipse.core.commands.operations.AbstractOperation;
17
import org.eclipse.core.runtime.IStatus;
18
import org.eclipse.core.runtime.Status;
19
import org.eclipse.e4.core.di.annotations.CanExecute;
20
import org.eclipse.e4.ui.model.application.MApplication;
21
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
22
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
23
import org.eclipse.e4.ui.services.IServiceConstants;
24
import org.eclipse.e4.ui.workbench.modeling.EPartService;
25
import org.eclipse.jface.viewers.IStructuredSelection;
26
import org.eclipse.jface.viewers.TreeSelection;
27
import org.eclipse.jface.window.Window;
28
import org.eclipse.jface.wizard.WizardDialog;
29
import org.eclipse.swt.widgets.Shell;
30

    
31
import eu.etaxonomy.cdm.api.service.config.PublishForSubtreeConfigurator;
32
import eu.etaxonomy.cdm.model.taxon.Classification;
33
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
34
import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigatorLabels;
35
import eu.etaxonomy.taxeditor.navigation.navigator.operation.SetPublishForSubtreeOperation;
36
import eu.etaxonomy.taxeditor.operation.e4.RemotingCdmHandlerE4;
37
import eu.etaxonomy.taxeditor.ui.dialog.configurator.SetPublishForSubtreeWizard;
38

    
39
/**
40
 * @author k.luther
41
 * @date 11.10.2017
42
 *
43
 */
44
public class SetPublishFlagForSubtreeHandlerE4 extends RemotingCdmHandlerE4 {
45

    
46
    /**
47
     * @param label
48
     */
49
    public SetPublishFlagForSubtreeHandlerE4() {
50
        //FIXME add missing l10n property
51
//        super(TaxonNavigatorLabels.CHANGE_PUBLISH_FOR_SUBTREE);
52
        super("");
53
    }
54

    
55

    
56
    private ITaxonTreeNode taxonNode;
57
    private PublishForSubtreeConfigurator configurator;
58

    
59

    
60
    @Override
61
    public IStatus allowOperations(IStructuredSelection selection, Shell shell, MPart activePart,
62
            MHandledMenuItem menuItem) {
63
     // check that only a single taxon tree node has been selected
64
        if(selection.size() > 1) {  }
65

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

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

    
87

    
88
        // check if corresponding name editor is closed
89
        //FIXME E4 migrate
90
        //           boolean editorClosed = NavigatorHandlerUtils.closeObsoleteEditor(event, (TaxonNode) taxonNode);
91
        //           if(editorClosed != true) {
92
        //               return new Status(IStatus.ERROR,
93
        //                       "unknown", //$NON-NLS-1$
94
        //                       TaxonNavigatorLabels.RELATED_EDITOR_NOT_CLOSED_MESSAGE);
95
        //           }
96

    
97
        configurator = new PublishForSubtreeConfigurator(taxonNode.getUuid());
98
        SetPublishForSubtreeWizard wizard = new SetPublishForSubtreeWizard(configurator);
99

    
100
        WizardDialog dialog = new WizardDialog(shell, wizard);
101

    
102
        if (dialog.open() == Window.OK) {
103
            return Status.OK_STATUS;
104
        }else{
105
            return Status.CANCEL_STATUS;
106
        }
107
    }
108

    
109
    @CanExecute
110
    private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection, MHandledMenuItem menuItem){
111
        boolean canExecute = false;
112
        canExecute = selection.getFirstElement() instanceof ITaxonTreeNode;
113
        menuItem.setVisible(canExecute);
114
        return canExecute;
115
    }
116

    
117

    
118
    @Override
119
    public AbstractOperation prepareOperation(IStructuredSelection selection, Shell shell, MPart activePart,
120
            MHandledMenuItem menuItem) {
121
        SetPublishForSubtreeOperation operation =
122
                new SetPublishForSubtreeOperation(getTrigger(),
123
                        false,
124
                        taxonNode.getUuid(),
125
                        partService,
126
                        activePart,
127
                        application,
128
                        configurator);
129

    
130
        return operation;
131
    }
132

    
133

    
134
    @Override
135
    public void onComplete() {
136

    
137
    }
138

    
139

    
140
    @Override
141
    protected Object getTrigger() {
142
        return this;
143
    }
144

    
145
}
(16-16/17)