ref #5670: updating parent node when changing node in taxonnodewizard
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / handler / defaultHandler / e4 / DefaultOpenTaxonNodeWizardHandlerE4.java
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 * @author k.luther
34 * @date 22.03.2016
35 *
36 */
37 public class DefaultOpenTaxonNodeWizardHandlerE4 extends DefaultOpenHandlerBaseE4<TaxonNodeDto> {
38
39 // @Override
40 // protected TaxonNode getEntity(UUID uuid) {
41 // return CdmStore.getService(ITaxonNodeService.class).load(uuid);
42 // }
43
44 @Override
45 protected void open(TaxonNodeDto entity, Shell shell, EPartService partService) {
46 Collection<MPart> dirtyParts = partService.getDirtyParts();
47 if (!dirtyParts.isEmpty()){
48
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?");
54
55 if (!doSave) {
56 return ;
57 }
58
59 partService.savePart(dirtyPart, false);
60 }
61
62 }
63 }
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());
74 }
75
76 }
77
78 @Override
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());
82 }
83 return false;
84 }
85
86
87
88 }