2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.navigation
.navigator
.e4
.handler
;
12 import javax
.inject
.Named
;
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
;
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 import eu
.etaxonomy
.taxeditor
.newWizard
.NewTaxonNodeWizardDialog
;
40 public class NewTaxonNodeHandlerE4
{
43 public void execute(@Named(IServiceConstants
.ACTIVE_SHELL
) Shell shell
,
44 @Named(IServiceConstants
.ACTIVE_SELECTION
) ITreeSelection selection
, EModelService modelService
,
45 EPartService partService
, MApplication application
) throws Exception
{
47 final NewTaxonNodeWizard wizard
= new NewTaxonNodeWizard();
48 wizard
.init(null, selection
);
49 final WizardDialog dialog
= new NewTaxonNodeWizardDialog(shell
, wizard
);
50 wizard
.addWizardPageListener(new IWizardPageListener() {
53 wizard
.performFinish();
57 int status
= dialog
.open();
59 if(status
== IStatus
.OK
&& wizard
.openInEditor()){
60 EventUtility
.postEvent(WorkbenchEventConstants
.REFRESH_NAVIGATOR
, true);
61 if(wizard
.openEmpty()){
62 EditorUtil
.openEmptyE4(wizard
.getParentTreeNode().getUuid());
63 }else if(wizard
.getEntity() != null){
64 EditorUtil
.openTaxonNodeE4(wizard
.getEntity().getUuid(), modelService
, partService
, application
);
70 private boolean canExecute(@Named(IServiceConstants
.ACTIVE_SELECTION
)TreeSelection selection
,
71 MHandledMenuItem menuItem
){
72 boolean canExecute
= false;
73 canExecute
= selection
!=null && selection
.size()==1;
74 menuItem
.setVisible(canExecute
);