Revision fd61512c
Added by Patrick Plitzner over 5 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/operation/MoveDefinedTermOperation.java | ||
---|---|---|
9 | 9 |
package eu.etaxonomy.taxeditor.editor.definedterm.operation; |
10 | 10 |
|
11 | 11 |
import java.util.Collection; |
12 |
import java.util.UUID; |
|
12 | 13 |
|
13 | 14 |
import org.eclipse.core.commands.ExecutionException; |
14 | 15 |
import org.eclipse.core.commands.operations.IUndoContext; |
15 | 16 |
import org.eclipse.core.runtime.IAdaptable; |
16 | 17 |
import org.eclipse.core.runtime.IProgressMonitor; |
17 | 18 |
import org.eclipse.core.runtime.IStatus; |
18 |
import org.eclipse.core.runtime.Status; |
|
19 |
import org.eclipse.jface.viewers.ViewerDropAdapter; |
|
20 | 19 |
|
20 |
import eu.etaxonomy.cdm.api.service.ITermService; |
|
21 | 21 |
import eu.etaxonomy.cdm.model.common.DefinedTermBase; |
22 |
import eu.etaxonomy.cdm.model.common.OrderedTermBase; |
|
23 |
import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary; |
|
24 |
import eu.etaxonomy.cdm.model.common.TermBase; |
|
25 | 22 |
import eu.etaxonomy.cdm.model.common.TermVocabulary; |
26 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
|
23 |
import eu.etaxonomy.cdm.persistence.dto.AbstractTermDto; |
|
24 |
import eu.etaxonomy.cdm.persistence.dto.TermDto; |
|
27 | 25 |
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation; |
28 | 26 |
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; |
29 |
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
|
27 |
import eu.etaxonomy.taxeditor.store.CdmStore;
|
|
30 | 28 |
|
31 | 29 |
/** |
32 | 30 |
* @author l.morris |
... | ... | |
35 | 33 |
*/ |
36 | 34 |
public class MoveDefinedTermOperation extends AbstractPostTaxonOperation { |
37 | 35 |
|
38 |
private final Collection<DefinedTermBase> sourceTerms;// the actual DefinedTermBase(s) we are moving
|
|
39 |
private final TermBase targetTermOrVocabulary;// the target VOCABULARY or DefinedTerm we are moving these to
|
|
36 |
private final Collection<TermDto> sourceTerms;// the actual DefinedTermBase(s) we are moving
|
|
37 |
private final AbstractTermDto targetTermOrVocabulary;// the target VOCABULARY or DefinedTerm we are moving these to
|
|
40 | 38 |
private final int currentLocation; |
41 | 39 |
|
42 | 40 |
public MoveDefinedTermOperation(String label, |
43 | 41 |
IUndoContext undoContext, |
44 |
TermBase target,
|
|
45 |
Collection<DefinedTermBase> sourceTerms,
|
|
42 |
AbstractTermDto target,
|
|
43 |
Collection<TermDto> sourceTerms,
|
|
46 | 44 |
IPostOperationEnabled postOperationEnabled, |
47 | 45 |
int currentLocation) { |
48 | 46 |
super(label, undoContext, postOperationEnabled); |
... | ... | |
55 | 53 |
@Override |
56 | 54 |
public IStatus execute(IProgressMonitor monitor, IAdaptable info) |
57 | 55 |
throws ExecutionException { |
58 |
|
|
59 |
// need to make the moved DefinedTerm part of another DefinedTerm or Vocabulary (target) |
|
60 |
// and remove it from old associations |
|
61 |
|
|
62 |
//TODO move to ITermService |
|
63 |
|
|
64 |
for (DefinedTermBase term : sourceTerms) { |
|
65 |
// do nothing when moving it on itself |
|
66 |
if(targetTermOrVocabulary.equals(term)){ |
|
67 |
Status status = new Status(IStatus.CANCEL, StoreUtil.getPluginId(), "Term can not be added to itself"); |
|
68 |
MessagingUtils.informationDialog("", status); |
|
69 |
return status; |
|
70 |
} |
|
71 |
|
|
72 |
if (targetTermOrVocabulary instanceof TermVocabulary) { |
|
73 |
TermVocabulary termVocabulary = (TermVocabulary)targetTermOrVocabulary; |
|
74 |
|
|
75 |
// do nothing when term is top level and gets added to the same vocabulary |
|
76 |
if(term.getPartOf() == null && termVocabulary.equals(term.getVocabulary())){ |
|
77 |
Status status = new Status(IStatus.CANCEL, StoreUtil.getPluginId(), "Term is already in this vocabulary"); |
|
78 |
MessagingUtils.informationDialog("", status); |
|
79 |
return status; |
|
80 |
} |
|
81 |
|
|
82 |
cleanTerm(term); |
|
83 |
termVocabulary.addTerm(term); |
|
84 |
|
|
85 |
} else if (targetTermOrVocabulary instanceof DefinedTermBase) { |
|
86 |
cleanTerm(term); |
|
87 |
DefinedTermBase targetDefinedTerm = (DefinedTermBase) targetTermOrVocabulary; |
|
88 |
|
|
89 |
if(targetDefinedTerm instanceof OrderedTermBase && term instanceof OrderedTermBase) { |
|
90 |
OrderedTermBase targetOrderedDefinedTerm = (OrderedTermBase)targetDefinedTerm; |
|
91 |
TermVocabulary tVoc = targetOrderedDefinedTerm.getVocabulary(); |
|
92 |
if(tVoc instanceof OrderedTermVocabulary) { |
|
93 |
OrderedTermVocabulary otVoc = (OrderedTermVocabulary)tVoc; |
|
94 |
// the link between the location and the add term (below / above) |
|
95 |
// method is determined by the compare method in the |
|
96 |
// DefinedTermEditor's ViewerSorter (DefinedTermSorter) class |
|
97 |
if(currentLocation == ViewerDropAdapter.LOCATION_BEFORE) { |
|
98 |
otVoc.addTermAbove((OrderedTermBase)term, (OrderedTermBase)targetTermOrVocabulary); |
|
99 |
if (targetOrderedDefinedTerm.getPartOf() != null){ |
|
100 |
targetOrderedDefinedTerm.getPartOf().addIncludes(term); |
|
101 |
} |
|
102 |
} |
|
103 |
|
|
104 |
if(currentLocation == ViewerDropAdapter.LOCATION_AFTER) { |
|
105 |
otVoc.addTermBelow((OrderedTermBase)term, (OrderedTermBase)targetTermOrVocabulary); |
|
106 |
if (targetOrderedDefinedTerm.getPartOf() != null){ |
|
107 |
targetOrderedDefinedTerm.getPartOf().addIncludes(term); |
|
108 |
} |
|
109 |
} |
|
110 |
if(currentLocation == ViewerDropAdapter.LOCATION_ON) { |
|
111 |
targetOrderedDefinedTerm.addIncludes(term); |
|
112 |
targetOrderedDefinedTerm.getVocabulary().addTerm(term); |
|
113 |
} |
|
114 |
} |
|
115 |
} else{ |
|
116 |
targetDefinedTerm.addIncludes(term); |
|
117 |
targetDefinedTerm.getVocabulary().addTerm(term); |
|
118 |
} |
|
119 |
|
|
120 |
} |
|
121 |
|
|
122 |
} |
|
56 |
sourceTerms.forEach(term-> |
|
57 |
{ |
|
58 |
UUID parentUuid = targetTermOrVocabulary.getUuid(); |
|
59 |
boolean isKindOf = term.getKindOfUuid()!=null && term.getKindOfUuid().equals(parentUuid); |
|
60 |
CdmStore.getService(ITermService.class).moveTerm(term.getUuid(), parentUuid, isKindOf); |
|
61 |
//FIXME: implement moving for ordered terms |
|
62 |
}); |
|
63 |
// // need to make the moved DefinedTerm part of another DefinedTerm or Vocabulary (target) |
|
64 |
// // and remove it from old associations |
|
65 |
// |
|
66 |
// |
|
67 |
// for (DefinedTermBase term : sourceTerms) { |
|
68 |
// // do nothing when moving it on itself |
|
69 |
// if(targetTermOrVocabulary.equals(term)){ |
|
70 |
// Status status = new Status(IStatus.CANCEL, StoreUtil.getPluginId(), "Term can not be added to itself"); |
|
71 |
// MessagingUtils.informationDialog("", status); |
|
72 |
// return status; |
|
73 |
// } |
|
74 |
// |
|
75 |
// if (targetTermOrVocabulary instanceof TermVocabulary) { |
|
76 |
// TermVocabulary termVocabulary = (TermVocabulary)targetTermOrVocabulary; |
|
77 |
// |
|
78 |
// // do nothing when term is top level and gets added to the same vocabulary |
|
79 |
// if(term.getPartOf() == null && termVocabulary.equals(term.getVocabulary())){ |
|
80 |
// Status status = new Status(IStatus.CANCEL, StoreUtil.getPluginId(), "Term is already in this vocabulary"); |
|
81 |
// MessagingUtils.informationDialog("", status); |
|
82 |
// return status; |
|
83 |
// } |
|
84 |
// |
|
85 |
// cleanTerm(term); |
|
86 |
// termVocabulary.addTerm(term); |
|
87 |
// |
|
88 |
// } else if (targetTermOrVocabulary instanceof DefinedTermBase) { |
|
89 |
// cleanTerm(term); |
|
90 |
// DefinedTermBase targetDefinedTerm = (DefinedTermBase) targetTermOrVocabulary; |
|
91 |
// |
|
92 |
// if(targetDefinedTerm instanceof OrderedTermBase && term instanceof OrderedTermBase) { |
|
93 |
// OrderedTermBase targetOrderedDefinedTerm = (OrderedTermBase)targetDefinedTerm; |
|
94 |
// TermVocabulary tVoc = targetOrderedDefinedTerm.getVocabulary(); |
|
95 |
// if(tVoc instanceof OrderedTermVocabulary) { |
|
96 |
// OrderedTermVocabulary otVoc = (OrderedTermVocabulary)tVoc; |
|
97 |
// // the link between the location and the add term (below / above) |
|
98 |
// // method is determined by the compare method in the |
|
99 |
// // DefinedTermEditor's ViewerSorter (DefinedTermSorter) class |
|
100 |
// if(currentLocation == ViewerDropAdapter.LOCATION_BEFORE) { |
|
101 |
// otVoc.addTermAbove((OrderedTermBase)term, (OrderedTermBase)targetTermOrVocabulary); |
|
102 |
// if (targetOrderedDefinedTerm.getPartOf() != null){ |
|
103 |
// targetOrderedDefinedTerm.getPartOf().addIncludes(term); |
|
104 |
// } |
|
105 |
// } |
|
106 |
// |
|
107 |
// if(currentLocation == ViewerDropAdapter.LOCATION_AFTER) { |
|
108 |
// otVoc.addTermBelow((OrderedTermBase)term, (OrderedTermBase)targetTermOrVocabulary); |
|
109 |
// if (targetOrderedDefinedTerm.getPartOf() != null){ |
|
110 |
// targetOrderedDefinedTerm.getPartOf().addIncludes(term); |
|
111 |
// } |
|
112 |
// } |
|
113 |
// if(currentLocation == ViewerDropAdapter.LOCATION_ON) { |
|
114 |
// targetOrderedDefinedTerm.addIncludes(term); |
|
115 |
// targetOrderedDefinedTerm.getVocabulary().addTerm(term); |
|
116 |
// } |
|
117 |
// } |
|
118 |
// } else{ |
|
119 |
// targetDefinedTerm.addIncludes(term); |
|
120 |
// targetDefinedTerm.getVocabulary().addTerm(term); |
|
121 |
// } |
|
122 |
// |
|
123 |
// } |
|
124 |
// |
|
125 |
// } |
|
123 | 126 |
return postExecute(targetTermOrVocabulary); |
124 | 127 |
} |
125 | 128 |
|
Also available in: Unified diff
ref #7887 Adapt moving terms based on DTOs