Revision 9d4c1568
Added by Patrick Plitzner almost 7 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/CharacterEditor.java | ||
---|---|---|
9 | 9 |
*/ |
10 | 10 |
package eu.etaxonomy.taxeditor.editor.workingSet; |
11 | 11 |
|
12 |
import java.util.ArrayList; |
|
13 |
import java.util.Arrays; |
|
14 |
import java.util.HashMap; |
|
15 |
import java.util.List; |
|
16 |
import java.util.Map; |
|
12 | 17 |
import java.util.UUID; |
13 | 18 |
|
14 | 19 |
import javax.annotation.PostConstruct; |
... | ... | |
17 | 22 |
import javax.inject.Named; |
18 | 23 |
|
19 | 24 |
import org.eclipse.e4.ui.di.Focus; |
25 |
import org.eclipse.e4.ui.di.Persist; |
|
20 | 26 |
import org.eclipse.e4.ui.model.application.ui.MDirtyable; |
21 | 27 |
import org.eclipse.e4.ui.services.IServiceConstants; |
22 | 28 |
import org.eclipse.e4.ui.workbench.modeling.ESelectionService; |
... | ... | |
45 | 51 |
import org.eclipse.ui.forms.widgets.FormToolkit; |
46 | 52 |
|
47 | 53 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
54 |
import eu.etaxonomy.cdm.api.service.IFeatureNodeService; |
|
48 | 55 |
import eu.etaxonomy.cdm.api.service.IFeatureTreeService; |
49 | 56 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
50 | 57 |
import eu.etaxonomy.cdm.model.description.Character; |
... | ... | |
57 | 64 |
import eu.etaxonomy.taxeditor.featuretree.FeatureTreeLabelProvider; |
58 | 65 |
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditorComposite; |
59 | 66 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
67 |
import eu.etaxonomy.taxeditor.session.ICdmEntitySession; |
|
68 |
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled; |
|
60 | 69 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
61 | 70 |
import eu.etaxonomy.taxeditor.ui.dialog.selection.FeatureTreeSelectionDialog; |
62 | 71 |
|
... | ... | |
65 | 74 |
* @date 24.05.2017 |
66 | 75 |
* |
67 | 76 |
*/ |
68 |
public class CharacterEditor implements ISelectionChangedListener, ModifyListener{ |
|
77 |
public class CharacterEditor implements ICdmEntitySessionEnabled, ISelectionChangedListener, ModifyListener{
|
|
69 | 78 |
|
70 | 79 |
|
71 | 80 |
private FeatureTreeEditorComposite featureTreeEditorComposite; |
... | ... | |
81 | 90 |
private MDirtyable dirty; |
82 | 91 |
|
83 | 92 |
private ConversationHolder conversation; |
93 |
|
|
94 |
private ICdmEntitySession cdmEntitySession; |
|
95 |
|
|
84 | 96 |
private FeatureTree featureTree; |
85 | 97 |
|
86 | 98 |
public CharacterEditor() { |
87 |
conversation = CdmStore.createConversation(); |
|
99 |
if(conversation==null){ |
|
100 |
conversation = CdmStore.createConversation(); |
|
101 |
} |
|
102 |
if (CdmStore.isActive()) { |
|
103 |
cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true); |
|
104 |
} |
|
88 | 105 |
} |
89 | 106 |
|
90 | 107 |
/** |
... | ... | |
162 | 179 |
init(); |
163 | 180 |
} |
164 | 181 |
|
182 |
@Focus |
|
183 |
public void focus(){ |
|
184 |
featureTreeEditorComposite.getViewer().getControl().setFocus(); |
|
185 |
if(conversation!=null && !conversation.isBound()){ |
|
186 |
conversation.bind(); |
|
187 |
} |
|
188 |
if(cdmEntitySession != null) { |
|
189 |
cdmEntitySession.bind(); |
|
190 |
} |
|
191 |
} |
|
192 |
|
|
165 | 193 |
public void setSelectedTree(FeatureTree featureTree) { |
166 | 194 |
this.featureTree = HibernateProxyHelper.deproxy(featureTree, FeatureTree.class); |
167 | 195 |
this.featureTree.setRoot(HibernateProxyHelper.deproxy(featureTree.getRoot(), FeatureNode.class)); |
... | ... | |
195 | 223 |
public void widgetSelected(SelectionEvent e) { |
196 | 224 |
ISelection structureTreeSelection = treeViewerStructures.getSelection(); |
197 | 225 |
ISelection propertyTreeSelection = treeViewerProperties.getSelection(); |
198 |
if(structureTreeSelection==null || propertyTreeSelection==null /*|| editor.getSelectedFeatureTree()==null*/){
|
|
226 |
if(structureTreeSelection==null || propertyTreeSelection==null || featureTree==null){
|
|
199 | 227 |
MessagingUtils.warningDialog("Cannot perform action", CharacterEditor.this, |
200 | 228 |
"You have to select a structure, a property and a feature tree to perform this action."); |
201 | 229 |
return; |
... | ... | |
206 | 234 |
//create new Character |
207 | 235 |
String label = structureNode.getFeature().toString()+" "+propertyNode.getFeature().toString(); |
208 | 236 |
Character character = Character.NewInstance(structureNode, propertyNode, null, label, label); |
209 |
// CdmStore.getService(ITermService.class).merge(character);
|
|
237 |
// CdmStore.getService(ITermService.class).saveOrUpdate(character);
|
|
210 | 238 |
|
211 | 239 |
//add new Character to feature tree |
212 |
IStructuredSelection selection = (IStructuredSelection) featureTreeEditorComposite.getViewer().getSelection(); |
|
213 |
FeatureNode parent = (FeatureNode) (selection.getFirstElement() != null ? selection.getFirstElement() |
|
214 |
: ((FeatureTree) featureTreeEditorComposite.getViewer().getInput()).getRoot()); |
|
215 |
FeatureNode child = FeatureNode.NewInstance(character); |
|
216 |
// CdmStore.getService(IFeatureNodeService.class).merge(child, true); |
|
240 |
FeatureNode parent = ((FeatureTree) featureTreeEditorComposite.getViewer().getInput()).getRoot(); |
|
241 |
CdmStore.getService(IFeatureNodeService.class).addChildFeaturNode(parent.getUuid(), character.getUuid()); |
|
217 | 242 |
|
218 |
parent.addChild(child); |
|
219 | 243 |
setDirty(true); |
220 | 244 |
featureTreeEditorComposite.getViewer().refresh(); |
221 | 245 |
} |
222 | 246 |
}); |
223 | 247 |
} |
224 | 248 |
|
249 |
@Persist |
|
250 |
public void save(){ |
|
251 |
if (!conversation.isBound()) { |
|
252 |
conversation.bind(); |
|
253 |
} |
|
254 |
|
|
255 |
// commit the conversation and start a new transaction immediately |
|
256 |
conversation.commit(true); |
|
257 |
|
|
258 |
CdmStore.getService(IFeatureTreeService.class).saveOrUpdate(featureTree); |
|
259 |
|
|
260 |
this.setDirty(false); |
|
261 |
} |
|
262 |
|
|
225 | 263 |
@PreDestroy |
226 |
public void dispose() { |
|
264 |
public void dispose(){ |
|
265 |
if(conversation!=null){ |
|
266 |
conversation.close(); |
|
267 |
} |
|
268 |
if(cdmEntitySession != null) { |
|
269 |
cdmEntitySession.dispose(); |
|
270 |
} |
|
271 |
} |
|
272 |
|
|
273 |
@Override |
|
274 |
public Map<Object, List<String>> getPropertyPathsMap() { |
|
275 |
List<String> propertyPaths = Arrays.asList(new String[] { |
|
276 |
"children", //$NON-NLS-1$ |
|
277 |
"feature", //$NON-NLS-1$ |
|
278 |
"featureTree", //$NON-NLS-1$ |
|
279 |
}); |
|
280 |
Map<Object, List<String>> propertyPathMap = |
|
281 |
new HashMap<Object, List<String>>(); |
|
282 |
propertyPathMap.put(FeatureNode.class,propertyPaths); |
|
283 |
return propertyPathMap; |
|
284 |
} |
|
285 |
|
|
286 |
/** |
|
287 |
* {@inheritDoc} |
|
288 |
*/ |
|
289 |
@Override |
|
290 |
public List<FeatureTree> getRootEntities() { |
|
291 |
List<FeatureTree> root = new ArrayList<>(); |
|
292 |
root.add(featureTree); |
|
293 |
return root; |
|
294 |
} |
|
295 |
|
|
296 |
@Override |
|
297 |
public ICdmEntitySession getCdmEntitySession() { |
|
298 |
return cdmEntitySession; |
|
227 | 299 |
} |
228 | 300 |
|
229 | 301 |
@Focus |
... | ... | |
259 | 331 |
setDirty(true); |
260 | 332 |
} |
261 | 333 |
|
262 |
private void setDirty(boolean isDirty) {
|
|
334 |
public void setDirty(boolean isDirty) {
|
|
263 | 335 |
dirty.setDirty(isDirty); |
264 | 336 |
} |
337 |
|
|
265 | 338 |
} |
Also available in: Unified diff
Implement session handling in CharacterEditor