1 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 37 public class AddExceptionDialogExtension extends TypeSelectionExtension { 38 39 42 private Button fCaughtButton; 43 private Button fUncaughtButton; 44 private boolean fCaught = false; 45 private boolean fUncaught = false; 46 47 50 public AddExceptionDialogExtension(boolean caught, boolean uncaught) { 51 super(); 52 fCaught = caught; 53 fUncaught = uncaught; 54 } 55 56 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 93 public boolean catchExceptions() { 94 return fCaught; 95 } 96 97 100 public ISelectionStatusValidator getSelectionValidator() { 101 ISelectionStatusValidator validator = new ISelectionStatusValidator() { 102 public IStatus validate(Object [] 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, ""); } 112 113 }; 114 return validator; 115 } 116 117 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('.'))) { return true; 131 } 132 curr = hierarchy.getSuperclass(curr); 133 } 134 } 135 catch (JavaModelException e) {JDIDebugUIPlugin.log(e);} 136 } 137 return false; 138 } 139 140 144 public boolean uncaughtExceptions() { 145 return fUncaught; 146 } 147 } 148 | Popular Tags |