Project

General

Profile

Download (3.37 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * Copyright (C) 2016 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.editor.key.polytomous.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.swt.widgets.Shell;
22

    
23
import eu.etaxonomy.cdm.model.description.PolytomousKey;
24
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
25
import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyEditorLabels;
26
import eu.etaxonomy.taxeditor.editor.key.polytomous.e4.PolytomousKeyListEditorE4;
27
import eu.etaxonomy.taxeditor.editor.key.polytomous.operation.InsertPolytomousKeyNodeOperation;
28
import eu.etaxonomy.taxeditor.operation.e4.RemotingCdmHandlerE4;
29

    
30
/**
31
 * @author k.luther
32
 * @date 17.11.2016
33
 *
34
 */
35
public class InsertNewNodeHandlerE4 extends RemotingCdmHandlerE4{
36

    
37
    private PolytomousKeyNode parentNode ;
38

    
39

    
40
    public InsertNewNodeHandlerE4() {
41
        super(PolytomousKeyEditorLabels.INSERT_NODE_POLYTOMOUS_KEY_NODE_LABEL);
42
    }
43

    
44
    @Override
45
    public IStatus allowOperations(@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
46
            @Named(IServiceConstants.ACTIVE_SHELL)Shell shell,
47
            @Named(IServiceConstants.ACTIVE_PART)MPart activePart,
48
            MHandledMenuItem menuItem) {
49

    
50
        PolytomousKeyListEditorE4 editor = (PolytomousKeyListEditorE4) activePart.getObject();
51

    
52
        if(editor.getTableItemCount() == 0) {
53
            PolytomousKey pk = editor.getViewerInputKey();
54
            parentNode = pk.getRoot();
55

    
56
        } else {
57
            if (selection.getFirstElement() instanceof PolytomousKeyNode) {
58
                parentNode = ((PolytomousKeyNode) selection.getFirstElement()).getParent();
59
            } else {
60
                return new Status(IStatus.ERROR,
61
                        "unknown", //$NON-NLS-1$
62
                        PolytomousKeyEditorLabels.NO_KEY_NODE_FOR_INSERT_NODE_SELECTED_MESSAGE);
63
            }
64
        }
65
        return Status.OK_STATUS;
66
    }
67

    
68
    @Override
69
    public AbstractOperation prepareOperation(@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
70
            @Named(IServiceConstants.ACTIVE_SHELL)Shell shell,
71
            @Named(IServiceConstants.ACTIVE_PART)MPart activePart,
72
            MHandledMenuItem menuItem) {
73
        PolytomousKeyListEditorE4 editor = (PolytomousKeyListEditorE4) activePart.getObject();
74
        editor.changed(null);
75
        return new InsertPolytomousKeyNodeOperation(getTrigger(), false, parentNode, editor);
76
    }
77

    
78
    @Override
79
    public void onComplete() {
80
    }
81

    
82
    @CanExecute
83
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
84
            MHandledMenuItem menuItem){
85
        return true;
86
    }
87

    
88
    /**
89
     * {@inheritDoc}
90
     */
91
    @Override
92
    protected Object getTrigger() {
93
        return this;
94
    }
95

    
96
}
(4-4/6)