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
|
EPartService partService;
|
36
|
MPart activePart;
|
37
|
MApplication application;
|
38
|
TaxonNode subtreeNode;
|
39
|
ITaxonNodeService taxonNodeService;
|
40
|
|
41
|
public UpdateSubtreeOperation(Object source,
|
42
|
boolean async,
|
43
|
UUID taxonNodeUuid,
|
44
|
EPartService partService,
|
45
|
MPart activePart,
|
46
|
MApplication application,
|
47
|
ForSubtreeConfiguratorBase config,
|
48
|
String label) {
|
49
|
super(label, Action.Update, source, async);
|
50
|
parentUuid = taxonNodeUuid;
|
51
|
this.config = config;
|
52
|
this.updateResult = new UpdateResult();
|
53
|
this.partService= partService;
|
54
|
this.activePart = activePart;
|
55
|
this.application = application;
|
56
|
try {
|
57
|
taxonNodeService = CdmApplicationState.getService(ITaxonNodeService.class);
|
58
|
} catch (CdmApplicationException e) {
|
59
|
// TODO Auto-generated catch block
|
60
|
e.printStackTrace();
|
61
|
}
|
62
|
subtreeNode = taxonNodeService.load(config.getSubtreeUuid());
|
63
|
}
|
64
|
|
65
|
public void updateNameEditors(){
|
66
|
for (CdmBase object: updateResult.getUpdatedObjects()){
|
67
|
Taxon taxon = null;
|
68
|
TaxonNode node = null;
|
69
|
if (object instanceof Taxon){
|
70
|
taxon = HibernateProxyHelper.deproxy(object, Taxon.class);
|
71
|
node = taxon.getTaxonNode(subtreeNode.getClassification());
|
72
|
|
73
|
}else if (object instanceof Synonym){
|
74
|
Synonym syn = HibernateProxyHelper.deproxy(object, Synonym.class);
|
75
|
taxon = syn.getAcceptedTaxon();
|
76
|
node = taxon.getTaxonNode(subtreeNode.getClassification());
|
77
|
}
|
78
|
|
79
|
Display.getDefault().asyncExec(new Runnable() {
|
80
|
public void run() {
|
81
|
for (MPart part : partService.getParts()){
|
82
|
Object object = part.getObject();
|
83
|
if (object instanceof TaxonNameEditorE4){
|
84
|
Set<TaxonNode> nodes = ((TaxonNameEditorE4)object).getTaxon().getTaxonNodes();
|
85
|
for (TaxonNode node: nodes){
|
86
|
if (node.treeIndex().startsWith(subtreeNode.treeIndex())){
|
87
|
EditorUtil.updateEditor(node, partService, application);
|
88
|
}
|
89
|
|
90
|
}
|
91
|
}
|
92
|
}
|
93
|
}
|
94
|
});
|
95
|
}
|
96
|
}
|
97
|
}
|