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.common.NotDefinedException;
14
import org.eclipse.core.commands.operations.IUndoContext;
15
import org.eclipse.e4.core.di.annotations.CanExecute;
16
import org.eclipse.e4.core.di.annotations.Execute;
17
import org.eclipse.e4.core.di.annotations.Optional;
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) throws NotDefinedException {
44

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

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

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

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

    
61
    }
62

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

    
69
        TermVocabulary vocabulary = null;
70

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

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

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

    
87
        return true;
88
    }
89

    
90
}
(1-1/4)