2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.editor
.definedterm
.e4
.handler
;
11 import javax
.inject
.Named
;
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
.model
.application
.ui
.basic
.MPart
;
18 import org
.eclipse
.e4
.ui
.model
.application
.ui
.menu
.MHandledMenuItem
;
19 import org
.eclipse
.e4
.ui
.services
.IServiceConstants
;
21 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
22 import eu
.etaxonomy
.cdm
.model
.common
.Marker
;
23 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
24 import eu
.etaxonomy
.cdm
.model
.common
.TermBase
;
25 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
26 import eu
.etaxonomy
.taxeditor
.editor
.definedterm
.e4
.DefinedTermEditorE4
;
27 import eu
.etaxonomy
.taxeditor
.editor
.definedterm
.operation
.CreateDefinedTermOperation
;
28 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
29 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
30 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
38 public class CreateDefinedTermHandlerE4
{
41 public void execute(@Named(IServiceConstants
.ACTIVE_PART
) MPart activePart
,
42 @Optional@Named(IServiceConstants
.ACTIVE_SELECTION
) TermBase termBase
, MHandledMenuItem menuItem
) {
44 DefinedTermEditorE4 termEditor
= (DefinedTermEditorE4
) activePart
.getObject();
46 boolean addTermAsKindOf
=
47 menuItem
.getCommand().getElementId().equals("eu.etaxonomy.taxeditor.editor.definedTerms.newKindOfTerm")?
true:false;
49 String label
= menuItem
.getLocalizedLabel();
50 IUndoContext undoContext
= StoreUtil
.getUndoContext();
52 AbstractPostOperation operation
=
53 new CreateDefinedTermOperation(label
,
56 termEditor
.getDefinedTermEditorInput(),
57 termEditor
, addTermAsKindOf
);
58 AbstractUtility
.executeOperation(operation
);
63 public boolean canExecute(@Named(IServiceConstants
.ACTIVE_SELECTION
) TermBase termBase
){
64 if (termBase
== null){
68 TermVocabulary vocabulary
= null;
70 if(termBase
instanceof DefinedTermBase
){
71 vocabulary
= ((DefinedTermBase
) termBase
).getVocabulary();
72 }else if(termBase
instanceof TermVocabulary
){
73 vocabulary
= (TermVocabulary
) termBase
;
76 if(vocabulary
== null){
80 for(Marker vocabularyMarker
: vocabulary
.getMarkers()){
81 if(vocabularyMarker
.getMarkerType().equals(MarkerType
.MODIFIABLE())){
82 return vocabularyMarker
.getValue();