1 package eu
.etaxonomy
.taxeditor
.navigation
.navigator
.e4
.handler
;
3 import javax
.inject
.Named
;
5 import org
.eclipse
.e4
.core
.di
.annotations
.CanExecute
;
6 import org
.eclipse
.e4
.core
.di
.annotations
.Execute
;
7 import org
.eclipse
.e4
.ui
.di
.UISynchronize
;
8 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
9 import org
.eclipse
.e4
.ui
.model
.application
.ui
.menu
.MHandledMenuItem
;
10 import org
.eclipse
.e4
.ui
.services
.IServiceConstants
;
11 import org
.eclipse
.jface
.viewers
.TreeSelection
;
13 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
14 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
15 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
16 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
17 import eu
.etaxonomy
.taxeditor
.navigation
.l10n
.Messages
;
18 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.e4
.TaxonNavigatorE4
;
19 import eu
.etaxonomy
.taxeditor
.navigation
.operation
.CreateNewTaxonHierarchyOperation
;
20 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
21 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
22 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
30 public class CreateClassificationHierarchyHandlerE4
{
33 public void execute(@Named(IServiceConstants
.ACTIVE_SELECTION
)TreeSelection selection
,
34 @Named(IServiceConstants
.ACTIVE_PART
)MPart activePart
,
37 TaxonNavigatorE4 taxonNavigator
= (TaxonNavigatorE4
) activePart
.getObject();
39 Object selectedElement
= selection
.getFirstElement();
40 if (selectedElement
instanceof TaxonNode
&& !((TaxonNode
)selectedElement
).hasTaxon()) {
41 Classification classification
= ((TaxonNode
) selectedElement
).getClassification();
43 CreateNewTaxonHierarchyOperation operation
= new CreateNewTaxonHierarchyOperation(Messages
.CreateClassificationHierarchyHandler_CREATE_HIERARCHY
, StoreUtil
.getUndoContext(),classification
, taxonNavigator
, taxonNavigator
);
44 AbstractUtility
.executeOperation(operation
, sync
);
45 taxonNavigator
.refresh();
46 } catch (Exception e
) {
47 MessagingUtils
.messageDialog(Messages
.CreateClassificationHierarchyHandler_FAILED
, CreateClassificationHierarchyHandlerE4
.class,
48 Messages
.CreateClassificationHierarchyHandler_FAILED_MESSAGE
, e
);
54 private boolean canExecute(@Named(IServiceConstants
.ACTIVE_SELECTION
)TreeSelection selection
, MHandledMenuItem menuItem
){
55 boolean canExecute
= false;
56 canExecute
= selection
.size()==1
57 && selection
.getFirstElement() instanceof TaxonNode
58 && ((TaxonNode
) selection
.getFirstElement()).getTaxon()==null
59 && PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.SHOW_EXPERIMENTAL_FEATURES
)
60 && !PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.DISABLE_MULTI_CLASSIFICATION
);
61 menuItem
.setVisible(canExecute
);