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