1 11 package org.eclipse.debug.internal.ui.views.launch; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.core.runtime.IAdaptable; 18 import org.eclipse.core.runtime.IProgressMonitor; 19 import org.eclipse.core.runtime.NullProgressMonitor; 20 import org.eclipse.debug.core.model.IStackFrame; 21 import org.eclipse.debug.internal.ui.DebugUIPlugin; 22 import org.eclipse.debug.internal.ui.viewers.AsynchronousTreeModel; 23 import org.eclipse.debug.internal.ui.viewers.AsynchronousTreeViewer; 24 import org.eclipse.debug.internal.ui.viewers.provisional.AsynchronousContentAdapter; 25 import org.eclipse.debug.internal.ui.viewers.provisional.IAsynchronousContentAdapter; 26 import org.eclipse.debug.internal.ui.viewers.provisional.IPresentationContext; 27 import org.eclipse.debug.ui.IDebugUIConstants; 28 import org.eclipse.ui.model.IWorkbenchAdapter; 29 import org.eclipse.ui.progress.IDeferredWorkbenchAdapter; 30 import org.eclipse.ui.progress.IElementCollector; 31 import org.osgi.framework.Bundle; 32 33 38 public class LaunchTreeModel extends AsynchronousTreeModel { 39 40 public LaunchTreeModel(AsynchronousTreeViewer viewer) { 41 super(viewer); 42 } 43 44 protected IAsynchronousContentAdapter getContentAdapter(Object element) { 45 IAsynchronousContentAdapter contentAdapter = super.getContentAdapter(element); 46 if (contentAdapter != null) { 47 return contentAdapter; 48 } 49 50 AsynchronousContentAdapter legacyAdapter = getLegacyAdapter(element); 51 if (legacyAdapter != null) { 52 return legacyAdapter; 53 } 54 55 return null; 56 } 57 58 64 private AsynchronousContentAdapter getLegacyAdapter(Object element) { 65 if (element instanceof IDeferredWorkbenchAdapter) { 66 return new WrappedDeferredWorkbenchTreeAdapter((IDeferredWorkbenchAdapter) element, element); 67 } 68 69 if (!(element instanceof IAdaptable)) { 70 return null; 71 } 72 73 IAdaptable adaptable = (IAdaptable) element; 74 IDeferredWorkbenchAdapter deferred = (IDeferredWorkbenchAdapter) adaptable.getAdapter(IDeferredWorkbenchAdapter.class); 75 if (deferred != null) { 76 DebugUIPlugin plugin = DebugUIPlugin.getDefault(); 77 Bundle bundle = plugin.getBundle(deferred.getClass()); 78 Bundle debugBundle = plugin.getBundle(); 79 if (!debugBundle.equals(bundle)) { 80 return new WrappedDeferredWorkbenchTreeAdapter(deferred, element); 82 } 83 } 84 IWorkbenchAdapter nonDeferred = (IWorkbenchAdapter) adaptable.getAdapter(IWorkbenchAdapter.class); 86 if (nonDeferred != null) { 87 DebugUIPlugin plugin = DebugUIPlugin.getDefault(); 88 Bundle bundle = plugin.getBundle(nonDeferred.getClass()); 89 Bundle debugBundle = plugin.getBundle(); 90 bundle = plugin.getBundle(nonDeferred.getClass()); 91 if (!debugBundle.equals(bundle)) { 92 return new WrappedWorkbenchTreeAdapter(nonDeferred); 93 } 94 } 95 return null; 96 } 97 98 private class ElementCollector implements IElementCollector { 99 List children = new ArrayList (); 100 101 public void add(Object element, IProgressMonitor monitor) { 102 children.add(element); 103 } 104 105 public void add(Object [] elements, IProgressMonitor monitor) { 106 for (int i = 0; i < elements.length; i++) { 107 children.add(elements[i]); 108 } 109 } 110 111 public void done() { 112 } 113 114 public Object [] getChildren() { 115 return children.toArray(); 116 } 117 118 } 119 120 private class WrappedDeferredWorkbenchTreeAdapter extends AsynchronousContentAdapter { 121 private IDeferredWorkbenchAdapter fAdapter; 122 123 private Object fElement; 124 125 public WrappedDeferredWorkbenchTreeAdapter(IDeferredWorkbenchAdapter adapter, Object element) { 126 fAdapter = adapter; 127 fElement = element; 128 } 129 130 protected Object [] getChildren(Object parent, IPresentationContext context) throws CoreException { 131 ElementCollector elementCollector = new ElementCollector(); 132 fAdapter.fetchDeferredChildren(fElement, elementCollector, new NullProgressMonitor()); 133 return elementCollector.getChildren(); 134 } 135 136 protected boolean hasChildren(Object element, IPresentationContext context) throws CoreException { 137 if (element instanceof IStackFrame) { 138 return false; 139 } 140 return fAdapter.isContainer(); 141 } 142 143 protected boolean supportsPartId(String id) { 144 return IDebugUIConstants.ID_DEBUG_VIEW.equals(id); 145 } 146 } 147 148 private class WrappedWorkbenchTreeAdapter extends AsynchronousContentAdapter { 149 private IWorkbenchAdapter fAdapter; 150 151 public WrappedWorkbenchTreeAdapter(IWorkbenchAdapter adapter) { 152 fAdapter = adapter; 153 } 154 155 protected Object [] getChildren(Object parent, IPresentationContext context) throws CoreException { 156 return fAdapter.getChildren(parent); 157 } 158 159 protected boolean hasChildren(Object element, IPresentationContext context) throws CoreException { 160 if (element instanceof IStackFrame) { 161 return false; 162 } 163 return fAdapter.getChildren(element).length > 0; 164 } 165 166 protected boolean supportsPartId(String id) { 167 return IDebugUIConstants.ID_DEBUG_VIEW.equals(id); 168 } 169 170 } 171 172 } 173 | Popular Tags |