Project

General

Profile

Download (4.3 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.persistence.dto.TaxonNodeDto;
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 TaxonNodeDto 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 TaxonNodeDto) {
72
             taxonNode = (TaxonNodeDto)obj;
73
        } else if(obj instanceof Classification){
74
            taxonNode = new TaxonNodeDto(((Classification)obj).getRootNode());
75
        }else{
76
            return new Status(IStatus.ERROR,
77
                    "unknown", //$NON-NLS-1$
78
                    TaxonNavigatorLabels.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE);
79
        }
80
        configurator = new PublishForSubtreeConfigurator(taxonNode.getUuid());
81
        SetPublishForSubtreeWizard wizard = new SetPublishForSubtreeWizard(configurator);
82

    
83
        WizardDialog dialog = new WizardDialog(shell, wizard);
84

    
85
        if (dialog.open() == Window.OK) {
86
            return Status.OK_STATUS;
87
        }else{
88
            return Status.CANCEL_STATUS;
89
        }
90
    }
91

    
92
    @CanExecute
93
    private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection, MHandledMenuItem menuItem){
94
        boolean canExecute = false;
95
        canExecute = selection.size()==1
96
                && selection.getFirstElement() instanceof TaxonNodeDto;
97
        menuItem.setVisible(canExecute);
98
        return canExecute;
99
    }
100

    
101

    
102
    @Override
103
    public AbstractOperation prepareOperation(IStructuredSelection selection, Shell shell, MPart activePart,
104
            MHandledMenuItem menuItem) {
105
        SetPublishForSubtreeOperation operation =
106
                new SetPublishForSubtreeOperation(getTrigger(),
107
                        false,
108
                        taxonNode.getUuid(),
109
                        partService,
110
                        activePart,
111
                        application,
112
                        modelService,
113
                        configurator);
114

    
115
        return operation;
116
    }
117

    
118

    
119
    @Override
120
    public void onComplete() {
121

    
122
    }
123

    
124

    
125
    @Override
126
    protected Object getTrigger() {
127
        return this;
128
    }
129

    
130
}
(13-13/14)