1 11 package org.eclipse.debug.internal.ui.sourcelookup; 12 13 import org.eclipse.core.runtime.IAdaptable; 14 import org.eclipse.core.runtime.PlatformObject; 15 import org.eclipse.debug.internal.ui.views.launch.DebugElementAdapterFactory; 16 import org.eclipse.debug.ui.DebugUITools; 17 import org.eclipse.debug.ui.contexts.DebugContextEvent; 18 import org.eclipse.debug.ui.contexts.IDebugContextListener; 19 import org.eclipse.debug.ui.sourcelookup.ISourceDisplay; 20 import org.eclipse.jface.viewers.ISelection; 21 import org.eclipse.jface.viewers.IStructuredSelection; 22 import org.eclipse.ui.IWorkbenchPage; 23 import org.eclipse.ui.IWorkbenchPart; 24 import org.eclipse.ui.IWorkbenchWindow; 25 26 31 public class SourceLookupService implements IDebugContextListener, ISourceDisplay { 32 33 private IWorkbenchWindow fWindow; 34 35 public SourceLookupService(IWorkbenchWindow window) { 36 fWindow = window; 37 DebugUITools.getDebugContextManager().getContextService(window).addDebugContextListener(this); 38 } 39 40 public void dispose() { 41 DebugUITools.getDebugContextManager().getContextService(fWindow).removeDebugContextListener(this); 42 } 43 44 public synchronized void debugContextChanged(DebugContextEvent event) { 45 if ((event.getFlags() & DebugContextEvent.ACTIVATED) > 0) { 46 displaySource(event.getContext(), event.getDebugContextProvider().getPart(), false); 47 } 48 } 49 50 58 protected synchronized void displaySource(ISelection selection, IWorkbenchPart part, boolean force) { 59 if (selection instanceof IStructuredSelection) { 60 IStructuredSelection structuredSelection = (IStructuredSelection)selection; 61 if (structuredSelection.size() == 1) { 62 Object context = (structuredSelection).getFirstElement(); 63 IWorkbenchPage page = null; 64 if (part == null) { 65 page = fWindow.getActivePage(); 66 } else { 67 page = part.getSite().getPage(); 68 } 69 displaySource(context, page, force); 70 } 71 } 72 } 73 74 77 public void displaySource(Object context, IWorkbenchPage page, boolean forceSourceLookup) { 78 if (context instanceof IAdaptable) { 79 IAdaptable adaptable = (IAdaptable) context; 80 ISourceDisplay adapter = (ISourceDisplay) adaptable.getAdapter(ISourceDisplay.class); 81 if (adapter == null && !(context instanceof PlatformObject)) { 82 adapter = (ISourceDisplay) new DebugElementAdapterFactory().getAdapter(context, ISourceDisplay.class); 85 } 86 if (adapter != null) { 87 adapter.displaySource(context, page, forceSourceLookup); 88 } 89 } 90 } 91 } 92 | Popular Tags |