KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > actions > OpenBreakpointMarkerAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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); //$NON-NLS-1$
37
setToolTipText(ActionMessages.OpenBreakpointMarkerAction_Go_to_File_for_Breakpoint_2); //$NON-NLS-1$
38
setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin("org.eclipse.ui", "icons/full/elcl16/gotoobj_tsk.gif")); //$NON-NLS-1$ //$NON-NLS-2$
39
PlatformUI.getWorkbench().getHelpSystem().setHelp(
40             this,
41             IDebugHelpContextIds.OPEN_BREAKPOINT_ACTION);
42         setEnabled(false);
43     }
44
45     /* (non-Javadoc)
46      * @see org.eclipse.jface.action.IAction#run()
47      */

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 JavaDoc 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); //$NON-NLS-1$ //$NON-NLS-2$
72
}
73             }
74         }
75         if (part != null) {
76             part.setFocus();
77             IDE.gotoMarker(part, breakpoint.getMarker());
78         }
79     }
80     
81     /* (non-Javadoc)
82      * @see org.eclipse.ui.actions.SelectionProviderAction#selectionChanged(org.eclipse.jface.viewers.IStructuredSelection)
83      */

84     public void selectionChanged(IStructuredSelection sel) {
85         if (sel.size() == 1) {
86             Object JavaDoc 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