Project

General

Profile

Download (3.37 KB) Statistics
| Branch: | Tag: | Revision:
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.e4;
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
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
25

    
26
/**
27
 *
28
 * @author pplitzner
29
 * @since Sep 28, 2017
30
 *
31
 */
32
public class PolytomousKeyViewPartDataChangeBehaviorE4_ extends
33
		AbstractDataChangeBehaviour_ {
34

    
35
    private static final String UPDATING_POLYTOMOUS_KEY_VIEWER = Messages.PolytomousKeyViewPartDataChangeBehavior_UPDATE;
36
    private final PolytomousKeyViewPartE4 source;
37

    
38
	public PolytomousKeyViewPartDataChangeBehaviorE4_(
39
			PolytomousKeyViewPartE4 polytomousKeyViewPart) {
40
		source = polytomousKeyViewPart;
41
	}
42

    
43
	@Override
44
	public void reactOnDataChange(CdmDataChangeMap changeEvents) {
45
		if(isRelevant(changeEvents)){
46
			final Display display = Display.getCurrent();
47
			Job job = new Job(UPDATING_POLYTOMOUS_KEY_VIEWER) {
48

    
49
				@Override
50
				protected IStatus run(IProgressMonitor monitor) {
51
					monitor.beginTask(UPDATING_POLYTOMOUS_KEY_VIEWER, 3);
52
					monitor.worked(1);
53

    
54
					// clear the session completely
55
					monitor.subTask(Messages.PolytomousKeyViewPartDataChangeBehavior_CLEAR);
56
					display.asyncExec(new Runnable() {
57
						 @Override
58
                        public void run() {
59
//							 source.getConversationHolder().clear();
60
						 }
61
					});
62
					// FIXME completely clearing the session is a brute force approach.
63
					// It would be much more elegant to clear only those elements that have been changed.
64
					// I could not get that to work but we should consider workin on this because we might
65
					// run into serious performance issues, especially when it comes to large trees
66
					//
67
					// at least, we moved this to a job so it can run in a background thred
68
					// seems to improve the situation but not sure if final solution
69
					monitor.worked(1);
70

    
71
					monitor.subTask(Messages.PolytomousKeyViewPartDataChangeBehavior_REFRESH);
72

    
73
					display.asyncExec(new Runnable() {
74
					    @Override
75
                        public void run() {
76
					    	source.refresh();
77
					    }
78
					});
79

    
80

    
81

    
82
					monitor.worked(1);
83
					monitor.done();
84
					return Status.OK_STATUS;
85
				}
86
			};
87

    
88
			job.setPriority(Job.SHORT);
89
			job.schedule();
90

    
91
		}
92
	}
93

    
94
	private boolean isRelevant(CdmDataChangeMap changeEvents) {
95
		for(CdmDataChangeEvent event : changeEvents.getAllEvents()){
96
			EventType eventType = event.getEventType();
97
			CdmBase eventEntity = event.getEntity();
98

    
99
			// all poyltomous key changes are relevant
100
			if((eventType == EventType.INSERT || eventType == EventType.DELETE || eventType == EventType.UPDATE)
101
					&& eventEntity instanceof PolytomousKey){
102
				return true;
103
			}
104
		}
105
		return false;
106
	}
107
}
(1-1/2)