Project

General

Profile

Download (4.61 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 javax.inject.Named;
13

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

    
27
import eu.etaxonomy.cdm.api.service.config.PublishForSubtreeConfigurator;
28
import eu.etaxonomy.cdm.model.taxon.Classification;
29
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
30
import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigatorLabels;
31
import eu.etaxonomy.taxeditor.navigation.navigator.operation.SetPublishForSubtreeOperation;
32
import eu.etaxonomy.taxeditor.operation.e4.RemotingCdmHandlerE4;
33
import eu.etaxonomy.taxeditor.ui.dialog.configurator.SetPublishForSubtreeWizard;
34

    
35
/**
36
 * @author k.luther
37
 * @date 11.10.2017
38
 *
39
 */
40
public class SetPublishFlagForSubtreeHandlerE4 extends RemotingCdmHandlerE4 {
41

    
42
    /**
43
     * @param label
44
     */
45
    public SetPublishFlagForSubtreeHandlerE4() {
46
        //FIXME add missing l10n property
47
//        super(TaxonNavigatorLabels.CHANGE_PUBLISH_FOR_SUBTREE);
48
        super("");
49
    }
50

    
51

    
52
    private ITaxonTreeNode taxonNode;
53
    private PublishForSubtreeConfigurator configurator;
54

    
55

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

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

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

    
83

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

    
93
        configurator = new PublishForSubtreeConfigurator(taxonNode.getUuid());
94
        SetPublishForSubtreeWizard wizard = new SetPublishForSubtreeWizard(configurator);
95

    
96
        WizardDialog dialog = new WizardDialog(shell, wizard);
97

    
98
        if (dialog.open() == Window.OK) {
99
            return Status.OK_STATUS;
100
        }else{
101
            return Status.CANCEL_STATUS;
102
        }
103
    }
104

    
105
    @CanExecute
106
    private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection, MHandledMenuItem menuItem){
107
        boolean canExecute = false;
108
        canExecute = selection.getFirstElement() instanceof ITaxonTreeNode;
109
        menuItem.setVisible(canExecute);
110
        return canExecute;
111
    }
112

    
113

    
114
    @Override
115
    public AbstractOperation prepareOperation(IStructuredSelection selection, Shell shell, MPart activePart,
116
            MHandledMenuItem menuItem) {
117
        SetPublishForSubtreeOperation operation =
118
                new SetPublishForSubtreeOperation(getTrigger(),
119
                        false,
120
                        taxonNode.getUuid(),
121
                        configurator);
122

    
123
        return operation;
124
    }
125

    
126

    
127
    @Override
128
    public void onComplete() {
129

    
130
    }
131

    
132

    
133
    @Override
134
    protected Object getTrigger() {
135
        return this;
136
    }
137

    
138
}
(15-15/16)