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 import org.eclipse.debug.internal.ui.views.launch.DebugElementHelper; 23 import org.eclipse.jface.resource.ImageDescriptor; 24 import org.eclipse.swt.graphics.FontData; 25 import org.eclipse.swt.graphics.RGB; 26 import org.eclipse.ui.progress.UIJob; 27 28 35 public abstract class AsynchronousLabelAdapter implements IAsynchronousLabelAdapter { 36 37 40 public void retrieveLabel(final Object element, final IPresentationContext context, final ILabelRequestMonitor result) { 41 Job job = null; 42 if (requiresUIJob(element)) { 43 job = new UIJob("Retrieving labels") { public IStatus runInUIThread(IProgressMonitor monitor) { 45 computeLabels(element, context, result); 46 return Status.OK_STATUS; 47 } 48 }; 49 } else { 50 job = new Job("Retrieving labels") { protected IStatus run(IProgressMonitor monitor) { 52 computeLabels(element, context, result); 53 return Status.OK_STATUS; 54 } 55 }; 56 } 57 job.setSystem(true); 58 job.setRule(getLabelRule(element, context)); 59 job.schedule(); 60 } 61 62 69 protected ISchedulingRule getLabelRule(Object element, IPresentationContext context) { 70 return AsynchronousSchedulingRuleFactory.getDefault().newSerialPerObjectRule(context); 71 } 72 73 80 protected boolean requiresUIJob(Object object) { 81 return !DebugElementHelper.isInitialized(object); 82 } 83 84 91 protected void computeLabels(Object element, IPresentationContext context, ILabelRequestMonitor monitor) { 92 if (!monitor.isCanceled()) { 93 IStatus status = Status.OK_STATUS; 94 try { 95 monitor.setLabels(getLabels(element, context)); 96 if (!monitor.isCanceled()) { 97 monitor.setImageDescriptors(getImageDescriptors(element, context)); 98 } 99 if (!monitor.isCanceled()) { 100 monitor.setFontDatas(getFontDatas(element, context)); 101 } 102 if (!monitor.isCanceled()) { 103 monitor.setBackgrounds(getBackgrounds(element, context)); 104 } 105 if (!monitor.isCanceled()) { 106 monitor.setForegrounds(getForegrounds(element, context)); 107 } 108 } catch (CoreException e) { 109 status = e.getStatus(); 110 } 111 if (!monitor.isCanceled()) { 112 monitor.setStatus(status); 113 monitor.done(); 114 } 115 } 116 } 117 118 126 protected abstract String [] getLabels(Object element, IPresentationContext context) throws CoreException; 127 128 137 protected abstract ImageDescriptor[] getImageDescriptors(Object element, IPresentationContext context) throws CoreException; 138 139 148 protected abstract FontData[] getFontDatas(Object element, IPresentationContext context) throws CoreException; 149 150 159 protected abstract RGB[] getForegrounds(Object element, IPresentationContext context) throws CoreException; 160 161 170 protected abstract RGB[] getBackgrounds(Object element, IPresentationContext context) throws CoreException; 171 } 172 | Popular Tags |