1
|
/**
|
2
|
* Copyright (C) 2015 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
|
package eu.etaxonomy.taxeditor.navigation.navigator.operation;
|
10
|
|
11
|
import java.util.HashSet;
|
12
|
import java.util.Set;
|
13
|
import java.util.UUID;
|
14
|
|
15
|
import org.eclipse.core.runtime.IAdaptable;
|
16
|
import org.eclipse.core.runtime.IProgressMonitor;
|
17
|
import org.eclipse.e4.ui.model.application.MApplication;
|
18
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
19
|
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
20
|
import org.eclipse.swt.widgets.Display;
|
21
|
|
22
|
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
|
23
|
import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
|
24
|
import eu.etaxonomy.cdm.api.service.DeleteResult;
|
25
|
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
|
26
|
import eu.etaxonomy.cdm.api.service.UpdateResult;
|
27
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
28
|
import eu.etaxonomy.cdm.model.metadata.SecReferenceHandlingEnum;
|
29
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
30
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
31
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
32
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
33
|
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonEditor;
|
34
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
35
|
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
|
36
|
import eu.etaxonomy.taxeditor.operation.CdmUpdateOperation;
|
37
|
|
38
|
|
39
|
/**
|
40
|
* @author cmathew
|
41
|
* @date 17 Jun 2015
|
42
|
*
|
43
|
*/
|
44
|
public class ChangeAcceptedTaxonToSynonymOperation extends CdmUpdateOperation {
|
45
|
|
46
|
private Set<UUID> oldTaxonNodeUuids = new HashSet();
|
47
|
private final UUID newAcceptedTaxonNodeUuid;
|
48
|
private UUID secundumUuid;
|
49
|
private boolean setNameInSource ;
|
50
|
private SecReferenceHandlingEnum secHandling;
|
51
|
private DeleteResult deleteResult;
|
52
|
|
53
|
|
54
|
private final static String LABEL = Messages.RemotingChangeAcceptedTaxonToSynonymOperation_CHANGE_OP;
|
55
|
|
56
|
/**
|
57
|
* @param label
|
58
|
*/
|
59
|
public ChangeAcceptedTaxonToSynonymOperation(Object source,
|
60
|
boolean async,
|
61
|
Set<UUID> oldTaxonNodeUuids,
|
62
|
UUID newAcceptedTaxonNodeUuid,
|
63
|
UUID newSecUuid,
|
64
|
SecReferenceHandlingEnum secHandling,
|
65
|
EPartService partService,
|
66
|
MPart activePart,
|
67
|
MApplication application,
|
68
|
boolean setNameInSource) {
|
69
|
super(LABEL, Action.Update, source, async, partService, activePart, application);
|
70
|
this.oldTaxonNodeUuids.addAll(oldTaxonNodeUuids);
|
71
|
this.newAcceptedTaxonNodeUuid = newAcceptedTaxonNodeUuid;
|
72
|
this.setNameInSource = setNameInSource;
|
73
|
this.secundumUuid = newSecUuid;
|
74
|
this.secHandling = secHandling;
|
75
|
|
76
|
}
|
77
|
|
78
|
/**
|
79
|
* @param label
|
80
|
*/
|
81
|
public ChangeAcceptedTaxonToSynonymOperation(Object source,
|
82
|
boolean async,
|
83
|
UUID oldTaxonNodeUuid,
|
84
|
UUID newAcceptedTaxonNodeUuid,
|
85
|
UUID newSecUuid,
|
86
|
SecReferenceHandlingEnum secHandling,
|
87
|
EPartService partService,
|
88
|
MPart activePart,
|
89
|
MApplication application,
|
90
|
boolean setNameInSource) {
|
91
|
super(LABEL, Action.Update, source, async, partService, activePart, application);
|
92
|
this.oldTaxonNodeUuids.add(oldTaxonNodeUuid);
|
93
|
this.newAcceptedTaxonNodeUuid = newAcceptedTaxonNodeUuid;
|
94
|
this.setNameInSource = setNameInSource;
|
95
|
this.secundumUuid = newSecUuid;
|
96
|
this.secHandling = secHandling;
|
97
|
}
|
98
|
|
99
|
/**
|
100
|
* @param label
|
101
|
*/
|
102
|
public ChangeAcceptedTaxonToSynonymOperation(Object source,
|
103
|
boolean async,
|
104
|
UUID oldTaxonNodeUuid,
|
105
|
UUID newAcceptedTaxonNodeUuid,
|
106
|
UUID newSecUuid,
|
107
|
SecReferenceHandlingEnum secHandling,
|
108
|
boolean setNameInSource) {
|
109
|
super(LABEL, Action.Update, source, async);
|
110
|
this.oldTaxonNodeUuids.add(oldTaxonNodeUuid);
|
111
|
this.newAcceptedTaxonNodeUuid = newAcceptedTaxonNodeUuid;
|
112
|
this.setNameInSource = setNameInSource;
|
113
|
this.secundumUuid = newSecUuid;
|
114
|
this.secHandling = secHandling;
|
115
|
}
|
116
|
|
117
|
/* (non-Javadoc)
|
118
|
* @see eu.etaxonomy.taxeditor.operation.CdmUpdateOperation#doUpdateExecute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
|
119
|
*/
|
120
|
@Override
|
121
|
protected UpdateResult doUpdateExecute(IProgressMonitor monitor, IAdaptable info) throws Exception {
|
122
|
|
123
|
if (this.oldTaxonNodeUuids.size() == 1){
|
124
|
updateResult = CdmApplicationState.getService(ITaxonNodeService.class).makeTaxonNodeASynonymOfAnotherTaxonNode(oldTaxonNodeUuids.iterator().next(),
|
125
|
newAcceptedTaxonNodeUuid,
|
126
|
null,
|
127
|
secundumUuid,
|
128
|
null,
|
129
|
secHandling,
|
130
|
setNameInSource);//TODO
|
131
|
}else{
|
132
|
updateResult = CdmApplicationState.getService(ITaxonNodeService.class).makeTaxonNodeSynonymsOfAnotherTaxonNode(oldTaxonNodeUuids,
|
133
|
newAcceptedTaxonNodeUuid,
|
134
|
null,
|
135
|
secundumUuid,
|
136
|
null,
|
137
|
secHandling,
|
138
|
setNameInSource);//TODO
|
139
|
}
|
140
|
boolean oldTaxaPublished = true;
|
141
|
for (CdmBase delObject:((DeleteResult)updateResult).getDeletedObjects()){
|
142
|
if (delObject instanceof TaxonBase){
|
143
|
oldTaxaPublished &= ((TaxonBase)delObject).isPublish();
|
144
|
}
|
145
|
}
|
146
|
Taxon newTaxon = null;
|
147
|
for (CdmBase updatedObject: updateResult.getUpdatedObjects()){
|
148
|
if (updatedObject instanceof Taxon){
|
149
|
for (TaxonNode node: ((Taxon)updatedObject).getTaxonNodes()){
|
150
|
if (node.getUuid().equals(newAcceptedTaxonNodeUuid)){
|
151
|
newTaxon = (Taxon)updatedObject;
|
152
|
break;
|
153
|
}
|
154
|
}
|
155
|
}
|
156
|
|
157
|
}
|
158
|
if (newTaxon != null && oldTaxaPublished != newTaxon.isPublish()){
|
159
|
MessagingUtils.warningDialog("Publish flag", null, Messages.RemotingChangeAcceptedTaxonToSynonym_warning_publish);
|
160
|
}
|
161
|
updateTaxonEditor();
|
162
|
return updateResult;
|
163
|
|
164
|
}
|
165
|
|
166
|
private void updateTaxonEditor(){
|
167
|
if (partService != null){
|
168
|
Display.getDefault().asyncExec(new Runnable() {
|
169
|
|
170
|
@Override
|
171
|
public void run() {
|
172
|
for (MPart part : partService.getParts()){
|
173
|
Object object = part.getObject();
|
174
|
boolean setFocus = false;
|
175
|
if (part == activePart){
|
176
|
setFocus = true;
|
177
|
}
|
178
|
if (part.getContributionURI().endsWith("TaxonNameEditorE4")){
|
179
|
|
180
|
}
|
181
|
if (object instanceof TaxonEditor ){
|
182
|
Set<TaxonNode> nodes = ((TaxonEditor)object).getTaxon().getTaxonNodes();
|
183
|
for (TaxonNode node: nodes){
|
184
|
if (node.getUuid().equals(newAcceptedTaxonNodeUuid)){
|
185
|
EditorUtil.updateEditor(node, (TaxonEditor)object);
|
186
|
}
|
187
|
|
188
|
}
|
189
|
}
|
190
|
}
|
191
|
}
|
192
|
});
|
193
|
}
|
194
|
}
|
195
|
}
|