3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.navigation
.key
.polytomous
;
13 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
14 import org
.eclipse
.core
.runtime
.IStatus
;
15 import org
.eclipse
.core
.runtime
.Status
;
16 import org
.eclipse
.core
.runtime
.jobs
.Job
;
17 import org
.eclipse
.swt
.widgets
.Display
;
19 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
20 import eu
.etaxonomy
.cdm
.model
.description
.PolytomousKey
;
21 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.CdmDataChangeEvent
;
22 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.CdmDataChangeEvent
.EventType
;
23 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.CdmDataChangeMap
;
24 import eu
.etaxonomy
.taxeditor
.model
.AbstractDataChangeBehaviour
;
28 * @created May 5, 2011
31 public class PolytomousKeyViewPartDataChangeBehavior
extends
32 AbstractDataChangeBehaviour
{
34 private final PolytomousKeyViewPart source
;
37 * @param polytomousKeyViewPart
39 public PolytomousKeyViewPartDataChangeBehavior(
40 PolytomousKeyViewPart polytomousKeyViewPart
) {
41 source
= polytomousKeyViewPart
;
45 * @see eu.etaxonomy.taxeditor.model.AbstractDataChangeBehaviour#reactOnDataChange(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
48 public void reactOnDataChange(CdmDataChangeMap changeEvents
) {
49 if(isRelevant(changeEvents
)){
50 final Display display
= Display
.getCurrent();
51 Job job
= new Job("Updating Polytomous Key Viewer") {
54 protected IStatus
run(IProgressMonitor monitor
) {
55 monitor
.beginTask("Updating Polytomous Key Viewer", 3);
58 // clear the session completely
59 monitor
.subTask("Clearing Polytomous Key Viewer session");
60 display
.asyncExec(new Runnable() {
62 source
.getConversationHolder().clear();
65 // FIXME completely clearing the session is a brute force approach.
66 // It would be much more elegant to clear only those elements that have been changed.
67 // I could not get that to work but we should consider workin on this because we might
68 // run into serious performance issues, especially when it comes to large trees
70 // at least, we moved this to a job so it can run in a background thred
71 // seems to improve the situation but not sure if final solution
74 monitor
.subTask("Refreshing viewer");
76 display
.asyncExec(new Runnable() {
86 return Status
.OK_STATUS
;
90 job
.setPriority(Job
.SHORT
);
99 private boolean isRelevant(CdmDataChangeMap changeEvents
) {
100 for(CdmDataChangeEvent event
: changeEvents
.getAllEvents()){
101 EventType eventType
= event
.getEventType();
102 CdmBase eventEntity
= event
.getEntity();
104 // all poyltomous key changes are relevant
105 if((eventType
== EventType
.INSERT
|| eventType
== EventType
.DELETE
|| eventType
== EventType
.UPDATE
)
106 && eventEntity
instanceof PolytomousKey
){