2 * Copyright (C) 2016 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.
9 package eu
.etaxonomy
.taxeditor
.handler
.defaultHandler
.e4
;
11 import java
.util
.Collection
;
13 import org
.eclipse
.e4
.core
.contexts
.ContextInjectionFactory
;
14 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
15 import org
.eclipse
.e4
.ui
.workbench
.modeling
.EPartService
;
16 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
17 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
18 import org
.eclipse
.jface
.window
.Window
;
19 import org
.eclipse
.jface
.wizard
.WizardDialog
;
20 import org
.eclipse
.swt
.widgets
.Shell
;
22 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonNodeService
;
23 import eu
.etaxonomy
.cdm
.model
.metadata
.PreferencePredicate
;
24 import eu
.etaxonomy
.cdm
.persistence
.dto
.TaxonNodeDto
;
25 import eu
.etaxonomy
.taxeditor
.editor
.ITaxonEditor
;
26 import eu
.etaxonomy
.taxeditor
.event
.EventUtility
;
27 import eu
.etaxonomy
.taxeditor
.event
.WorkbenchEventConstants
;
28 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
29 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
30 import eu
.etaxonomy
.taxeditor
.ui
.section
.classification
.EditTaxonNodeWizard
;
37 public class DefaultOpenTaxonNodeWizardHandlerE4
extends DefaultOpenHandlerBaseE4
<TaxonNodeDto
> {
40 // protected TaxonNode getEntity(UUID uuid) {
41 // return CdmStore.getService(ITaxonNodeService.class).load(uuid);
45 protected void open(TaxonNodeDto entity
, Shell shell
, EPartService partService
) {
46 Collection
<MPart
> dirtyParts
= partService
.getDirtyParts();
47 if (!dirtyParts
.isEmpty()){
49 for (MPart dirtyPart
: dirtyParts
){
50 if (dirtyPart
.getElementId().equals("eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4") && ((ITaxonEditor
)dirtyPart
.getObject()).getTaxonNode().getUuid().equals(entity
.getUuid())){
51 boolean doSave
= MessageDialog
52 .openConfirm(shell
, "The taxonnode is in an unsaved mode",
53 "Do you want to save?");
59 partService
.savePart(dirtyPart
, false);
64 EditTaxonNodeWizard taxonNodeWizard
= ContextInjectionFactory
.make(EditTaxonNodeWizard
.class, context
);
65 taxonNodeWizard
.init(null, null);
66 taxonNodeWizard
.setEntity(CdmStore
.getService(ITaxonNodeService
.class).load(entity
.getUuid()));
67 WizardDialog dialog
= new WizardDialog(shell
, taxonNodeWizard
);
68 int result
= dialog
.open();
69 if (result
== Window
.OK
){
70 // entity = CdmStore.getService(ITaxonNodeService.class).dto(entity.getUuid());
71 entity
= new TaxonNodeDto(taxonNodeWizard
.getEntity());
72 EventUtility
.postEvent(WorkbenchEventConstants
.REFRESH_NAVIGATOR
, taxonNodeWizard
.getEntity().getParent());
73 EventUtility
.postEvent(WorkbenchEventConstants
.REFRESH_NAME_EDITOR
, entity
.getTaxonUuid());
79 public boolean canExecute(Object selection
) {
80 if (((IStructuredSelection
)selection
).getFirstElement() instanceof TaxonNodeDto
&& ((IStructuredSelection
)selection
).size() == 1){
81 return ((TaxonNodeDto
)((IStructuredSelection
)selection
).getFirstElement()).getTaxonUuid()!=null && PreferencesUtil
.getBooleanValue(PreferencePredicate
.ShowTaxonNodeWizard
.getKey());