Project

General

Profile

Download (4.28 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.e4.handler;
10

    
11
import javax.inject.Named;
12

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

    
26
import eu.etaxonomy.cdm.api.service.config.SecundumForSubtreeConfigurator;
27
import eu.etaxonomy.cdm.model.taxon.Classification;
28
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
29
import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigatorLabels;
30
import eu.etaxonomy.taxeditor.navigation.navigator.operation.SetSecundumForSubtreeOperation;
31
import eu.etaxonomy.taxeditor.operation.e4.RemotingCdmHandlerE4;
32
import eu.etaxonomy.taxeditor.ui.dialog.configurator.SetSecundumForSubtreeConfigurationWizard;
33

    
34
/**
35
 * @author k.luther
36
 * @author pplitzner
37
 * @date 10.02.2017
38
 *
39
 */
40
public class SetSecReferenceForSubtreeHandlerE4 extends RemotingCdmHandlerE4 {
41

    
42
    private TaxonNodeDto taxonNode;
43
    private SecundumForSubtreeConfigurator configurator;
44

    
45
    public SetSecReferenceForSubtreeHandlerE4() {
46
        super(TaxonNavigatorLabels.CHANGE_SECUNDUM_FOR_SUBTREE);
47
    }
48

    
49
    @Override
50
    public IStatus allowOperations(IStructuredSelection selection,
51
            Shell shell,
52
            MPart activePart,
53
            MHandledMenuItem menuItem) {
54
        // check that only a single taxon tree node has been selected
55
        if(selection.size() > 1) {  }
56

    
57
        // check for no taxon tree node selected
58
        if(selection.size() == 0) {
59
            return new Status(IStatus.ERROR,
60
                    "unknown", //$NON-NLS-1$
61
                    TaxonNavigatorLabels.NO_TAXON_SELECTION_MESSAGE);
62
        }
63

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

    
78
        configurator = new SecundumForSubtreeConfigurator(taxonNode.getUuid());
79
        SetSecundumForSubtreeConfigurationWizard wizard = new SetSecundumForSubtreeConfigurationWizard(configurator);
80

    
81
        WizardDialog dialog = new WizardDialog(shell, wizard);
82

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

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

    
98
    @Override
99
    public AbstractOperation prepareOperation(IStructuredSelection selection,
100
            Shell shell,
101
            MPart activePart,
102
            MHandledMenuItem menuItem) {
103
        SetSecundumForSubtreeOperation operation =
104
                new SetSecundumForSubtreeOperation(getTrigger(),
105
                        true,
106
                        taxonNode.getUuid(),
107
                        partService, activePart, application, modelService,
108
                        configurator);
109

    
110
        return operation;
111
    }
112

    
113
    @Override
114
    public void onComplete() {
115
    }
116

    
117
    /**
118
     * {@inheritDoc}
119
     */
120
    @Override
121
    protected Object getTrigger() {
122
        return this;
123
    }
124

    
125
}
(14-14/14)