Project

General

Profile

Download (3.43 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * Copyright (C) 2015 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.handler;
10

    
11
import org.eclipse.core.commands.ExecutionEvent;
12
import org.eclipse.core.commands.operations.AbstractOperation;
13
import org.eclipse.core.runtime.IStatus;
14
import org.eclipse.core.runtime.Status;
15
import org.eclipse.jface.viewers.IStructuredSelection;
16
import org.eclipse.ui.IEditorPart;
17
import org.eclipse.ui.handlers.HandlerUtil;
18

    
19
import eu.etaxonomy.cdm.model.description.PolytomousKey;
20
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
21
import eu.etaxonomy.taxeditor.editor.key.KeyEditor;
22
import eu.etaxonomy.taxeditor.editor.key.polytomous.IPolytomousKeyEditorPage;
23
import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyEditorLabels;
24
import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyListEditor;
25
import eu.etaxonomy.taxeditor.editor.key.polytomous.operation.RemotingCreatePolytomousKeyNodeOperation;
26

    
27
/**
28
 * @author cmathew
29
 * @date 21 Jul 2015
30
 *
31
 */
32
public class RemotingCreateChildPolytomousKeyNodeHandler extends AbstractPolytomousKeyNodeHandler {
33

    
34
    private PolytomousKeyNode parentNode;
35
    IPolytomousKeyEditorPage editorPage;
36

    
37

    
38
    public RemotingCreateChildPolytomousKeyNodeHandler() {
39
        super(PolytomousKeyEditorLabels.CREATE_CHILD_POLYTOMOUS_KEY_NODE_LABEL);
40
    }
41
    /* (non-Javadoc)
42
     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#allowOperations(org.eclipse.core.commands.ExecutionEvent)
43
     */
44
    @Override
45
    public IStatus allowOperations(ExecutionEvent event) {
46
        IEditorPart editor = HandlerUtil.getActiveEditor(event);
47

    
48
        if (editor instanceof KeyEditor) {
49
            editorPage = (IPolytomousKeyEditorPage) ((KeyEditor) editor)
50
                    .getActiveEditor();
51

    
52
            if (editorPage instanceof PolytomousKeyListEditor) {
53
                PolytomousKeyListEditor klEditor = (PolytomousKeyListEditor) editorPage;
54
                if(klEditor.getTableItemCount() == 0) {
55
                    PolytomousKey pk = klEditor.getViewerInputKey();
56
                    parentNode = pk.getRoot();
57

    
58
                } else {
59
                    IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
60
                    if (selection.getFirstElement() instanceof PolytomousKeyNode) {
61
                        parentNode = (PolytomousKeyNode) selection.getFirstElement();
62
                    } else {
63
                        return new Status(IStatus.ERROR,
64
                                "unknown", //$NON-NLS-1$
65
                                PolytomousKeyEditorLabels.NO_KEY_NODE_FOR_INSERT_NODE_SELECTED_MESSAGE);
66
                    }
67
                }
68
            }
69
        }
70
        return Status.OK_STATUS;
71
    }
72

    
73
    /* (non-Javadoc)
74
     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#prepareOperation(org.eclipse.core.commands.ExecutionEvent)
75
     */
76
    @Override
77
    public AbstractOperation prepareOperation(ExecutionEvent event) {
78
        return new RemotingCreatePolytomousKeyNodeOperation(event.getTrigger(), false, parentNode, editorPage);
79
    }
80

    
81
    /* (non-Javadoc)
82
     * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#onComplete()
83
     */
84
    @Override
85
    public void onComplete() {
86

    
87

    
88
    }
89

    
90

    
91

    
92
}
(7-7/8)