KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > breakpoints > AddExceptionDialogExtension


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.breakpoints;
12
13 import org.eclipse.core.runtime.IStatus;
14 import org.eclipse.core.runtime.NullProgressMonitor;
15 import org.eclipse.jdt.core.IType;
16 import org.eclipse.jdt.core.ITypeHierarchy;
17 import org.eclipse.jdt.core.JavaModelException;
18 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
19 import org.eclipse.jdt.internal.debug.ui.StatusInfo;
20 import org.eclipse.jdt.ui.dialogs.TypeSelectionExtension;
21 import org.eclipse.swt.SWT;
22 import org.eclipse.swt.events.SelectionEvent;
23 import org.eclipse.swt.events.SelectionListener;
24 import org.eclipse.swt.layout.GridData;
25 import org.eclipse.swt.layout.GridLayout;
26 import org.eclipse.swt.widgets.Button;
27 import org.eclipse.swt.widgets.Composite;
28 import org.eclipse.swt.widgets.Control;
29 import org.eclipse.ui.dialogs.ISelectionStatusValidator;
30
31 /**
32  *
33  * This class adds the extensions for the AddExceptionDialog, to use the new Camal cased selection dialog
34  * @since 3.2
35  *
36  */

37 public class AddExceptionDialogExtension extends TypeSelectionExtension {
38
39      /**
40       * widgets
41       */

42      private Button fCaughtButton;
43      private Button fUncaughtButton;
44      private boolean fCaught = false;
45      private boolean fUncaught = false;
46     
47     /**
48      * Constructor
49      */

50     public AddExceptionDialogExtension(boolean caught, boolean uncaught) {
51         super();
52         fCaught = caught;
53         fUncaught = uncaught;
54     }
55
56     /* (non-Javadoc)
57      * @see org.eclipse.jdt.ui.dialogs.TypeSelectionExtension#createContentArea(org.eclipse.swt.widgets.Composite)
58      */

59     public Control createContentArea(Composite parent) {
60         super.createContentArea(parent);
61         Composite comp = new Composite(parent, SWT.NONE);
62         comp.setLayout(new GridLayout(1, true));
63         comp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
64         fCaughtButton = new Button(comp, SWT.CHECK);
65         fCaughtButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
66         fCaughtButton.setFont(comp.getFont());
67         fCaughtButton.setText(BreakpointMessages.AddExceptionDialog_15);
68         fCaughtButton.setSelection(fCaught);
69         fCaughtButton.addSelectionListener(new SelectionListener() {
70             public void widgetSelected(SelectionEvent e) {
71                 fCaught = fCaughtButton.getSelection();
72             }
73             public void widgetDefaultSelected(SelectionEvent e) {}
74         });
75         fUncaughtButton = new Button(comp, SWT.CHECK);
76         fUncaughtButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
77         fUncaughtButton.setFont(comp.getFont());
78         fUncaughtButton.setText(BreakpointMessages.AddExceptionDialog_16);
79         fUncaughtButton.setSelection(fUncaught);
80         fUncaughtButton.addSelectionListener(new SelectionListener() {
81             public void widgetSelected(SelectionEvent e) {
82                 fUncaught = fUncaughtButton.getSelection();
83             }
84             public void widgetDefaultSelected(SelectionEvent e) {}
85         });
86         return comp;
87     }
88
89     /**
90      * Returns if the caught button has been checked or not
91      * @return if the caught button has been checked or not
92      */

93     public boolean catchExceptions() {
94         return fCaught;
95     }
96     
97     /* (non-Javadoc)
98      * @see org.eclipse.jdt.ui.dialogs.TypeSelectionExtension#getSelectionValidator()
99      */

100     public ISelectionStatusValidator getSelectionValidator() {
101         ISelectionStatusValidator validator = new ISelectionStatusValidator() {
102             public IStatus validate(Object JavaDoc[] selection) {
103                 IType type = null;
104                 for(int i = 0; i < selection.length; i ++) {
105                     type = (IType)selection[i];
106                     if(!isException(type)) {
107                         return new StatusInfo(IStatus.ERROR, BreakpointMessages.AddExceptionDialogExtension_0);
108                     }
109                 }
110                 return new StatusInfo(IStatus.OK, ""); //$NON-NLS-1$
111
}
112             
113         };
114         return validator;
115     }
116
117     /**
118      * Returns if the exception is checked or not
119      * @param type the type of the exception breakpoint
120      * @return true if it is a checked exception, false other wise
121      * @since 3.2
122      */

123     protected boolean isException(IType type) {
124         if(type != null) {
125             try {
126                 ITypeHierarchy hierarchy = type.newSupertypeHierarchy(new NullProgressMonitor());
127                 IType curr = type;
128                 while (curr != null) {
129                     if ("java.lang.Throwable".equals(curr.getFullyQualifiedName('.'))) { //$NON-NLS-1$
130
return true;
131                     }
132                     curr = hierarchy.getSuperclass(curr);
133                 }
134             }
135             catch (JavaModelException e) {JDIDebugUIPlugin.log(e);}
136         }
137         return false;
138     }
139     
140     /**
141      * Returns if the uncaught button has been checked or not
142      * @return if the uncaught button has been checked or not
143      */

144     public boolean uncaughtExceptions() {
145         return fUncaught;
146     }
147 }
148
Popular Tags