KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > console > JavaExceptionHyperLink


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.jdt.internal.debug.ui.console;
12
13 import java.util.HashMap JavaDoc;
14 import java.util.Map JavaDoc;
15
16 import org.eclipse.core.resources.IResource;
17 import org.eclipse.core.resources.ResourcesPlugin;
18 import org.eclipse.core.runtime.CoreException;
19 import org.eclipse.debug.core.DebugPlugin;
20 import org.eclipse.debug.core.model.IBreakpoint;
21 import org.eclipse.jdt.core.IClassFile;
22 import org.eclipse.jdt.core.ICompilationUnit;
23 import org.eclipse.jdt.core.IType;
24 import org.eclipse.jdt.debug.core.IJavaExceptionBreakpoint;
25 import org.eclipse.jdt.debug.core.JDIDebugModel;
26 import org.eclipse.jdt.internal.debug.ui.BreakpointUtils;
27 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
28 import org.eclipse.jdt.internal.debug.ui.actions.JavaBreakpointPropertiesAction;
29 import org.eclipse.jdt.internal.debug.ui.breakpoints.AddExceptionAction;
30 import org.eclipse.jdt.internal.debug.ui.propertypages.JavaBreakpointPage;
31 import org.eclipse.jface.viewers.StructuredSelection;
32 import org.eclipse.ui.console.TextConsole;
33
34 /**
35  * A hyperlink that creates an exception breakpoint.
36  */

37 public class JavaExceptionHyperLink extends JavaStackTraceHyperlink {
38
39     private String JavaDoc fExceptionName = null;
40
41     /**
42      * Constructs a new hyper link
43      *
44      * @param console
45      * the console the link is contained in
46      * @param exceptionName
47      * fully qualified name of the exception
48      */

49     public JavaExceptionHyperLink(TextConsole console, String JavaDoc exceptionName) {
50         super(console);
51         fExceptionName = exceptionName;
52     }
53
54     /**
55      * @see org.eclipse.debug.ui.console.IConsoleHyperlink#linkActivated()
56      */

57     public void linkActivated() {
58         try {
59             // check for an existing breakpoint
60
IBreakpoint[] breakpoints = DebugPlugin.getDefault()
61                     .getBreakpointManager().getBreakpoints(
62                             JDIDebugModel.getPluginIdentifier());
63             for (int i = 0; i < breakpoints.length; i++) {
64                 IBreakpoint breakpoint = breakpoints[i];
65                 if (breakpoint instanceof IJavaExceptionBreakpoint) {
66                     IJavaExceptionBreakpoint exceptionBreakpoint = (IJavaExceptionBreakpoint) breakpoint;
67                     if (fExceptionName
68                             .equals(exceptionBreakpoint.getTypeName())) {
69                         showProperties(exceptionBreakpoint);
70                         return;
71                     }
72                 }
73             }
74             // create a new exception breakpoint
75
startSourceSearch(fExceptionName, -1);
76         } catch (CoreException e) {
77             JDIDebugUIPlugin.statusDialog(e.getStatus());
78             return;
79         }
80     }
81
82     /**
83      * Show the properties dialog for the given breakpoint.
84      *
85      * @param exceptionBreakpoint
86      */

87     private void showProperties(IJavaExceptionBreakpoint breakpoint) {
88         JavaBreakpointPropertiesAction action = new JavaBreakpointPropertiesAction();
89         action.selectionChanged(null, new StructuredSelection(breakpoint));
90         action.run(null);
91     }
92
93     /* (non-Javadoc)
94      * @see org.eclipse.jdt.internal.debug.ui.console.JavaStackTraceHyperlink#processSearchResult(java.lang.Object, java.lang.String, int)
95      */

96     protected void processSearchResult(Object JavaDoc source, String JavaDoc typeName, int lineNumber) {
97         try {
98             IResource res = ResourcesPlugin.getWorkspace().getRoot();
99             IType type = null;
100             if (source instanceof ICompilationUnit) {
101                 type = ((ICompilationUnit) source).findPrimaryType();
102             } else if (source instanceof IClassFile) {
103                 type = ((IClassFile) source).getType();
104             } else if (source instanceof IType) {
105                 type = (IType) source;
106             }
107             if (type != null) {
108                 res = BreakpointUtils.getBreakpointResource(type);
109             }
110             Map JavaDoc map = new HashMap JavaDoc();
111             map.put(JavaBreakpointPage.ATTR_DELETE_ON_CANCEL,
112                     JavaBreakpointPage.ATTR_DELETE_ON_CANCEL);
113             IJavaExceptionBreakpoint breakpoint = JDIDebugModel
114                     .createExceptionBreakpoint(res, fExceptionName, true, true,
115                             AddExceptionAction.isChecked(type), false, map);
116             showProperties(breakpoint);
117         } catch (CoreException e) {
118             JDIDebugUIPlugin.statusDialog(e.getStatus());
119         }
120     }
121
122 }
123
Popular Tags