Revision 0343d833
Added by Patrick Plitzner almost 7 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/FeatureTreeEditor.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
package eu.etaxonomy.taxeditor.featuretree.e4; |
11 | 11 |
|
12 |
import java.util.ArrayList; |
|
13 |
import java.util.Arrays; |
|
12 | 14 |
import java.util.Collection; |
15 |
import java.util.HashMap; |
|
16 |
import java.util.List; |
|
17 |
import java.util.Map; |
|
13 | 18 |
|
14 | 19 |
import javax.annotation.PostConstruct; |
20 |
import javax.annotation.PreDestroy; |
|
15 | 21 |
import javax.inject.Inject; |
16 | 22 |
import javax.inject.Named; |
17 | 23 |
|
... | ... | |
42 | 48 |
import eu.etaxonomy.cdm.model.description.FeatureNode; |
43 | 49 |
import eu.etaxonomy.cdm.model.description.FeatureTree; |
44 | 50 |
import eu.etaxonomy.taxeditor.featuretree.AvailableFeaturesWizard; |
51 |
import eu.etaxonomy.taxeditor.session.ICdmEntitySession; |
|
52 |
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled; |
|
45 | 53 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
46 | 54 |
import eu.etaxonomy.taxeditor.ui.dialog.selection.FeatureTreeSelectionDialog; |
47 | 55 |
|
... | ... | |
51 | 59 |
* @date 06.06.2017 |
52 | 60 |
* |
53 | 61 |
*/ |
54 |
public class FeatureTreeEditor implements |
|
62 |
public class FeatureTreeEditor implements ICdmEntitySessionEnabled,
|
|
55 | 63 |
ModifyListener, ISelectionChangedListener { |
56 | 64 |
|
57 | 65 |
private ConversationHolder conversation; |
58 | 66 |
|
67 |
private ICdmEntitySession cdmEntitySession; |
|
68 |
|
|
59 | 69 |
@Inject |
60 | 70 |
private ESelectionService selService; |
61 | 71 |
|
... | ... | |
74 | 84 |
if(conversation==null){ |
75 | 85 |
conversation = CdmStore.createConversation(); |
76 | 86 |
} |
87 |
if (CdmStore.isActive()) { |
|
88 |
cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true); |
|
89 |
} |
|
77 | 90 |
} |
78 | 91 |
|
79 | 92 |
/** {@inheritDoc} */ |
... | ... | |
137 | 150 |
if(conversation!=null && !conversation.isBound()){ |
138 | 151 |
conversation.bind(); |
139 | 152 |
} |
153 |
if(cdmEntitySession != null) { |
|
154 |
cdmEntitySession.bind(); |
|
155 |
} |
|
140 | 156 |
} |
141 | 157 |
|
142 | 158 |
@Persist |
143 | 159 |
public void save(){ |
144 |
CdmStore.getService(IFeatureTreeService.class).saveOrUpdate(featureTree); |
|
145 |
setDirty(false); |
|
160 |
if (!conversation.isBound()) { |
|
161 |
conversation.bind(); |
|
162 |
} |
|
163 |
|
|
164 |
// commit the conversation and start a new transaction immediately |
|
165 |
conversation.commit(true); |
|
166 |
|
|
167 |
CdmStore.getService(IFeatureTreeService.class).merge(featureTree); |
|
168 |
|
|
169 |
this.setDirty(false); |
|
170 |
} |
|
171 |
|
|
172 |
@PreDestroy |
|
173 |
public void dispose(){ |
|
174 |
if(conversation!=null){ |
|
175 |
conversation.close(); |
|
176 |
} |
|
177 |
if(cdmEntitySession != null) { |
|
178 |
cdmEntitySession.dispose(); |
|
179 |
} |
|
146 | 180 |
} |
147 | 181 |
|
182 |
@Override |
|
183 |
public ICdmEntitySession getCdmEntitySession() { |
|
184 |
return cdmEntitySession; |
|
185 |
} |
|
186 |
|
|
187 |
@Override |
|
188 |
public Map<Object, List<String>> getPropertyPathsMap() { |
|
189 |
List<String> propertyPaths = Arrays.asList(new String[] { |
|
190 |
"children", //$NON-NLS-1$ |
|
191 |
"feature", //$NON-NLS-1$ |
|
192 |
"featureTree", //$NON-NLS-1$ |
|
193 |
}); |
|
194 |
Map<Object, List<String>> propertyPathMap = |
|
195 |
new HashMap<Object, List<String>>(); |
|
196 |
propertyPathMap.put(FeatureNode.class,propertyPaths); |
|
197 |
return propertyPathMap; |
|
198 |
} |
|
199 |
|
|
200 |
/** |
|
201 |
* {@inheritDoc} |
|
202 |
*/ |
|
203 |
@Override |
|
204 |
public List<FeatureTree> getRootEntities() { |
|
205 |
List<FeatureTree> root = new ArrayList<>(); |
|
206 |
root.add(featureTree); |
|
207 |
return root; |
|
208 |
} |
|
209 |
|
|
148 | 210 |
private class AddButtonListener extends SelectionAdapter { |
149 | 211 |
@Override |
150 | 212 |
public void widgetSelected(SelectionEvent e) { |
Also available in: Unified diff
ref #6694 Add CdmEntitySessionHandling to feature tree editor