1
|
package eu.etaxonomy.taxeditor.editor.name.operation;
|
2
|
|
3
|
import java.util.ArrayList;
|
4
|
import java.util.List;
|
5
|
import java.util.UUID;
|
6
|
|
7
|
import org.eclipse.core.commands.ExecutionException;
|
8
|
import org.eclipse.core.commands.operations.IUndoContext;
|
9
|
import org.eclipse.core.runtime.IAdaptable;
|
10
|
import org.eclipse.core.runtime.IProgressMonitor;
|
11
|
import org.eclipse.core.runtime.IStatus;
|
12
|
|
13
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
14
|
import eu.etaxonomy.cdm.api.service.exception.HomotypicalGroupChangeException;
|
15
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
16
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
17
|
import eu.etaxonomy.cdm.model.taxon.SynonymRelationship;
|
18
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
19
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
20
|
import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
|
21
|
import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
|
22
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
23
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
24
|
|
25
|
public class MoveSynonymToAnotherAcceptedTaxonOperation extends
|
26
|
AbstractPostTaxonOperation {
|
27
|
|
28
|
/**
|
29
|
* The synonym to be moved.
|
30
|
*/
|
31
|
private final Synonym synonym;
|
32
|
|
33
|
private final Taxon oldTaxon;
|
34
|
|
35
|
|
36
|
/**
|
37
|
* <p>Constructor for MoveSynonymToAnotherAcceptedTaxon.</p>
|
38
|
*
|
39
|
* @param label a {@link java.lang.String} object.
|
40
|
* @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
|
41
|
* @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
|
42
|
* @param synonym a {@link eu.etaxonomy.cdm.model.taxon.Synonym} object.
|
43
|
|
44
|
* @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
|
45
|
*/
|
46
|
public MoveSynonymToAnotherAcceptedTaxonOperation(String label, IUndoContext undoContext,
|
47
|
UUID oldTaxonUUID, UUID synonymUUID, Taxon taxon, IPostOperationEnabled postOperationEnabled) {
|
48
|
|
49
|
super(label, undoContext, taxon, postOperationEnabled);
|
50
|
List<String> propertyPaths = new ArrayList<String>();
|
51
|
propertyPaths.add("synonymRelations");
|
52
|
this.element = (Taxon) CdmStore.getService(ITaxonService.class).load(taxon.getUuid(),propertyPaths);
|
53
|
this.oldTaxon = (Taxon) CdmStore.getService(ITaxonService.class).load(oldTaxonUUID);
|
54
|
this.synonym = (Synonym) CdmStore.getService(ITaxonService.class).load(synonymUUID);
|
55
|
if(synonym == null){
|
56
|
throw new IllegalArgumentException(
|
57
|
"A null synonym was provided.");
|
58
|
}
|
59
|
}
|
60
|
|
61
|
@Override
|
62
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info)
|
63
|
throws ExecutionException {
|
64
|
|
65
|
// Get synonym name
|
66
|
TaxonNameBase<?, ?> synonymName = synonym.getName();
|
67
|
monitor.worked(20);
|
68
|
|
69
|
|
70
|
|
71
|
// Switch groups
|
72
|
|
73
|
monitor.worked(40);
|
74
|
SynonymRelationship synRel = synonym.getSynonymRelations().iterator().next();
|
75
|
|
76
|
|
77
|
|
78
|
((TaxonNameEditor)EditorUtil.getActiveMultiPageTaxonEditor().getActiveEditor()).getConversationHolder().commit();
|
79
|
|
80
|
|
81
|
|
82
|
try {
|
83
|
synRel = (SynonymRelationship) CdmStore.getService(ITaxonService.class).moveSynonymToAnotherTaxon(synRel,
|
84
|
this.element.getUuid(),
|
85
|
true,
|
86
|
synRel.getType(),
|
87
|
null,
|
88
|
null,
|
89
|
true).getCdmEntity();
|
90
|
} catch (HomotypicalGroupChangeException e) {
|
91
|
// TODO Auto-generated catch block
|
92
|
e.printStackTrace();
|
93
|
}
|
94
|
((TaxonNameEditor)EditorUtil.getActiveMultiPageTaxonEditor().getActiveEditor()).getConversationHolder().commit();
|
95
|
|
96
|
|
97
|
|
98
|
// Redraw editor if it exists
|
99
|
return postExecute(synRel.getSynonym());
|
100
|
}
|
101
|
|
102
|
@Override
|
103
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info)
|
104
|
throws ExecutionException {
|
105
|
// TODO Auto-generated method stub
|
106
|
return null;
|
107
|
}
|
108
|
|
109
|
@Override
|
110
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info)
|
111
|
throws ExecutionException {
|
112
|
// TODO Auto-generated method stub
|
113
|
return null;
|
114
|
}
|
115
|
|
116
|
}
|