Project

General

Profile

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

    
11
import javax.inject.Named;
12

    
13
import org.eclipse.core.commands.operations.IUndoContext;
14
import org.eclipse.e4.core.di.annotations.CanExecute;
15
import org.eclipse.e4.core.di.annotations.Execute;
16
import org.eclipse.e4.core.di.annotations.Optional;
17
import org.eclipse.e4.ui.di.UISynchronize;
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

    
22
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
23
import eu.etaxonomy.cdm.model.common.Marker;
24
import eu.etaxonomy.cdm.model.common.MarkerType;
25
import eu.etaxonomy.cdm.model.common.TermBase;
26
import eu.etaxonomy.cdm.model.common.TermVocabulary;
27
import eu.etaxonomy.taxeditor.editor.definedterm.e4.DefinedTermEditorE4;
28
import eu.etaxonomy.taxeditor.editor.definedterm.operation.CreateDefinedTermOperation;
29
import eu.etaxonomy.taxeditor.model.AbstractUtility;
30
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
31
import eu.etaxonomy.taxeditor.store.StoreUtil;
32

    
33
/**
34
 *
35
 * @author pplitzner
36
 * @since Aug 22, 2017
37
 *
38
 */
39
public class CreateDefinedTermHandlerE4 {
40

    
41
    @Execute
42
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
43
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION) TermBase termBase, MHandledMenuItem menuItem,
44
            UISynchronize sync) {
45

    
46
        DefinedTermEditorE4 termEditor = (DefinedTermEditorE4) activePart.getObject();
47

    
48
        boolean addTermAsKindOf =
49
                menuItem.getCommand().getElementId().equals("eu.etaxonomy.taxeditor.editor.definedTerms.newKindOfTerm")?true:false;
50

    
51
        String label = menuItem.getLocalizedLabel();
52
        IUndoContext undoContext = StoreUtil.getUndoContext();
53

    
54
        AbstractPostOperation operation =
55
                new CreateDefinedTermOperation(label,
56
                        undoContext,
57
                        termBase,
58
                        termEditor.getDefinedTermEditorInput(),
59
                        termEditor, addTermAsKindOf);
60
        AbstractUtility.executeOperation(operation, sync);
61

    
62
    }
63

    
64
    @CanExecute
65
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) TermBase termBase){
66
        if (termBase == null){
67
            return true;
68
        }
69

    
70
        TermVocabulary vocabulary = null;
71

    
72
        if(termBase instanceof DefinedTermBase){
73
            vocabulary = ((DefinedTermBase) termBase).getVocabulary();
74
        }else if(termBase instanceof TermVocabulary){
75
            vocabulary = (TermVocabulary) termBase;
76
        }
77

    
78
        if(vocabulary == null){
79
            return true;
80
        }
81

    
82
        for(Marker vocabularyMarker : vocabulary.getMarkers()){
83
            if(vocabularyMarker.getMarkerType().equals(MarkerType.MODIFIABLE())){
84
                return vocabularyMarker.getValue();
85
            }
86
        }
87

    
88
        return true;
89
    }
90

    
91
}
(1-1/4)