Project

General

Profile

Download (2.68 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * Copyright (C) 2007 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

    
10
package eu.etaxonomy.taxeditor.navigation.navigator.e4.handler;
11

    
12
import javax.inject.Named;
13

    
14
import org.eclipse.core.runtime.IStatus;
15
import org.eclipse.e4.core.di.annotations.CanExecute;
16
import org.eclipse.e4.core.di.annotations.Execute;
17
import org.eclipse.e4.ui.model.application.MApplication;
18
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
19
import org.eclipse.e4.ui.services.IServiceConstants;
20
import org.eclipse.e4.ui.workbench.modeling.EModelService;
21
import org.eclipse.e4.ui.workbench.modeling.EPartService;
22
import org.eclipse.jface.viewers.ITreeSelection;
23
import org.eclipse.jface.viewers.TreeSelection;
24
import org.eclipse.jface.wizard.WizardDialog;
25
import org.eclipse.swt.widgets.Shell;
26

    
27
import eu.etaxonomy.taxeditor.editor.EditorUtil;
28
import eu.etaxonomy.taxeditor.event.EventUtility;
29
import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
30
import eu.etaxonomy.taxeditor.newWizard.IWizardPageListener;
31
import eu.etaxonomy.taxeditor.newWizard.NewTaxonNodeWizard;
32

    
33
/**
34
 *
35
 * @author pplitzner
36
 * @date 05.09.2017
37
 *
38
 */
39
public class NewTaxonNodeHandlerE4 {
40

    
41
    @Execute
42
    public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell,
43
            @Named(IServiceConstants.ACTIVE_SELECTION) ITreeSelection selection, EModelService modelService,
44
            EPartService partService, MApplication application) throws Exception {
45

    
46
		final NewTaxonNodeWizard wizard = new NewTaxonNodeWizard();
47
		wizard.init(null, selection);
48
		final WizardDialog dialog = new WizardDialog(shell, wizard);
49
		wizard.addWizardPageListener(new IWizardPageListener() {
50
		    @Override
51
		    public void close() {
52
		        wizard.performFinish();
53
		        dialog.close();
54
		    }
55
		});
56
		int status = dialog.open();
57

    
58
		if(status == IStatus.OK && wizard.openInEditor()){
59
		    EventUtility.postEvent(WorkbenchEventConstants.REFRESH_NAVIGATOR, true);
60
			if(wizard.openEmpty()){
61
                EditorUtil.openEmptyE4(wizard.getParentTreeNode().getUuid());
62
			}else if(wizard.getTaxonNode() != null){
63
                EditorUtil.openTaxonNodeE4(wizard.getTaxonNode().getUuid(), modelService, partService, application);
64
			}
65
		}
66
	}
67

    
68
    @CanExecute
69
    private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection,
70
            MHandledMenuItem menuItem){
71
        boolean canExecute = false;
72
        canExecute = selection!=null && selection.size()==1;
73
        menuItem.setVisible(canExecute);
74
        return canExecute;
75
    }
76
}
(8-8/18)