Project

General

Profile

Download (4.26 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.getFirstElement() instanceof TaxonNodeDto;
96
        menuItem.setVisible(canExecute);
97
        return canExecute;
98
    }
99

    
100

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

    
114
        return operation;
115
    }
116

    
117

    
118
    @Override
119
    public void onComplete() {
120

    
121
    }
122

    
123

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

    
129
}
(13-13/14)