Project

General

Profile

Download (2.47 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.services.IServiceConstants;
19
import org.eclipse.e4.ui.workbench.modeling.EModelService;
20
import org.eclipse.e4.ui.workbench.modeling.EPartService;
21
import org.eclipse.jface.viewers.ITreeSelection;
22
import org.eclipse.jface.viewers.TreeSelection;
23
import org.eclipse.jface.wizard.WizardDialog;
24
import org.eclipse.swt.widgets.Shell;
25

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

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

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

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

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

    
67
    @CanExecute
68
    private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection){
69
        return selection!=null && !selection.isEmpty();
70
    }
71
}
(7-7/14)