1 11 package org.eclipse.debug.internal.ui.viewers.model; 12 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.ISchedulingRule; 17 import org.eclipse.debug.internal.core.commands.Request; 18 import org.eclipse.debug.internal.ui.viewers.AsynchronousSchedulingRuleFactory; 19 import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementContentProvider; 20 import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; 21 import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate; 22 import org.eclipse.jface.viewers.TreePath; 23 import org.eclipse.ui.progress.WorkbenchJob; 24 25 28 abstract class ViewerUpdateMonitor extends Request implements IViewerUpdate { 29 30 private ModelContentProvider fContentProvider; 31 32 35 private TreePath fElementPath; 36 37 40 private Object fElement; 41 42 45 private IElementContentProvider fElementContentProvider; 46 47 50 private boolean fDone = false; 51 52 55 private boolean fStarted = false; 56 57 60 private IPresentationContext fContext; 61 62 protected WorkbenchJob fViewerUpdateJob = new WorkbenchJob("Asynchronous viewer update") { public IStatus runInUIThread(IProgressMonitor monitor) { 64 try { 66 if (!isCanceled() && !getContentProvider().isDisposed()) { 67 IStatus status = getStatus(); 68 if (status == null || status.isOK()) { 69 performUpdate(); 70 } 71 } 72 } finally { 73 getContentProvider().updateComplete(ViewerUpdateMonitor.this); 74 } 75 return Status.OK_STATUS; 76 } 77 }; 78 79 86 public ViewerUpdateMonitor(ModelContentProvider contentProvider, TreePath elementPath, Object element, IElementContentProvider elementContentProvider, IPresentationContext context) { 87 fContext = context; 88 fElementContentProvider = elementContentProvider; 89 fContentProvider = contentProvider; 90 fElement = element; 91 fElementPath = elementPath; 92 fViewerUpdateJob.setRule(getUpdateSchedulingRule()); 94 fViewerUpdateJob.setSystem(true); 95 } 96 97 102 protected ISchedulingRule getUpdateSchedulingRule() { 103 return AsynchronousSchedulingRuleFactory.getDefault().newSerialPerObjectRule(getContentProvider()); 104 } 105 106 111 protected ModelContentProvider getContentProvider() { 112 return fContentProvider; 113 } 114 115 120 protected IElementContentProvider getElementContentProvider() { 121 return fElementContentProvider; 122 } 123 124 127 public final void done() { 128 synchronized (this) { 129 if (isDone()) { 130 return; 131 } 132 fDone = true; 133 } 134 scheduleViewerUpdate(); 135 } 136 137 142 protected synchronized boolean isDone() { 143 return fDone; 144 } 145 146 protected void scheduleViewerUpdate() { 147 if(!isCanceled()) { 148 fViewerUpdateJob.schedule(); 149 } else { 150 getContentProvider().updateComplete(this); 151 } 152 } 153 154 158 protected abstract void performUpdate(); 159 160 163 public IPresentationContext getPresentationContext() { 164 return fContext; 165 } 166 167 170 public Object getElement() { 171 return fElement; 172 } 173 174 177 public TreePath getElementPath() { 178 return fElementPath; 179 } 180 181 188 abstract boolean coalesce(ViewerUpdateMonitor update); 189 190 193 final void start() { 194 synchronized (this) { 195 if (fStarted) { 196 return; 197 } 198 fStarted = true; 199 } 200 getContentProvider().updateStarted(this); 201 if (!isCanceled()) { 202 startRequest(); 203 } else { 204 done(); 205 } 206 } 207 208 211 abstract void startRequest(); 212 213 220 abstract int getPriority(); 221 222 229 abstract TreePath getSchedulingPath(); 230 } 231 | Popular Tags |