2 * Copyright (C) 2017 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
.featuretree
.e4
.handler
;
11 import java
.util
.List
;
13 import javax
.inject
.Named
;
15 import org
.eclipse
.core
.runtime
.IStatus
;
16 import org
.eclipse
.e4
.core
.di
.annotations
.CanExecute
;
17 import org
.eclipse
.e4
.core
.di
.annotations
.Execute
;
18 import org
.eclipse
.e4
.core
.di
.annotations
.Optional
;
19 import org
.eclipse
.e4
.ui
.di
.UISynchronize
;
20 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
21 import org
.eclipse
.e4
.ui
.model
.application
.ui
.menu
.MHandledMenuItem
;
22 import org
.eclipse
.e4
.ui
.services
.IServiceConstants
;
23 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
24 import org
.eclipse
.jface
.wizard
.WizardDialog
;
25 import org
.eclipse
.swt
.widgets
.Shell
;
27 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
28 import eu
.etaxonomy
.cdm
.persistence
.dto
.TermDto
;
29 import eu
.etaxonomy
.taxeditor
.featuretree
.TermChooseWizard
;
30 import eu
.etaxonomy
.taxeditor
.featuretree
.e4
.IFeatureTreeEditor
;
31 import eu
.etaxonomy
.taxeditor
.featuretree
.e4
.operation
.AddFeatureOperation
;
32 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
33 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
40 public class AddFeatureHandler
{
43 public void execute(@Named(IServiceConstants
.ACTIVE_SHELL
) Shell shell
,
44 @Named(IServiceConstants
.ACTIVE_SELECTION
)IStructuredSelection selection
,
45 @Named(IServiceConstants
.ACTIVE_PART
)MPart thisPart
, UISynchronize sync
) {
46 IFeatureTreeEditor editor
= ((IFeatureTreeEditor
) thisPart
.getObject());
48 if (StoreUtil
.promptCheckIsDirty(editor
)) {
53 TermChooseWizard wizard
= new TermChooseWizard();
54 // AvailableFeaturesWizard wizard = new AvailableFeaturesWizard();
55 WizardDialog dialog
= new WizardDialog(shell
, wizard
);
57 if (dialog
.open() == IStatus
.OK
) {
58 FeatureTree tree
= (FeatureTree
) selection
.getFirstElement();
59 List
<TermDto
> selectedTerms
= wizard
.getSelectedTerms();
60 for (TermDto termDto
: selectedTerms
) {
61 AddFeatureOperation operation
= new AddFeatureOperation(termDto
.getUuid(), tree
.getRoot(), editor
, editor
);
62 AbstractUtility
.executeOperation(operation
, sync
);
68 public boolean canExecute(
69 @Optional@Named(IServiceConstants
.ACTIVE_SELECTION
)IStructuredSelection selection
,
70 @Named(IServiceConstants
.ACTIVE_PART
)MPart thisPart
,
71 MHandledMenuItem menuItem
) {
72 boolean canExecute
= false;
73 canExecute
= thisPart
.getObject() instanceof IFeatureTreeEditor
75 && selection
.size()==1
76 && selection
.getFirstElement() instanceof FeatureTree
;
77 menuItem
.setVisible(canExecute
);