1
|
/**
|
2
|
* Copyright (C) 2017 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.featuretree.e4.handler;
|
10
|
|
11
|
import java.util.Collection;
|
12
|
|
13
|
import javax.inject.Named;
|
14
|
|
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;
|
26
|
|
27
|
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
|
28
|
import eu.etaxonomy.cdm.model.term.FeatureNode;
|
29
|
import eu.etaxonomy.taxeditor.featuretree.AvailableFeaturesWizard;
|
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;
|
34
|
|
35
|
/**
|
36
|
* @author pplitzner
|
37
|
* @since Jul 12, 2017
|
38
|
*
|
39
|
*/
|
40
|
public class AddChildFeatureHandler {
|
41
|
|
42
|
@Execute
|
43
|
public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell,
|
44
|
@Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
|
45
|
@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
|
46
|
UISynchronize sync) {
|
47
|
IFeatureTreeEditor editor = ((IFeatureTreeEditor) thisPart.getObject());
|
48
|
if (StoreUtil.promptCheckIsDirty(editor)) {
|
49
|
return;
|
50
|
}
|
51
|
FeatureNode parent = (FeatureNode)selection.getFirstElement();
|
52
|
|
53
|
// TermChooseWizard wizard = new TermChooseWizard(parent.getTermType());
|
54
|
// WizardDialog dialog = new WizardDialog(shell, wizard);
|
55
|
//
|
56
|
// if (dialog.open() == IStatus.OK) {
|
57
|
// List<TermDto> selectedTerms = wizard.getSelectedTerms();
|
58
|
// for (TermDto termDto: selectedTerms) {
|
59
|
// AddFeatureOperation operation = new AddFeatureOperation(termDto.getUuid(), parent, editor, editor);
|
60
|
// AbstractUtility.executeOperation(operation, sync);
|
61
|
// }
|
62
|
// }
|
63
|
|
64
|
AvailableFeaturesWizard wizard = new AvailableFeaturesWizard(parent.getTermType());
|
65
|
WizardDialog dialog = new WizardDialog(shell, wizard);
|
66
|
|
67
|
if (dialog.open() == IStatus.OK) {
|
68
|
Collection<DefinedTermBase> additionalTerms = wizard.getAdditionalFeatures();
|
69
|
for (DefinedTermBase term : additionalTerms) {
|
70
|
AddFeatureOperation operation = new AddFeatureOperation(term.getUuid(), parent, editor, editor);
|
71
|
AbstractUtility.executeOperation(operation, sync);
|
72
|
}
|
73
|
}
|
74
|
}
|
75
|
|
76
|
@CanExecute
|
77
|
public boolean canExecute(
|
78
|
@Optional@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
|
79
|
@Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
|
80
|
MHandledMenuItem menuItem) {
|
81
|
boolean canExecute = false;
|
82
|
canExecute = thisPart.getObject() instanceof IFeatureTreeEditor
|
83
|
&& selection!=null
|
84
|
&& selection.size()==1
|
85
|
&& selection.getFirstElement() instanceof FeatureNode;
|
86
|
menuItem.setVisible(canExecute);
|
87
|
return canExecute;
|
88
|
}
|
89
|
}
|