59 |
59 |
|
60 |
60 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
61 |
61 |
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
62 |
|
import eu.etaxonomy.cdm.api.service.IFeatureNodeService;
|
63 |
62 |
import eu.etaxonomy.cdm.api.service.ITermNodeService;
|
64 |
63 |
import eu.etaxonomy.cdm.api.service.ITermTreeService;
|
65 |
64 |
import eu.etaxonomy.cdm.api.service.IVocabularyService;
|
66 |
65 |
import eu.etaxonomy.cdm.api.service.UpdateResult;
|
|
66 |
import eu.etaxonomy.cdm.model.common.Language;
|
67 |
67 |
import eu.etaxonomy.cdm.model.description.Character;
|
68 |
68 |
import eu.etaxonomy.cdm.model.description.Feature;
|
69 |
69 |
import eu.etaxonomy.cdm.model.term.DefinedTerm;
|
70 |
70 |
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
|
|
71 |
import eu.etaxonomy.cdm.model.term.Representation;
|
71 |
72 |
import eu.etaxonomy.cdm.model.term.TermNode;
|
72 |
73 |
import eu.etaxonomy.cdm.model.term.TermTree;
|
73 |
74 |
import eu.etaxonomy.cdm.model.term.TermType;
|
74 |
75 |
import eu.etaxonomy.cdm.model.term.TermVocabulary;
|
75 |
76 |
import eu.etaxonomy.cdm.model.term.VocabularyEnum;
|
|
77 |
import eu.etaxonomy.cdm.persistence.dto.CharacterDto;
|
76 |
78 |
import eu.etaxonomy.cdm.persistence.dto.CharacterNodeDto;
|
77 |
79 |
import eu.etaxonomy.cdm.persistence.dto.TermNodeDto;
|
78 |
80 |
import eu.etaxonomy.cdm.persistence.dto.TermTreeDto;
|
... | ... | |
96 |
98 |
import eu.etaxonomy.taxeditor.model.ImageResources;
|
97 |
99 |
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
98 |
100 |
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
|
|
101 |
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
99 |
102 |
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
|
100 |
103 |
import eu.etaxonomy.taxeditor.store.CdmStore;
|
|
104 |
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
101 |
105 |
import eu.etaxonomy.taxeditor.ui.dialog.selection.FeatureTreeSelectionDialog;
|
102 |
106 |
import eu.etaxonomy.taxeditor.ui.dialog.selection.TermVocabularySelectionDialog;
|
|
107 |
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
|
103 |
108 |
import eu.etaxonomy.taxeditor.workbench.part.IE4ViewerPart;
|
104 |
109 |
|
105 |
110 |
/**
|
... | ... | |
109 |
114 |
*
|
110 |
115 |
*/
|
111 |
116 |
public class CharacterEditor implements ICharacterEditor, IConversationEnabled, ISelectionChangedListener,
|
112 |
|
ModifyListener, IE4ViewerPart, IPartContentHasDetails, IPartContentHasSupplementalData, IDirtyMarkable {
|
|
117 |
ModifyListener, IE4ViewerPart, IPartContentHasDetails, IPartContentHasSupplementalData, IDirtyMarkable, IE4SavablePart {
|
113 |
118 |
|
114 |
119 |
private FeatureTreeDtoEditorComposite characterTreeEditorComposite;
|
115 |
120 |
private final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
|
... | ... | |
135 |
140 |
|
136 |
141 |
private List<CharacterNodeDto> nodesToUpdate = new ArrayList<>();
|
137 |
142 |
|
|
143 |
private Map<Character, CharacterNodeDto> nodesToSave = new HashMap<>();
|
138 |
144 |
|
139 |
145 |
public CharacterEditor() {
|
140 |
146 |
}
|
... | ... | |
227 |
233 |
if(!isVocabularySet()){
|
228 |
234 |
return;
|
229 |
235 |
}
|
|
236 |
if (confirmSaveDirty()){
|
|
237 |
return;
|
|
238 |
}
|
230 |
239 |
ISelection structureTreeSelection = structureViewer.getSelection();
|
231 |
240 |
ISelection propertyTreeSelection = propertyViewer.getSelection();
|
232 |
241 |
if(structureTreeSelection==null || propertyTreeSelection==null || characterTreeEditorComposite.getFeatureTree()==null){
|
... | ... | |
236 |
245 |
}
|
237 |
246 |
Collection<Character> characters = createCharacters((TreeSelection)structureTreeSelection, (TreeSelection)propertyTreeSelection);
|
238 |
247 |
TermNodeDto parent = characterTreeEditorComposite.getFeatureTree().getRoot();
|
|
248 |
UpdateResult result = null;
|
|
249 |
TermTree tree = null;
|
239 |
250 |
for (Character character : characters) {
|
240 |
251 |
//add new Character to feature tree
|
241 |
|
|
242 |
|
|
243 |
|
UpdateResult result = CdmStore.getService(IFeatureNodeService.class).createChildFeatureNode(parent.getUuid(), character, vocabulary.getUuid());
|
244 |
|
cdmEntitySession.load(result, true);
|
245 |
|
characterTreeEditorComposite.setSelectedTree((TermTree)((TermNode)result.getCdmEntity()).getGraph());
|
246 |
|
|
|
252 |
CharacterNodeDto nodeDto = new CharacterNodeDto(CharacterDto.fromCharacter(character), parent, 0, parent.getTree(), null, null, null);
|
|
253 |
nodesToSave.put(character, nodeDto);
|
|
254 |
nodesToUpdate.add(nodeDto);
|
|
255 |
setDirty();
|
|
256 |
// result = CdmStore.getService(IFeatureNodeService.class).createChildFeatureNode(parent.getUuid(), character, vocabulary.getUuid());
|
|
257 |
// cdmEntitySession.load(result, true);
|
|
258 |
// if(result != null && result.getCdmEntity() != null){
|
|
259 |
// tree = (TermTree)((TermNode)result.getCdmEntity()).getGraph();
|
|
260 |
// }
|
|
261 |
}
|
|
262 |
if (tree != null){
|
|
263 |
characterTreeEditorComposite.setSelectedTree(tree);
|
247 |
264 |
}
|
248 |
265 |
|
249 |
266 |
refresh();
|
... | ... | |
338 |
355 |
Iterator<TermNode<DefinedTerm>> propertiesIterator = propertyTreeSelection.iterator();
|
339 |
356 |
while(propertiesIterator.hasNext()){
|
340 |
357 |
TermNode<DefinedTerm> propertyNode = propertiesIterator.next();
|
341 |
|
Character character = CharacterTransfer.createCharacter(structureNode, propertyNode);
|
|
358 |
Representation structureRepresentation = structureNode.getTerm().getRepresentation(PreferencesUtil.getGlobalLanguage());
|
|
359 |
if(structureRepresentation==null){
|
|
360 |
structureRepresentation = structureNode.getTerm().getRepresentation(Language.DEFAULT());
|
|
361 |
}
|
|
362 |
Representation propertyRepresentation = propertyNode.getTerm().getRepresentation(PreferencesUtil.getGlobalLanguage());
|
|
363 |
if(propertyRepresentation==null){
|
|
364 |
propertyRepresentation = propertyNode.getTerm().getRepresentation(Language.DEFAULT());
|
|
365 |
}
|
|
366 |
String label = null;
|
|
367 |
String abbrevLabel = null;
|
|
368 |
if(structureRepresentation!=null && propertyRepresentation!=null){
|
|
369 |
if(structureRepresentation.getLabel()!=null && propertyRepresentation.getLabel()!=null){
|
|
370 |
label = structureRepresentation.getLabel()+" "+propertyRepresentation.getLabel();
|
|
371 |
}
|
|
372 |
if(structureRepresentation.getAbbreviatedLabel()!=null && propertyRepresentation.getAbbreviatedLabel()!=null){
|
|
373 |
abbrevLabel = structureRepresentation.getAbbreviatedLabel()+" "+propertyRepresentation.getAbbreviatedLabel();
|
|
374 |
}
|
|
375 |
}
|
|
376 |
if(label!=null){
|
|
377 |
//default label
|
|
378 |
label = structureNode.getTerm().getLabel()+" "+propertyNode.getTerm().getLabel();
|
|
379 |
}
|
|
380 |
Character character = Character.NewInstance(structureNode, structureNode, null, label, abbrevLabel);
|
342 |
381 |
characters.add(character);
|
343 |
382 |
|
344 |
383 |
}
|
... | ... | |
352 |
391 |
if (!conversation.isBound()) {
|
353 |
392 |
conversation.bind();
|
354 |
393 |
}
|
355 |
|
|
|
394 |
UpdateResult result = new UpdateResult();
|
|
395 |
if (nodesToSave != null && this.getVocabulary() != null) {
|
|
396 |
result.includeResult(CdmStore.getService(ITermNodeService.class).saveNewCharacterNodeDtoMap(this.nodesToSave, this.getVocabulary().getUuid()));
|
|
397 |
}
|
|
398 |
nodesToSave.clear();
|
356 |
399 |
TermTreeDto featureTree = characterTreeEditorComposite.getFeatureTree();
|
357 |
400 |
if (operations != null && !operations.isEmpty()){
|
358 |
401 |
for (AbstractPostOperation<TermNode> operation: operations){
|
... | ... | |
363 |
406 |
|
364 |
407 |
// TODO: implement update method for dto
|
365 |
408 |
|
366 |
|
CdmStore.getService(ITermNodeService.class).saveCharacterNodeDtoList(this.nodesToUpdate);
|
|
409 |
result.includeResult(CdmStore.getService(ITermNodeService.class).saveCharacterNodeDtoList(this.nodesToUpdate));
|
367 |
410 |
nodesToUpdate.clear();
|
368 |
411 |
// commit the conversation and start a new transaction immediately
|
369 |
412 |
conversation.commit(true);
|
|
413 |
if (result.getUpdatedObjects() != null && !result.getUpdatedObjects().isEmpty()){
|
|
414 |
Object o = result.getUpdatedObjects().iterator().next();
|
|
415 |
if (o instanceof TermNode){
|
|
416 |
TermNode node = (TermNode)o;
|
|
417 |
TermTree updateTree = (TermTree)node.getGraph();
|
|
418 |
if (updateTree != null){
|
|
419 |
characterTreeEditorComposite.setSelectedTree(updateTree);
|
|
420 |
}
|
|
421 |
}
|
|
422 |
|
|
423 |
}
|
370 |
424 |
|
371 |
425 |
// initializeTrees();
|
372 |
426 |
|
... | ... | |
407 |
461 |
return vocabulary!=null;
|
408 |
462 |
}
|
409 |
463 |
|
|
464 |
public boolean confirmSaveDirty(){
|
|
465 |
return StoreUtil.promptCheckIsDirty(this);
|
|
466 |
}
|
|
467 |
|
410 |
468 |
public TermVocabulary getVocabulary() {
|
411 |
469 |
return vocabulary;
|
412 |
470 |
}
|
ref #8774: fix save of newly created character nodes