Project

General

Profile

Download (2.29 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.newWizard.IWizardPageListener;
28
import eu.etaxonomy.taxeditor.newWizard.NewTaxonNodeWizard;
29

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

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

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

    
55
		if(status == IStatus.OK && wizard.openInEditor()){
56
			if(wizard.openEmpty()){
57
                EditorUtil.openEmptyE4(wizard.getParentTreeNode().getUuid());
58
			}else if(wizard.getTaxonNode() != null){
59
                EditorUtil.openTaxonNodeE4(wizard.getTaxonNode().getUuid(), modelService, partService, application);
60
			}
61
		}
62
	}
63

    
64
    @CanExecute
65
    private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection){
66
        return selection!=null && !selection.isEmpty();
67
    }
68
}
(10-10/17)