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.navigation.key.polytomous;
|
11
|
|
12
|
import org.eclipse.core.runtime.IProgressMonitor;
|
13
|
import org.eclipse.core.runtime.IStatus;
|
14
|
import org.eclipse.core.runtime.Status;
|
15
|
import org.eclipse.core.runtime.jobs.Job;
|
16
|
import org.eclipse.swt.widgets.Display;
|
17
|
|
18
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
19
|
import eu.etaxonomy.cdm.model.description.PolytomousKey;
|
20
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeEvent;
|
21
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeEvent.EventType;
|
22
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
|
23
|
import eu.etaxonomy.taxeditor.model.AbstractDataChangeBehaviour;
|
24
|
|
25
|
/**
|
26
|
* @author n.hoffmann
|
27
|
* @created May 5, 2011
|
28
|
* @version 1.0
|
29
|
*/
|
30
|
public class PolytomousKeyViewPartDataChangeBehavior extends
|
31
|
AbstractDataChangeBehaviour {
|
32
|
|
33
|
private final PolytomousKeyViewPart source;
|
34
|
|
35
|
/**
|
36
|
* @param polytomousKeyViewPart
|
37
|
*/
|
38
|
public PolytomousKeyViewPartDataChangeBehavior(
|
39
|
PolytomousKeyViewPart polytomousKeyViewPart) {
|
40
|
source = polytomousKeyViewPart;
|
41
|
}
|
42
|
|
43
|
/* (non-Javadoc)
|
44
|
* @see eu.etaxonomy.taxeditor.model.AbstractDataChangeBehaviour#reactOnDataChange(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
|
45
|
*/
|
46
|
@Override
|
47
|
public void reactOnDataChange(CdmDataChangeMap changeEvents) {
|
48
|
if(isRelevant(changeEvents)){
|
49
|
final Display display = Display.getCurrent();
|
50
|
Job job = new Job("Updating Polytomous Key Viewer") {
|
51
|
|
52
|
@Override
|
53
|
protected IStatus run(IProgressMonitor monitor) {
|
54
|
monitor.beginTask("Updating Polytomous Key Viewer", 3);
|
55
|
monitor.worked(1);
|
56
|
|
57
|
// clear the session completely
|
58
|
monitor.subTask("Clearing Polytomous Key Viewer session");
|
59
|
display.asyncExec(new Runnable() {
|
60
|
public void run() {
|
61
|
source.getConversationHolder().clear();
|
62
|
}
|
63
|
});
|
64
|
// FIXME completely clearing the session is a brute force approach.
|
65
|
// It would be much more elegant to clear only those elements that have been changed.
|
66
|
// I could not get that to work but we should consider workin on this because we might
|
67
|
// run into serious performance issues, especially when it comes to large trees
|
68
|
//
|
69
|
// at least, we moved this to a job so it can run in a background thred
|
70
|
// seems to improve the situation but not sure if final solution
|
71
|
monitor.worked(1);
|
72
|
|
73
|
monitor.subTask("Refreshing viewer");
|
74
|
|
75
|
display.asyncExec(new Runnable() {
|
76
|
public void run() {
|
77
|
source.refresh();
|
78
|
}
|
79
|
});
|
80
|
|
81
|
|
82
|
|
83
|
monitor.worked(1);
|
84
|
monitor.done();
|
85
|
return Status.OK_STATUS;
|
86
|
}
|
87
|
};
|
88
|
|
89
|
job.setPriority(Job.SHORT);
|
90
|
job.schedule();
|
91
|
|
92
|
}
|
93
|
}
|
94
|
|
95
|
/**
|
96
|
* @return
|
97
|
*/
|
98
|
private boolean isRelevant(CdmDataChangeMap changeEvents) {
|
99
|
for(CdmDataChangeEvent event : changeEvents.getAllEvents()){
|
100
|
EventType eventType = event.getEventType();
|
101
|
CdmBase eventEntity = event.getEntity();
|
102
|
|
103
|
// all poyltomous key changes are relevant
|
104
|
if((eventType == EventType.INSERT || eventType == EventType.DELETE || eventType == EventType.UPDATE)
|
105
|
&& eventEntity instanceof PolytomousKey){
|
106
|
return true;
|
107
|
}
|
108
|
}
|
109
|
return false;
|
110
|
}
|
111
|
}
|