70f0cdb7df657b3641662d76c8e2c4175a03c99d
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / navigator / e4 / handler / NewTaxonNodeHandlerE4.java
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.services.IServiceConstants;
18 import org.eclipse.jface.viewers.TreeSelection;
19 import org.eclipse.jface.wizard.WizardDialog;
20 import org.eclipse.swt.widgets.Shell;
21
22 import eu.etaxonomy.taxeditor.editor.EditorUtil;
23 import eu.etaxonomy.taxeditor.newWizard.IWizardPageListener;
24 import eu.etaxonomy.taxeditor.newWizard.NewTaxonNodeWizard;
25
26 /**
27 *
28 * @author pplitzner
29 * @date 05.09.2017
30 *
31 */
32 public class NewTaxonNodeHandlerE4 {
33
34 @Execute
35 public void execute(@Named(IServiceConstants.ACTIVE_SHELL)Shell shell) throws Exception {
36
37 final NewTaxonNodeWizard wizard = new NewTaxonNodeWizard();
38 wizard.init(null, null);
39 final WizardDialog dialog = new WizardDialog(shell, wizard);
40 wizard.addWizardPageListener(new IWizardPageListener() {
41 @Override
42 public void close() {
43 wizard.performFinish();
44 dialog.close();
45 }
46 });
47 int status = dialog.open();
48
49 if(status == IStatus.OK && wizard.openInEditor()){
50 if(wizard.openEmpty()){
51 EditorUtil.openEmptyE4(wizard.getParentTreeNode().getUuid());
52 }else if(wizard.getTaxonNode() != null){
53 EditorUtil.openTaxonNodeE4(wizard.getTaxonNode().getUuid());
54 }
55 }
56 }
57
58 @CanExecute
59 private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection){
60 return selection!=null && !selection.isEmpty();
61 }
62 }