1
|
package eu.etaxonomy.taxeditor.navigation.navigator.operation;
|
2
|
|
3
|
import java.util.Set;
|
4
|
import java.util.UUID;
|
5
|
|
6
|
import org.eclipse.core.runtime.IAdaptable;
|
7
|
import org.eclipse.core.runtime.IProgressMonitor;
|
8
|
import org.eclipse.e4.ui.model.application.MApplication;
|
9
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
10
|
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
11
|
import org.eclipse.swt.widgets.Display;
|
12
|
|
13
|
import eu.etaxonomy.cdm.api.application.CdmApplicationException;
|
14
|
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
|
15
|
import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
|
16
|
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
|
17
|
import eu.etaxonomy.cdm.api.service.UpdateResult;
|
18
|
import eu.etaxonomy.cdm.api.service.config.ForSubtreeConfiguratorBase;
|
19
|
import eu.etaxonomy.cdm.api.service.config.PublishForSubtreeConfigurator;
|
20
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
21
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
22
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
23
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
24
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
25
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
26
|
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
|
27
|
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
|
28
|
import eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation;
|
29
|
|
30
|
public abstract class UpdateSubtreeOperation extends RemotingCdmUpdateOperation {
|
31
|
|
32
|
ForSubtreeConfiguratorBase config;
|
33
|
|
34
|
UUID parentUuid;
|
35
|
|
36
|
TaxonNode subtreeNode;
|
37
|
ITaxonNodeService taxonNodeService;
|
38
|
|
39
|
public UpdateSubtreeOperation(Object source,
|
40
|
boolean async,
|
41
|
UUID taxonNodeUuid,
|
42
|
EPartService partService,
|
43
|
MPart activePart,
|
44
|
MApplication application,
|
45
|
ForSubtreeConfiguratorBase config,
|
46
|
String label) {
|
47
|
super(label, Action.Update, source, async, partService, activePart, application);
|
48
|
parentUuid = taxonNodeUuid;
|
49
|
this.config = config;
|
50
|
this.updateResult = new UpdateResult();
|
51
|
|
52
|
try {
|
53
|
taxonNodeService = CdmApplicationState.getService(ITaxonNodeService.class);
|
54
|
} catch (CdmApplicationException e) {
|
55
|
// TODO Auto-generated catch block
|
56
|
e.printStackTrace();
|
57
|
}
|
58
|
subtreeNode = taxonNodeService.load(config.getSubtreeUuid());
|
59
|
}
|
60
|
public void updateNameEditors(){
|
61
|
for (CdmBase object: updateResult.getUpdatedObjects()){
|
62
|
Taxon taxon = null;
|
63
|
TaxonNode node = null;
|
64
|
if (object instanceof Taxon){
|
65
|
taxon = HibernateProxyHelper.deproxy(object, Taxon.class);
|
66
|
node = taxon.getTaxonNode(subtreeNode.getClassification());
|
67
|
|
68
|
}else if (object instanceof Synonym){
|
69
|
Synonym syn = HibernateProxyHelper.deproxy(object, Synonym.class);
|
70
|
taxon = syn.getAcceptedTaxon();
|
71
|
node = taxon.getTaxonNode(subtreeNode.getClassification());
|
72
|
}
|
73
|
|
74
|
Display.getDefault().asyncExec(new Runnable() {
|
75
|
public void run() {
|
76
|
for (MPart part : partService.getParts()){
|
77
|
Object object = part.getObject();
|
78
|
if (object instanceof TaxonNameEditorE4){
|
79
|
Set<TaxonNode> nodes = ((TaxonNameEditorE4)object).getTaxon().getTaxonNodes();
|
80
|
for (TaxonNode node: nodes){
|
81
|
if (node.treeIndex().startsWith(subtreeNode.treeIndex())){
|
82
|
EditorUtil.updateEditor(node, partService, application);
|
83
|
}
|
84
|
|
85
|
}
|
86
|
}
|
87
|
}
|
88
|
}
|
89
|
});
|
90
|
}
|
91
|
}
|
92
|
|
93
|
}
|