23e7478d257c5de9106233f473bbacaca935865d
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / featuretree / FeatureTreeEditorWizard.java
1 /**
2 * Copyright (C) 2007 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
10 package eu.etaxonomy.taxeditor.featuretree;
11
12 import java.util.Arrays;
13 import java.util.List;
14 import java.util.Map;
15
16 import org.eclipse.jface.wizard.Wizard;
17
18 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
19 import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
20 import eu.etaxonomy.cdm.model.description.FeatureTree;
21 import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
22 import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
23 import eu.etaxonomy.taxeditor.store.CdmStore;
24
25 /**
26 * <p>FeatureTreeEditorWizard class.</p>
27 *
28 * @author n.hoffmann
29 * @created Aug 5, 2010
30 * @version 1.0
31 */
32 public class FeatureTreeEditorWizard extends Wizard implements ICdmEntitySessionEnabled {
33
34 private SelectFeatureTreeWizardPage selectFeatureTreePage;
35 private EditFeatureTreeWizardPage editFeatureTreePage;
36
37 private FeatureTree selectedFeatureTree;
38
39 private ConversationHolder conversation;
40 private ICdmEntitySession cdmEntitySession;
41 private ICdmEntitySession previousCdmEntitySession;
42
43 /**
44 * <p>Constructor for FeatureTreeEditorWizard.</p>
45 */
46 public FeatureTreeEditorWizard(){
47 conversation = CdmStore.createConversation();
48 previousCdmEntitySession = CdmStore.getCurrentSessionManager().getActiveSession();
49 cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true);
50 setWindowTitle("Feature Tree Editor");
51 }
52
53 /**
54 * <p>addPages</p>
55 */
56 @Override
57 public void addPages() {
58 selectFeatureTreePage = new SelectFeatureTreeWizardPage("SELECT");
59 addPage(selectFeatureTreePage);
60
61 editFeatureTreePage = new EditFeatureTreeWizardPage("EDIT");
62 addPage(editFeatureTreePage);
63 }
64
65
66
67 /** {@inheritDoc} */
68 @Override
69 public boolean performFinish() {
70 try{
71 if (selectedFeatureTree != null){
72 CdmStore.getService(IFeatureTreeService.class).merge(selectedFeatureTree, true);
73 }
74 conversation.commit();
75 }finally{
76 conversation.close();
77 cdmEntitySession.dispose();
78 if(previousCdmEntitySession != null) {
79 previousCdmEntitySession.bind();
80 }
81 }
82
83 return true;
84 }
85
86 /** {@inheritDoc} */
87 @Override
88 public boolean performCancel() {
89 cdmEntitySession.dispose();
90 if(previousCdmEntitySession != null) {
91 previousCdmEntitySession.bind();
92 }
93 return true;
94 }
95
96 /**
97 * <p>Setter for the field <code>selectedFeatureTree</code>.</p>
98 *
99 * @param selectedFeatureTree the selectedFeatureTree to set
100 */
101 public void setSelectedFeatureTree(FeatureTree selectedFeatureTree) {
102 this.selectedFeatureTree = selectedFeatureTree;
103 editFeatureTreePage.setSelectedTree(selectedFeatureTree);
104 }
105
106 /**
107 * <p>Getter for the field <code>selectedFeatureTree</code>.</p>
108 *
109 * @return the selectedFeatureTree
110 */
111 public FeatureTree getSelectedFeatureTree() {
112 return selectedFeatureTree;
113 }
114
115 /* (non-Javadoc)
116 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getCdmEntitySession()
117 */
118 @Override
119 public ICdmEntitySession getCdmEntitySession() {
120 // TODO Auto-generated method stub
121 return null;
122 }
123
124 /* (non-Javadoc)
125 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
126 */
127 @Override
128 public List<FeatureTree> getRootEntities() {
129 return Arrays.asList(selectedFeatureTree);
130 }
131
132 /* (non-Javadoc)
133 * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getPropertyPathsMap()
134 */
135 @Override
136 public Map<Object, List<String>> getPropertyPathsMap() {
137 // TODO Auto-generated method stub
138 return null;
139 }
140
141 }