Merge branch 'develop' into LibrAlign
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / navigator / handler / NewTaxonNodeHandler.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.handler;
11
12 import org.eclipse.core.commands.AbstractHandler;
13 import org.eclipse.core.commands.ExecutionEvent;
14 import org.eclipse.core.commands.ExecutionException;
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.jface.wizard.WizardDialog;
17 import org.eclipse.ui.handlers.HandlerUtil;
18
19 import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
20 import eu.etaxonomy.taxeditor.newWizard.IWizardPageListener;
21 import eu.etaxonomy.taxeditor.newWizard.NewTaxonNodeWizard;
22
23 /**
24 * <p>NewTaxonNodeHandler class.</p>
25 *
26 * @author n.hoffmann
27 * @created Sep 15, 2009
28 * @version 1.0
29 */
30 public class NewTaxonNodeHandler extends AbstractHandler {
31
32 /** {@inheritDoc} */
33 @Override
34 public Object execute(ExecutionEvent event) throws ExecutionException {
35 final NewTaxonNodeWizard wizard = new NewTaxonNodeWizard();
36 wizard.init(null, null);
37 final WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event), wizard);
38 wizard.addWizardPageListener(new IWizardPageListener() {
39
40 @Override
41 public void close() {
42 wizard.performFinish();
43 dialog.close();
44 }
45 });
46 int status = dialog.open();
47
48 if(status == IStatus.OK && wizard.openInEditor()){
49 if(wizard.openEmpty()){
50 NavigationUtil.openEmpty(wizard.getParentTreeNode().getUuid());
51 }else if(wizard.getTaxonNode() != null){
52 NavigationUtil.openEditor(wizard.getTaxonNode());
53 }
54 }
55 return null;
56 }
57 }