1 12 package org.eclipse.jdt.internal.ui.callhierarchy; 13 14 import org.eclipse.core.runtime.IProgressMonitor; 15 import org.eclipse.core.runtime.OperationCanceledException; 16 import org.eclipse.core.runtime.jobs.ISchedulingRule; 17 import org.eclipse.jdt.internal.corext.callhierarchy.MethodWrapper; 18 import org.eclipse.jdt.internal.ui.JavaPlugin; 19 import org.eclipse.ui.progress.IElementCollector; 20 import org.eclipse.ui.progress.IDeferredWorkbenchAdapter; 21 22 public class DeferredMethodWrapper extends MethodWrapperWorkbenchAdapter implements IDeferredWorkbenchAdapter { 23 private final CallHierarchyContentProvider fProvider; 24 25 29 private class BatchSimilarSchedulingRule implements ISchedulingRule { 30 public String id; 31 32 public BatchSimilarSchedulingRule(String id) { 33 this.id = id; 34 } 35 36 39 public boolean isConflicting(ISchedulingRule rule) { 40 if (rule instanceof BatchSimilarSchedulingRule) { 41 return ((BatchSimilarSchedulingRule) rule).id.equals(id); 42 } 43 return false; 44 } 45 46 49 public boolean contains(ISchedulingRule rule) { 50 return this == rule; 51 } 52 } 53 54 DeferredMethodWrapper(CallHierarchyContentProvider provider, MethodWrapper methodWrapper) { 55 super(methodWrapper); 56 this.fProvider = provider; 57 } 58 59 private Object getCalls(IProgressMonitor monitor) { 60 return getMethodWrapper().getCalls(monitor); 61 } 62 63 70 public void fetchDeferredChildren(Object object, IElementCollector collector, IProgressMonitor monitor) { 71 try { 72 fProvider.startFetching(); 73 DeferredMethodWrapper methodWrapper = (DeferredMethodWrapper) object; 74 collector.add((Object []) methodWrapper.getCalls(monitor), monitor); 75 collector.done(); 76 } catch (OperationCanceledException e) { 77 collector.add(new Object [] { TreeTermination.SEARCH_CANCELED }, monitor); 78 } catch (Exception e) { 79 JavaPlugin.log(e); 80 } finally { 81 fProvider.doneFetching(); 82 } 83 } 84 85 90 public boolean isContainer() { 91 return true; 92 } 93 94 99 public ISchedulingRule getRule(Object o) { 100 return new BatchSimilarSchedulingRule("org.eclipse.jdt.ui.callhierarchy.methodwrapper"); } 102 103 108 public Object [] getChildren(Object o) { 109 return this.fProvider.fetchChildren(((DeferredMethodWrapper) o).getMethodWrapper()); 110 } 111 112 117 public Object getAdapter(Class adapter) { 118 if (adapter == IDeferredWorkbenchAdapter.class) 119 return this; 120 return null; 121 } 122 } 123 | Popular Tags |