Project

General

Profile

Download (3.79 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.EditorPreferencePredicate;
26
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
27
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
28
import eu.etaxonomy.taxeditor.store.StoreUtil;
29
import eu.etaxonomy.taxeditor.ui.section.classification.CloneClassificationWizard;
30

    
31
/**
32
 *
33
 * @author pplitzner
34
 * @date 05.09.2017
35
 *
36
 */
37
public class CloneClassificationHandlerE4 {
38

    
39
    @Execute
40
    public void execute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection,
41
            @Named(IServiceConstants.ACTIVE_SHELL)Shell shell,
42
            @Named(IServiceConstants.ACTIVE_PART)MPart activePart,
43
            IEclipseContext context,
44
            UISynchronize sync) {
45

    
46
        TaxonNavigatorE4 taxonNavigator = (TaxonNavigatorE4) activePart.getObject();
47

    
48
        Object selectedElement = selection.getFirstElement();
49
        if (selectedElement instanceof TaxonNode && !((TaxonNode)selectedElement).hasTaxon()) {
50
            Classification classification = ((TaxonNode)selectedElement).getClassification();
51
            CloneClassificationWizard wizard = new CloneClassificationWizard();
52
            ContextInjectionFactory.inject(wizard, context);
53
//            CloneClassificationWizard wizard = ContextInjectionFactory.make(CloneClassificationWizard.class, context);
54
            wizard.init(classification);
55
            WizardDialog dialog = new WizardDialog(shell, wizard);
56
            dialog.open();
57

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

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

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

    
71
    @CanExecute
72
    private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection, MHandledMenuItem menuItem){
73
        boolean canExecute = false;
74
        canExecute = selection.size()==1
75
                && selection.getFirstElement() instanceof TaxonNode
76
                && ((TaxonNode) selection.getFirstElement()).getTaxon()==null
77
                && PreferencesUtil.getBooleanValue(IPreferenceKeys.SHOW_EXPERIMENTAL_FEATURES)
78
                && !PreferencesUtil.getBooleanValue(EditorPreferencePredicate.DisableMultiClassification.getKey());
79
        menuItem.setVisible(canExecute);
80
        return canExecute;
81
    }
82
}
(2-2/20)