1
|
package eu.etaxonomy.taxeditor.navigation.navigator.operation;
|
2
|
|
3
|
import java.util.ArrayList;
|
4
|
import java.util.List;
|
5
|
import java.util.UUID;
|
6
|
|
7
|
import org.eclipse.e4.ui.model.application.MApplication;
|
8
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
9
|
import org.eclipse.e4.ui.workbench.modeling.EModelService;
|
10
|
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
11
|
import org.eclipse.swt.widgets.Display;
|
12
|
|
13
|
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
|
14
|
import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
|
15
|
import eu.etaxonomy.cdm.api.longrunningService.ILongRunningTasksService;
|
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.hibernate.HibernateProxyHelper;
|
20
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
21
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
22
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
23
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
24
|
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
|
25
|
import eu.etaxonomy.taxeditor.bulkeditor.input.TaxonEditorInput;
|
26
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
27
|
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
|
28
|
import eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation;
|
29
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
30
|
|
31
|
public abstract class UpdateSubtreeOperation extends RemotingCdmUpdateOperation {
|
32
|
|
33
|
ForSubtreeConfiguratorBase config;
|
34
|
|
35
|
UUID parentUuid;
|
36
|
|
37
|
TaxonNode subtreeNode;
|
38
|
ITaxonNodeService taxonNodeService;
|
39
|
ILongRunningTasksService longRunningTaskService;
|
40
|
|
41
|
protected EModelService modelService = null;
|
42
|
|
43
|
public UpdateSubtreeOperation(Object source,
|
44
|
boolean async,
|
45
|
UUID taxonNodeUuid,
|
46
|
EPartService partService,
|
47
|
MPart activePart,
|
48
|
MApplication application,
|
49
|
EModelService modelService,
|
50
|
ForSubtreeConfiguratorBase config,
|
51
|
String label) {
|
52
|
super(label, Action.Update, source, async, partService, activePart, application);
|
53
|
parentUuid = taxonNodeUuid;
|
54
|
this.config = config;
|
55
|
this.updateResult = new UpdateResult();
|
56
|
this.modelService = modelService;
|
57
|
longRunningTaskService = CdmApplicationState.getLongRunningTasksService();
|
58
|
subtreeNode = CdmStore.getService(ITaxonNodeService.class).load(config.getSubtreeUuid());
|
59
|
}
|
60
|
public void updateNameEditors(){
|
61
|
List<Taxon> taxaToUpdate = new ArrayList();
|
62
|
for (CdmBase object: updateResult.getUpdatedObjects()){
|
63
|
Taxon taxon = null;
|
64
|
TaxonNode node = null;
|
65
|
if (object instanceof Taxon){
|
66
|
taxon = HibernateProxyHelper.deproxy(object, Taxon.class);
|
67
|
node = taxon.getTaxonNode(subtreeNode.getClassification());
|
68
|
|
69
|
}else if (object instanceof Synonym){
|
70
|
Synonym syn = HibernateProxyHelper.deproxy(object, Synonym.class);
|
71
|
taxon = syn.getAcceptedTaxon();
|
72
|
node = taxon.getTaxonNode(subtreeNode.getClassification());
|
73
|
}
|
74
|
taxaToUpdate.add(taxon);
|
75
|
}
|
76
|
|
77
|
Display.getDefault().asyncExec(new Runnable() {
|
78
|
@Override
|
79
|
public void run() {
|
80
|
|
81
|
for (MPart part : partService.getParts()){
|
82
|
Object object = part.getObject();
|
83
|
boolean setFocus = false;
|
84
|
if (part == activePart){
|
85
|
setFocus = true;
|
86
|
}
|
87
|
if (object instanceof TaxonNameEditorE4){
|
88
|
if (object != null ){
|
89
|
if (taxaToUpdate.contains(((TaxonNameEditorE4)object).getTaxon())){
|
90
|
EditorUtil.openTaxonBaseE4(((TaxonNameEditorE4)object).getTaxon().getUuid(), modelService, partService, application);
|
91
|
}
|
92
|
}
|
93
|
}
|
94
|
if (object instanceof BulkEditorE4 && ((BulkEditorE4)object).getEditorInput() instanceof TaxonEditorInput){
|
95
|
((BulkEditorE4)object).getEditorInput().performSearch( ((BulkEditorE4)object).getLastQuery(), ((BulkEditorE4)object).getSelection());
|
96
|
}
|
97
|
}
|
98
|
}
|
99
|
});
|
100
|
|
101
|
}
|
102
|
|
103
|
}
|