1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.taxeditor.editor.name.operation;
|
11
|
|
12
|
import java.util.Set;
|
13
|
|
14
|
import org.eclipse.core.commands.ExecutionException;
|
15
|
import org.eclipse.core.commands.operations.IUndoContext;
|
16
|
import org.eclipse.core.runtime.IAdaptable;
|
17
|
import org.eclipse.core.runtime.IProgressMonitor;
|
18
|
import org.eclipse.core.runtime.IStatus;
|
19
|
|
20
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
21
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
22
|
import eu.etaxonomy.cdm.api.service.UpdateResult;
|
23
|
import eu.etaxonomy.cdm.api.service.exception.HomotypicalGroupChangeException;
|
24
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
25
|
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
|
26
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
27
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
28
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
29
|
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
|
30
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
31
|
import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
|
32
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
33
|
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
|
34
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
35
|
|
36
|
/**
|
37
|
* Change the taxonomic parent of a given taxon.
|
38
|
*
|
39
|
* @author n.hoffmann
|
40
|
* @created 16.01.2009
|
41
|
*/
|
42
|
public class ChangeSynonymToAcceptedTaxonOperation extends AbstractPersistentPostOperation {
|
43
|
|
44
|
private final Synonym synonym;
|
45
|
private final ITaxonTreeNode parentNode;
|
46
|
|
47
|
private TaxonNode newNode;
|
48
|
|
49
|
//private final Set<TaxonName> namesInHomotypicGroup;
|
50
|
|
51
|
/**
|
52
|
* <p>Constructor for ChangeSynonymToAcceptedTaxonOperation.</p>
|
53
|
*
|
54
|
* @param label a {@link java.lang.String} object.
|
55
|
* @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
|
56
|
* @param taxon a {@link eu.etaxonomy.cdm.model.taxon.Taxon} object.
|
57
|
* @param parentNode a {@link eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode} object.
|
58
|
* @param synonym a {@link eu.etaxonomy.cdm.model.taxon.Synonym} object.
|
59
|
* @param synonymsInHomotypicalGroup an array of {@link eu.etaxonomy.cdm.model.taxon.Synonym} objects.
|
60
|
* @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
|
61
|
* @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
|
62
|
*/
|
63
|
public ChangeSynonymToAcceptedTaxonOperation(String label,
|
64
|
IUndoContext undoContext,
|
65
|
Taxon taxon,
|
66
|
ITaxonTreeNode parentNode,
|
67
|
Synonym synonym,
|
68
|
Set<TaxonName> namesInHomotypicalGroup,
|
69
|
IPostOperationEnabled postOperationEnabled,
|
70
|
IConversationEnabled conversationEnabled,
|
71
|
ICdmEntitySessionEnabled cdmEntitySessionEnabled) {
|
72
|
super(label, undoContext, postOperationEnabled, conversationEnabled, cdmEntitySessionEnabled);
|
73
|
|
74
|
this.element = taxon;
|
75
|
this.parentNode = parentNode;
|
76
|
this.synonym = synonym;
|
77
|
//this.namesInHomotypicGroup = namesInHomotypicalGroup;
|
78
|
}
|
79
|
|
80
|
|
81
|
/** {@inheritDoc} */
|
82
|
@Override
|
83
|
public IStatus execute(IProgressMonitor monitor, IAdaptable info)
|
84
|
throws ExecutionException {
|
85
|
|
86
|
|
87
|
UpdateResult result;
|
88
|
try {
|
89
|
result = CdmStore.getService(ITaxonService.class).changeSynonymToAcceptedTaxon(synonym.getUuid(),
|
90
|
element.getUuid(),
|
91
|
parentNode.getUuid(),
|
92
|
true);
|
93
|
if (result.isAbort()){
|
94
|
|
95
|
MessagingUtils.warningDialog(Messages.ChangeSynonymToAcceptedTaxonOperation_INCONSISTENT_DATA, getClass(), result.toString());
|
96
|
return postExecute(null);
|
97
|
}
|
98
|
newNode = (TaxonNode) result.getCdmEntity();
|
99
|
} catch (HomotypicalGroupChangeException e) {
|
100
|
// TODO Auto-generated catch block
|
101
|
e.printStackTrace();
|
102
|
}
|
103
|
|
104
|
|
105
|
monitor.worked(20);
|
106
|
//newTaxon = (Taxon) CdmStore.getService(ITaxonService.class).merge(newTaxon);
|
107
|
//element.removeSynonym(synonym);
|
108
|
|
109
|
|
110
|
/*if(namesInHomotypicGroup != null){
|
111
|
Taxon taxon = newNode.getTaxon();
|
112
|
for (TaxonNameBase synonymName : namesInHomotypicGroup){
|
113
|
taxon.addHomotypicSynonymName(synonymName, null, null);
|
114
|
|
115
|
}
|
116
|
}*/
|
117
|
//newNode = CdmStore.getService(ITaxonNodeService.class).merge(newNode);
|
118
|
|
119
|
monitor.worked(40);
|
120
|
|
121
|
return postExecute(newNode);
|
122
|
}
|
123
|
|
124
|
/** {@inheritDoc} */
|
125
|
@Override
|
126
|
public IStatus redo(IProgressMonitor monitor, IAdaptable info)
|
127
|
throws ExecutionException {
|
128
|
return execute(monitor, info);
|
129
|
}
|
130
|
|
131
|
/** {@inheritDoc} */
|
132
|
@Override
|
133
|
public IStatus undo(IProgressMonitor monitor, IAdaptable info)
|
134
|
throws ExecutionException {
|
135
|
|
136
|
// TODO implement - biggest problem is that any window open for new taxon must be closed first
|
137
|
MessagingUtils.warn(this.getClass(), Messages.ChangeSynonymToAcceptedTaxonOperation_NOT_IMPLEMENTED);
|
138
|
|
139
|
return postExecute(element);
|
140
|
}
|
141
|
|
142
|
}
|