Project

General

Profile

Download (3.59 KB) Statistics
| Branch: | Tag: | Revision:
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 = new CloneClassificationWizard();
51
            ContextInjectionFactory.inject(wizard, context);
52
//            CloneClassificationWizard wizard = ContextInjectionFactory.make(CloneClassificationWizard.class, context);
53
            wizard.init(classification);
54
            WizardDialog dialog = new WizardDialog(shell, wizard);
55
            dialog.open();
56

    
57
            String classificationName = wizard.getClassificationName();
58
            TaxonRelationshipType relationType = wizard.getRelationType();
59
            Reference reference = wizard.getReference();
60

    
61
            CloneClassificationOperation operation = new CloneClassificationOperation(Messages.CloneClassificationHandler_CLONE_CLASSIFICATION,
62
                    StoreUtil.getUndoContext(), classification, classificationName, reference, relationType,
63
                    taxonNavigator, taxonNavigator);
64

    
65
            AbstractUtility.executeOperation(operation, sync);
66
            taxonNavigator.refresh();
67
        }
68
    }
69

    
70
    @CanExecute
71
    private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection, MHandledMenuItem menuItem){
72
        boolean canExecute = false;
73
        canExecute = selection.getFirstElement() instanceof TaxonNode
74
                && ((TaxonNode) selection.getFirstElement()).getTaxon()==null
75
                && PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_EXPERIMENTAL_FEATURES);
76
        menuItem.setVisible(canExecute);
77
        return canExecute;
78
    }
79
}
(2-2/17)