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