1 11 package org.eclipse.debug.internal.ui.viewers; 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.ui.commands.actions.AbstractRequestMonitor; 18 import org.eclipse.ui.progress.WorkbenchJob; 19 20 28 public abstract class AsynchronousRequestMonitor extends AbstractRequestMonitor { 29 30 33 private ModelNode fNode; 34 35 38 private AsynchronousModel fModel; 39 40 43 private boolean fDone = false; 44 45 protected WorkbenchJob fViewerUpdateJob = new WorkbenchJob("Asynchronous viewer update") { public IStatus runInUIThread(IProgressMonitor monitor) { 47 getModel().viewerUpdateScheduled(AsynchronousRequestMonitor.this); 51 if (fDone) { 52 getModel().requestComplete(AsynchronousRequestMonitor.this); 53 } 54 if (!isCanceled() && !getNode().isDisposed()) { 55 IStatus status = getStatus(); 56 if (status != null && !status.isOK()) { 57 getModel().getViewer().handlePresentationFailure(AsynchronousRequestMonitor.this, status); 58 } else { 59 performUpdate(); 60 } 61 } 62 getModel().viewerUpdateComplete(AsynchronousRequestMonitor.this); 63 return Status.OK_STATUS; 64 } 65 }; 66 67 73 public AsynchronousRequestMonitor(ModelNode node, AsynchronousModel model) { 74 fNode = node; 75 fModel = model; 76 fViewerUpdateJob.setRule(getUpdateSchedulingRule()); 78 fViewerUpdateJob.setSystem(true); 79 } 80 81 86 protected ISchedulingRule getUpdateSchedulingRule() { 87 return AsynchronousSchedulingRuleFactory.getDefault().newSerialPerObjectRule(getModel().getViewer()); 88 } 89 90 95 protected AsynchronousModel getModel() { 96 return fModel; 97 } 98 99 104 protected ModelNode getNode() { 105 return fNode; 106 } 107 108 116 protected boolean contains(ModelNode node) { 117 if (node == getNode()) { 118 return true; 119 } 120 ModelNode parentNode = getNode().getParentNode(); 121 while (parentNode != null) { 122 if (parentNode.equals(getNode())) { 123 return true; 124 } 125 parentNode = parentNode.getParentNode(); 126 } 127 return false; 128 } 129 130 131 134 public void setCanceled(boolean value) { 135 super.setCanceled(value); 136 if (value) { 137 getModel().requestCanceled(this); 138 } 139 } 140 141 144 public final void done() { 145 synchronized (this) { 146 fDone = true; 147 } 148 scheduleViewerUpdate(0L); 149 } 150 151 156 protected synchronized boolean isDone() { 157 return fDone; 158 } 159 160 protected void scheduleViewerUpdate(long ms) { 161 if(!isCanceled()) 162 fViewerUpdateJob.schedule(ms); 163 } 164 165 169 protected abstract void performUpdate(); 170 171 178 protected abstract boolean contains(AsynchronousRequestMonitor update); 179 180 } 181 | Popular Tags |