2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.navigation
.key
.polytomous
;
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
;
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
;
27 * @created May 5, 2011
30 public class PolytomousKeyViewPartDataChangeBehavior
extends
31 AbstractDataChangeBehaviour
{
33 private final PolytomousKeyViewPart source
;
36 * @param polytomousKeyViewPart
38 public PolytomousKeyViewPartDataChangeBehavior(
39 PolytomousKeyViewPart polytomousKeyViewPart
) {
40 source
= polytomousKeyViewPart
;
44 * @see eu.etaxonomy.taxeditor.model.AbstractDataChangeBehaviour#reactOnDataChange(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
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") {
53 protected IStatus
run(IProgressMonitor monitor
) {
54 monitor
.beginTask("Updating Polytomous Key Viewer", 3);
57 // clear the session completely
58 monitor
.subTask("Clearing Polytomous Key Viewer session");
59 display
.asyncExec(new Runnable() {
61 source
.getConversationHolder().clear();
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
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
73 monitor
.subTask("Refreshing viewer");
75 display
.asyncExec(new Runnable() {
85 return Status
.OK_STATUS
;
89 job
.setPriority(Job
.SHORT
);
98 private boolean isRelevant(CdmDataChangeMap changeEvents
) {
99 for(CdmDataChangeEvent event
: changeEvents
.getAllEvents()){
100 EventType eventType
= event
.getEventType();
101 CdmBase eventEntity
= event
.getEntity();
103 // all poyltomous key changes are relevant
104 if((eventType
== EventType
.INSERT
|| eventType
== EventType
.DELETE
|| eventType
== EventType
.UPDATE
)
105 && eventEntity
instanceof PolytomousKey
){