1 11 12 package org.eclipse.debug.internal.ui.viewers.provisional; 13 14 import org.eclipse.core.runtime.CoreException; 15 import org.eclipse.core.runtime.IProgressMonitor; 16 import org.eclipse.core.runtime.IStatus; 17 import org.eclipse.core.runtime.Status; 18 import org.eclipse.core.runtime.jobs.ISchedulingRule; 19 import org.eclipse.core.runtime.jobs.Job; 20 import org.eclipse.debug.internal.ui.viewers.AsynchronousSchedulingRuleFactory; 21 import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; 22 23 30 public abstract class AsynchronousContentAdapter implements IAsynchronousContentAdapter { 31 32 protected static final Object [] EMPTY = new Object [0]; 33 34 38 public void retrieveChildren(final Object parent, final IPresentationContext context, final IChildrenRequestMonitor result) { 39 Job job = new Job("Retrieving Children") { protected IStatus run(IProgressMonitor monitor) { 41 if (!monitor.isCanceled()) { 42 computeChildren(parent, context, result); 43 } 44 return Status.OK_STATUS; 45 } 46 }; 47 job.setSystem(true); 48 job.setRule(getRetrieveChildrenRule(parent, context)); 49 job.schedule(); 50 } 51 52 59 protected ISchedulingRule getRetrieveChildrenRule(Object parent, IPresentationContext context) { 60 return AsynchronousSchedulingRuleFactory.getDefault().newSerialPerObjectRule(context); 61 } 62 63 64 68 public void isContainer(final Object element, final IPresentationContext context, final IContainerRequestMonitor result) { 69 Job job = new Job("Computing hasChildren") { protected IStatus run(IProgressMonitor monitor) { 71 if (!monitor.isCanceled()) { 72 computeIsContainer(element, context, result); 73 } 74 return Status.OK_STATUS; 75 } 76 }; 77 job.setSystem(true); 78 job.setRule(getIsContainerRule(element, context)); 79 job.schedule(); 80 } 81 82 89 protected ISchedulingRule getIsContainerRule(Object parent, IPresentationContext context) { 90 return AsynchronousSchedulingRuleFactory.getDefault().newSerialPerObjectRule(context); 91 } 92 93 100 protected void computeChildren(Object parent, IPresentationContext context, IChildrenRequestMonitor monitor) { 101 if (!monitor.isCanceled()) { 102 IStatus status = Status.OK_STATUS; 103 try { 104 if (supportsContext(context)) { 105 monitor.addChildren(getChildren(parent, context)); 106 } 107 } catch (CoreException e) { 108 status = e.getStatus(); 109 } 110 monitor.setStatus(status); 111 monitor.done(); 112 } 113 } 114 115 122 protected void computeIsContainer(Object parent, IPresentationContext context, IContainerRequestMonitor monitor) { 123 if (!monitor.isCanceled()) { 124 IStatus status = Status.OK_STATUS; 125 try { 126 monitor.setIsContainer(hasChildren(parent, context)); 127 } catch (CoreException e) { 128 status = e.getStatus(); 129 } 130 monitor.setStatus(status); 131 monitor.done(); 132 } 133 } 134 135 143 protected abstract Object [] getChildren(Object parent, IPresentationContext context) throws CoreException; 144 145 154 protected abstract boolean hasChildren(Object element, IPresentationContext context) throws CoreException; 155 156 162 protected boolean supportsContext(IPresentationContext context) { 163 return supportsPartId(context.getId()); 164 } 165 166 172 protected abstract boolean supportsPartId(String id); 173 } 174 | Popular Tags |