blob: 32827aa27f40eb3dc82e1659d832037a38e761f2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
/*******************************************************************************
* Copyright (c) 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.debug.internal.ui.viewers.model;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.debug.internal.ui.commands.actions.AbstractRequestMonitor;
import org.eclipse.debug.internal.ui.viewers.AsynchronousSchedulingRuleFactory;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.ui.progress.WorkbenchJob;
/**
* @since 3.3
*/
abstract class ViewerUpdateMonitor extends AbstractRequestMonitor implements IViewerUpdate {
private ModelContentProvider fContentProvider;
/**
* Whether this request's 'done' method has been called.
*/
private boolean fDone = false;
/**
* Associated batch operation, or <code>null</code>
*/
private BatchUpdate fBatchUpdate = null;
protected WorkbenchJob fViewerUpdateJob = new WorkbenchJob("Asynchronous viewer update") { //$NON-NLS-1$
public IStatus runInUIThread(IProgressMonitor monitor) {
// necessary to check if viewer is disposed
try {
if (!isCanceled() && !getContentProvider().isDisposed()) {
IStatus status = getStatus();
if (status == null || status.isOK()) {
performUpdate();
}
}
} finally {
getContentProvider().updateComplete(ViewerUpdateMonitor.this);
}
return Status.OK_STATUS;
}
};
/**
* Constructs an update for the given content provider
*
* @param contentProvider content provider
*/
public ViewerUpdateMonitor(ModelContentProvider contentProvider) {
fContentProvider = contentProvider;
// serialize updates per viewer
fViewerUpdateJob.setRule(getUpdateSchedulingRule());
fViewerUpdateJob.setSystem(true);
contentProvider.updateStarted(this);
}
/**
* Returns the scheduling rule for viewer update job.
*
* @return rule or <code>null</code>
*/
protected ISchedulingRule getUpdateSchedulingRule() {
return AsynchronousSchedulingRuleFactory.getDefault().newSerialPerObjectRule(getContentProvider());
}
/**
* Returns the model content provider this update is being performed for.
*
* @return the model content provider this update is being performed for
*/
protected ModelContentProvider getContentProvider() {
return fContentProvider;
}
/* (non-Javadoc)
* @see org.eclipse.core.runtime.IProgressMonitor#done()
*/
public final void done() {
synchronized (this) {
if (isDone()) {
return;
}
fDone = true;
}
if (fBatchUpdate != null) {
fBatchUpdate.done(this);
} else {
scheduleViewerUpdate();
}
}
/**
* Returns whether this request is done yet.
*
* @return
*/
protected synchronized boolean isDone() {
return fDone;
}
protected void scheduleViewerUpdate() {
if(!isCanceled()) {
fViewerUpdateJob.schedule();
} else {
getContentProvider().updateComplete(this);
}
}
/**
* Notification this update has been completed and should now be applied to
* this update's viewer. This method is called in the UI thread.
*/
protected abstract void performUpdate();
/* (non-Javadoc)
* @see org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate#getPresentationContext()
*/
public IPresentationContext getPresentationContext() {
return fContentProvider.getPresentationContext();
}
public Object getElement(TreePath path) {
return fContentProvider.getElement(path);
}
/**
* Whether this update is rooted at or below the given path.
*
* @param path
* @return whether this update is rooted at or below the given path
*/
abstract boolean isContained(TreePath path);
synchronized void setBatchUpdate(BatchUpdate batchUpdate) {
fBatchUpdate = batchUpdate;
batchUpdate.batch(this);
}
}
|