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
.ui
.section
.classification
;
11 import java
.util
.Collection
;
12 import java
.util
.Collections
;
13 import java
.util
.List
;
16 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
17 import org
.eclipse
.swt
.widgets
.Shell
;
18 import org
.eclipse
.ui
.IWorkbench
;
20 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonNodeService
;
21 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
22 import eu
.etaxonomy
.cdm
.persistence
.dto
.MergeResult
;
23 import eu
.etaxonomy
.taxeditor
.event
.EventUtility
;
24 import eu
.etaxonomy
.taxeditor
.event
.WorkbenchEventConstants
;
25 import eu
.etaxonomy
.taxeditor
.newWizard
.IWizardPageListener
;
26 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySession
;
27 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySessionEnabled
;
28 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
29 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
36 public class EditTaxonNodeWizard
extends AbstractEditWizard
<TaxonNode
> implements ICdmEntitySessionEnabled
{
38 private TaxonNodeWizardPage taxonNodePage
;
39 private IWizardPageListener wizardPageListener
;
40 private ICdmEntitySession cdmEntitySession
;
44 public void init(IWorkbench workbench
, IStructuredSelection selection
) {
45 formFactory
= new CdmFormFactory(getContext().get(Shell
.class).getDisplay());
46 conversation
= CdmStore
.createConversation();
50 * @see eu.etaxonomy.taxeditor.ui.section.classification.AbstractEditWizard#getEntityName()
53 protected String
getEntityName() {
58 * @see eu.etaxonomy.taxeditor.ui.section.classification.AbstractEditWizard#saveEntity()
61 protected void saveEntity() {
62 getConversationHolder().bind();
63 TaxonNode node
= getEntity();
65 MergeResult result
= CdmStore
.getService(ITaxonNodeService
.class).merge(node
, true);
66 EventUtility
.postEvent(WorkbenchEventConstants
.REFRESH_NAME_EDITOR
, node
.getTaxon().getUuid());
70 public void addPages() {
71 taxonNodePage
= new TaxonNodeWizardPage(formFactory
, getConversationHolder(), getEntity(), wizardPageListener
, false);
73 addPage(taxonNodePage
);
76 public void addWizardPageListener(IWizardPageListener wizardPageListener
){
77 this.wizardPageListener
= wizardPageListener
;
81 * @see eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard#setEntity(java.lang.Object)
84 public void setEntity(TaxonNode entity
) {
85 setWindowTitle(String
.format("Edit %s", getEntityName()));
86 if (CdmStore
.isActive() && cdmEntitySession
== null) {
88 cdmEntitySession
= CdmStore
.getCurrentSessionManager().newSession(this, true);
89 cdmEntitySession
.bind();
91 entity
= CdmStore
.getService(ITaxonNodeService
.class).load(entity
.getUuid());
92 super.setEntity(entity
);
99 public ICdmEntitySession
getCdmEntitySession() {
101 return cdmEntitySession
;
108 public Collection
<TaxonNode
> getRootEntities() {
109 return Collections
.singleton(this.getEntity());
116 public Map
<Object
, List
<String
>> getPropertyPathsMap() {
117 // TODO Auto-generated method stub
122 public void dispose() {
123 cdmEntitySession
.dispose();