1
|
package eu.etaxonomy.taxeditor.navigation.navigator.e4.handler;
|
2
|
|
3
|
import javax.inject.Named;
|
4
|
|
5
|
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
|
6
|
import org.eclipse.e4.core.contexts.IEclipseContext;
|
7
|
import org.eclipse.e4.core.di.annotations.CanExecute;
|
8
|
import org.eclipse.e4.core.di.annotations.Execute;
|
9
|
import org.eclipse.e4.ui.di.UISynchronize;
|
10
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
11
|
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
|
12
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
13
|
import org.eclipse.jface.viewers.TreeSelection;
|
14
|
import org.eclipse.jface.wizard.WizardDialog;
|
15
|
import org.eclipse.swt.widgets.Shell;
|
16
|
|
17
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
18
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
19
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
20
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
|
21
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
22
|
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
|
23
|
import eu.etaxonomy.taxeditor.navigation.navigator.e4.TaxonNavigatorE4;
|
24
|
import eu.etaxonomy.taxeditor.navigation.operation.CloneClassificationOperation;
|
25
|
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
|
26
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
27
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
28
|
import eu.etaxonomy.taxeditor.ui.section.classification.CloneClassificationWizard;
|
29
|
|
30
|
/**
|
31
|
*
|
32
|
* @author pplitzner
|
33
|
* @date 05.09.2017
|
34
|
*
|
35
|
*/
|
36
|
public class CloneClassificationHandlerE4 {
|
37
|
|
38
|
@Execute
|
39
|
public void execute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection,
|
40
|
@Named(IServiceConstants.ACTIVE_SHELL)Shell shell,
|
41
|
@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
|
42
|
IEclipseContext context,
|
43
|
UISynchronize sync) {
|
44
|
|
45
|
TaxonNavigatorE4 taxonNavigator = (TaxonNavigatorE4) activePart.getObject();
|
46
|
|
47
|
Object selectedElement = selection.getFirstElement();
|
48
|
if (selectedElement instanceof TaxonNode && !((TaxonNode)selectedElement).hasTaxon()) {
|
49
|
Classification classification = ((TaxonNode)selectedElement).getClassification();
|
50
|
CloneClassificationWizard wizard = ContextInjectionFactory.make(CloneClassificationWizard.class, context);
|
51
|
wizard.init(classification);
|
52
|
WizardDialog dialog = new WizardDialog(shell, wizard);
|
53
|
dialog.open();
|
54
|
|
55
|
String classificationName = wizard.getClassificationName();
|
56
|
TaxonRelationshipType relationType = wizard.getRelationType();
|
57
|
Reference reference = wizard.getReference();
|
58
|
|
59
|
CloneClassificationOperation operation = new CloneClassificationOperation(Messages.CloneClassificationHandler_CLONE_CLASSIFICATION,
|
60
|
StoreUtil.getUndoContext(), classification, classificationName, reference, relationType,
|
61
|
taxonNavigator, taxonNavigator);
|
62
|
|
63
|
AbstractUtility.executeOperation(operation, sync);
|
64
|
taxonNavigator.refresh();
|
65
|
}
|
66
|
}
|
67
|
|
68
|
@CanExecute
|
69
|
private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection, MHandledMenuItem menuItem){
|
70
|
boolean canExecute = false;
|
71
|
canExecute = selection.getFirstElement() instanceof TaxonNode
|
72
|
&& ((TaxonNode) selection.getFirstElement()).getTaxon()==null
|
73
|
&& PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_EXPERIMENTAL_FEATURES);
|
74
|
menuItem.setVisible(canExecute);
|
75
|
return canExecute;
|
76
|
}
|
77
|
}
|