1 11 package org.eclipse.debug.internal.ui.actions; 12 13 import org.eclipse.debug.core.model.IBreakpoint; 14 import org.eclipse.debug.internal.ui.DebugUIPlugin; 15 import org.eclipse.debug.internal.ui.DelegatingModelPresentation; 16 import org.eclipse.debug.internal.ui.IDebugHelpContextIds; 17 import org.eclipse.jface.viewers.ISelectionProvider; 18 import org.eclipse.jface.viewers.IStructuredSelection; 19 import org.eclipse.ui.IEditorInput; 20 import org.eclipse.ui.IEditorPart; 21 import org.eclipse.ui.IWorkbenchPage; 22 import org.eclipse.ui.IWorkbenchWindow; 23 import org.eclipse.ui.PartInitException; 24 import org.eclipse.ui.PlatformUI; 25 import org.eclipse.ui.actions.SelectionProviderAction; 26 import org.eclipse.ui.ide.IDE; 27 import org.eclipse.ui.plugin.AbstractUIPlugin; 28 29 public class OpenBreakpointMarkerAction extends SelectionProviderAction { 30 31 protected static DelegatingModelPresentation fgPresentation = new DelegatingModelPresentation(); 32 private IBreakpoint breakpoint; 33 private IEditorInput input; 34 35 public OpenBreakpointMarkerAction(ISelectionProvider selectionProvider) { 36 super(selectionProvider, ActionMessages.OpenBreakpointMarkerAction__Go_to_File_1); setToolTipText(ActionMessages.OpenBreakpointMarkerAction_Go_to_File_for_Breakpoint_2); setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin("org.eclipse.ui", "icons/full/elcl16/gotoobj_tsk.gif")); PlatformUI.getWorkbench().getHelpSystem().setHelp( 40 this, 41 IDebugHelpContextIds.OPEN_BREAKPOINT_ACTION); 42 setEnabled(false); 43 } 44 45 48 public void run() { 49 IWorkbenchWindow dwindow= DebugUIPlugin.getActiveWorkbenchWindow(); 50 if (dwindow == null) { 51 return; 52 } 53 IWorkbenchPage page= dwindow.getActivePage(); 54 if (page == null) { 55 return; 56 } 57 58 IStructuredSelection selection= getStructuredSelection(); 59 if (selection.isEmpty()) { 60 setEnabled(false); 61 return; 62 } 63 64 IEditorPart part= null; 65 if (input != null) { 66 String editorId = fgPresentation.getEditorId(input, breakpoint); 67 if (editorId != null) { 68 try { 69 part= page.openEditor(input, editorId); 70 } catch (PartInitException e) { 71 DebugUIPlugin.errorDialog(dwindow.getShell(), ActionMessages.OpenBreakpointMarkerAction_Go_to_Breakpoint_1, ActionMessages.OpenBreakpointMarkerAction_Exceptions_occurred_attempting_to_open_the_editor_for_the_breakpoint_resource_2, e); } 73 } 74 } 75 if (part != null) { 76 part.setFocus(); 77 IDE.gotoMarker(part, breakpoint.getMarker()); 78 } 79 } 80 81 84 public void selectionChanged(IStructuredSelection sel) { 85 if (sel.size() == 1) { 86 Object element = sel.getFirstElement(); 87 if (element instanceof IBreakpoint) { 88 breakpoint= (IBreakpoint) element; 89 input= fgPresentation.getEditorInput(breakpoint); 90 if (input != null) { 91 setEnabled(true); 92 return; 93 } 94 } 95 } else { 96 breakpoint = null; 97 input = null; 98 } 99 setEnabled(false); 100 } 101 } 102 | Popular Tags |