1
|
/**
|
2
|
* Copyright (C) 2016 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
|
package eu.etaxonomy.taxeditor.handler.defaultHandler.e4;
|
10
|
|
11
|
import java.util.Collection;
|
12
|
|
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;
|
21
|
|
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;
|
31
|
|
32
|
/**
|
33
|
* Open the taxon node wizard via e.g. navigator context menu.
|
34
|
*
|
35
|
* @author k.luther
|
36
|
* @date 22.03.2016
|
37
|
*/
|
38
|
public class DefaultOpenTaxonNodeWizardHandlerE4 extends DefaultOpenHandlerBaseE4<TaxonNodeDto> {
|
39
|
|
40
|
@Override
|
41
|
protected void open(TaxonNodeDto entity, Shell shell, EPartService partService) {
|
42
|
Collection<MPart> dirtyParts = partService.getDirtyParts();
|
43
|
if (!dirtyParts.isEmpty()){
|
44
|
for (MPart dirtyPart: dirtyParts){
|
45
|
if (dirtyPart.getElementId().equals("eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4") && ((ITaxonEditor)dirtyPart.getObject()).getTaxonNode().getUuid().equals(entity.getUuid())){
|
46
|
boolean doSave = MessageDialog
|
47
|
.openConfirm(shell, "The taxonnode is in an unsaved mode",
|
48
|
"Do you want to save?");
|
49
|
if (!doSave) {
|
50
|
return ;
|
51
|
}
|
52
|
|
53
|
partService.savePart(dirtyPart, false);
|
54
|
}
|
55
|
}
|
56
|
}
|
57
|
EditTaxonNodeWizard taxonNodeWizard = ContextInjectionFactory.make(EditTaxonNodeWizard.class, context);
|
58
|
taxonNodeWizard.init(null, null);
|
59
|
taxonNodeWizard.setEntity(CdmStore.getService(ITaxonNodeService.class).load(entity.getUuid()));
|
60
|
WizardDialog dialog = new WizardDialog(shell, taxonNodeWizard);
|
61
|
int result = dialog.open();
|
62
|
if (result == Window.OK){
|
63
|
entity = new TaxonNodeDto(taxonNodeWizard.getEntity());
|
64
|
EventUtility.postEvent(WorkbenchEventConstants.REFRESH_NAVIGATOR, taxonNodeWizard.getEntity().getParent());
|
65
|
EventUtility.postEvent(WorkbenchEventConstants.REFRESH_NAME_EDITOR, entity.getTaxonUuid());
|
66
|
}
|
67
|
}
|
68
|
|
69
|
@Override
|
70
|
public boolean canExecute(Object selection) {
|
71
|
if (((IStructuredSelection)selection).getFirstElement() instanceof TaxonNodeDto && ((IStructuredSelection)selection).size() == 1){
|
72
|
return ((TaxonNodeDto)((IStructuredSelection)selection).getFirstElement()).getTaxonUuid()!=null && PreferencesUtil.getBooleanValue(PreferencePredicate.ShowTaxonNodeWizard.getKey());
|
73
|
}
|
74
|
return false;
|
75
|
}
|
76
|
}
|