1 11 package org.eclipse.jdt.internal.debug.ui.propertypages; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.eclipse.core.resources.IWorkspaceRunnable; 17 import org.eclipse.core.resources.ResourcesPlugin; 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.core.runtime.IAdaptable; 20 import org.eclipse.core.runtime.IProgressMonitor; 21 import org.eclipse.core.runtime.IStatus; 22 import org.eclipse.core.runtime.Status; 23 import org.eclipse.jdt.debug.core.IJavaBreakpoint; 24 import org.eclipse.jdt.internal.debug.ui.IJavaDebugHelpContextIds; 25 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; 26 import org.eclipse.jdt.internal.debug.ui.SWTFactory; 27 import org.eclipse.jdt.ui.JavaElementLabelProvider; 28 import org.eclipse.swt.SWT; 29 import org.eclipse.swt.events.ModifyEvent; 30 import org.eclipse.swt.events.ModifyListener; 31 import org.eclipse.swt.events.SelectionAdapter; 32 import org.eclipse.swt.events.SelectionEvent; 33 import org.eclipse.swt.events.ShellEvent; 34 import org.eclipse.swt.events.ShellListener; 35 import org.eclipse.swt.layout.GridData; 36 import org.eclipse.swt.widgets.Button; 37 import org.eclipse.swt.widgets.Combo; 38 import org.eclipse.swt.widgets.Composite; 39 import org.eclipse.swt.widgets.Control; 40 import org.eclipse.swt.widgets.Label; 41 import org.eclipse.swt.widgets.Shell; 42 import org.eclipse.swt.widgets.Text; 43 import org.eclipse.ui.PlatformUI; 44 import org.eclipse.ui.dialogs.PropertyPage; 45 import org.eclipse.ui.model.IWorkbenchAdapter; 46 47 import com.ibm.icu.text.MessageFormat; 48 49 52 public class JavaBreakpointPage extends PropertyPage { 53 54 protected JavaElementLabelProvider fJavaLabelProvider= new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT); 55 protected Button fEnabledButton; 56 protected Button fHitCountButton; 57 protected Text fHitCountText; 58 protected Combo fSuspendPolicy; 59 protected List fErrorMessages= new ArrayList (); 60 61 65 public static final String ATTR_DELETE_ON_CANCEL = JDIDebugUIPlugin.getUniqueIdentifier() + ".ATTR_DELETE_ON_CANCEL"; 67 70 protected static final String EMPTY_STRING = ""; 72 75 private static final String fgHitCountErrorMessage = PropertyPageMessages.JavaBreakpointPage_0; 76 77 81 public boolean performOk() { 82 IWorkspaceRunnable wr = new IWorkspaceRunnable() { 83 public void run(IProgressMonitor monitor) throws CoreException { 84 IJavaBreakpoint breakpoint = getBreakpoint(); 85 boolean delOnCancel = breakpoint.getMarker().getAttribute(ATTR_DELETE_ON_CANCEL) != null; 86 if (delOnCancel) { 87 breakpoint.getMarker().setAttribute(ATTR_DELETE_ON_CANCEL, (String )null); 90 breakpoint.setRegistered(true); 91 } 92 doStore(); 93 } 94 }; 95 try { 96 ResourcesPlugin.getWorkspace().run(wr, null, 0, null); 97 } 98 catch (CoreException e) { 99 JDIDebugUIPlugin.statusDialog(e.getStatus()); 100 JDIDebugUIPlugin.log(e); 101 } 102 return super.performOk(); 103 } 104 105 113 protected void addErrorMessage(String message) { 114 fErrorMessages.remove(message); 115 fErrorMessages.add(message); 116 setErrorMessage(message); 117 setValid(message == null); 118 } 119 120 127 protected void removeErrorMessage(String message) { 128 fErrorMessages.remove(message); 129 if (fErrorMessages.isEmpty()) { 130 addErrorMessage(null); 131 } else { 132 addErrorMessage((String ) fErrorMessages.get(fErrorMessages.size() - 1)); 133 } 134 } 135 136 141 protected void doStore() throws CoreException { 142 IJavaBreakpoint breakpoint = getBreakpoint(); 143 storeSuspendPolicy(breakpoint); 144 storeHitCount(breakpoint); 145 storeEnabled(breakpoint); 146 } 147 148 154 private void storeEnabled(IJavaBreakpoint breakpoint) throws CoreException { 155 breakpoint.setEnabled(fEnabledButton.getSelection()); 156 } 157 158 164 private void storeHitCount(IJavaBreakpoint breakpoint) throws CoreException { 165 int hitCount = -1; 166 if (fHitCountButton.getSelection()) { 167 try { 168 hitCount = Integer.parseInt(fHitCountText.getText()); 169 } 170 catch (NumberFormatException e) { 171 JDIDebugUIPlugin.log(new Status(IStatus.ERROR, JDIDebugUIPlugin.getUniqueIdentifier(), IStatus.ERROR, MessageFormat.format("JavaBreakpointPage allowed input of invalid string for hit count value: {0}.", new String [] { fHitCountText.getText() }), e)); } 173 } 174 breakpoint.setHitCount(hitCount); 175 } 176 177 182 private void storeSuspendPolicy(IJavaBreakpoint breakpoint) throws CoreException { 183 int suspendPolicy = IJavaBreakpoint.SUSPEND_VM; 184 if(fSuspendPolicy.getSelectionIndex() == 0) { 185 suspendPolicy = IJavaBreakpoint.SUSPEND_THREAD; 186 } 187 breakpoint.setSuspendPolicy(suspendPolicy); 188 } 189 190 194 protected Control createContents(Composite parent) { 195 setTitle(PropertyPageMessages.JavaBreakpointPage_11); 196 noDefaultAndApplyButton(); 197 Composite mainComposite = createComposite(parent, 1); 198 createLabels(mainComposite); 199 try { 200 createEnabledButton(mainComposite); 201 createHitCountEditor(mainComposite); 202 createTypeSpecificEditors(mainComposite); 203 createSuspendPolicyEditor(mainComposite); } 205 catch (CoreException e) {JDIDebugUIPlugin.log(e);} 206 setValid(true); 207 try { 209 if (getBreakpoint().getMarker().getAttribute(ATTR_DELETE_ON_CANCEL) != null) { 210 getShell().addShellListener(new ShellListener() { 211 public void shellActivated(ShellEvent e) { 212 Shell shell = (Shell)e.getSource(); 213 shell.setText(MessageFormat.format(PropertyPageMessages.JavaBreakpointPage_10, new String []{getName(getBreakpoint())})); 214 shell.removeShellListener(this); 215 } 216 public void shellClosed(ShellEvent e) { 217 } 218 public void shellDeactivated(ShellEvent e) { 219 } 220 public void shellDeiconified(ShellEvent e) { 221 } 222 public void shellIconified(ShellEvent e) { 223 } 224 }); 225 } 226 } catch (CoreException e) { 227 } 228 return mainComposite; 229 } 230 231 237 private String getName(IAdaptable element) { 238 IWorkbenchAdapter adapter = (IWorkbenchAdapter) element.getAdapter(IWorkbenchAdapter.class); 239 if (adapter != null) { 240 return adapter.getLabel(element); 241 } 242 return EMPTY_STRING; 243 } 244 245 249 protected void createLabels(Composite parent) { 250 Composite labelComposite = createComposite(parent, 2); 251 try { 252 String typeName = ((IJavaBreakpoint) getElement()).getTypeName(); 253 if (typeName != null) { 254 createLabel(labelComposite, PropertyPageMessages.JavaBreakpointPage_3); 255 Text text = SWTFactory.createText(labelComposite, SWT.READ_ONLY, 1, typeName); 256 text.setBackground(parent.getBackground()); 257 } 258 createTypeSpecificLabels(labelComposite); 259 } catch (CoreException ce) { 260 JDIDebugUIPlugin.log(ce); 261 } 262 } 263 264 270 private void createSuspendPolicyEditor(Composite parent) throws CoreException { 271 Composite comp = createComposite(parent, 2); 272 createLabel(comp, PropertyPageMessages.JavaBreakpointPage_6); 273 boolean suspendThread= getBreakpoint().getSuspendPolicy() == IJavaBreakpoint.SUSPEND_THREAD; 274 fSuspendPolicy = new Combo(comp, SWT.BORDER | SWT.READ_ONLY); 275 fSuspendPolicy.add(PropertyPageMessages.JavaBreakpointPage_7); 276 fSuspendPolicy.add(PropertyPageMessages.JavaBreakpointPage_8); 277 fSuspendPolicy.select(1); 278 if(suspendThread) { 279 fSuspendPolicy.select(0); 280 } 281 } 282 283 287 private void createHitCountEditor(Composite parent) throws CoreException { 288 Composite hitCountComposite = createComposite(parent, 2); 289 fHitCountButton= createCheckButton(hitCountComposite, PropertyPageMessages.JavaBreakpointPage_4); 290 fHitCountButton.addSelectionListener(new SelectionAdapter() { 291 public void widgetSelected(SelectionEvent event) { 292 fHitCountText.setEnabled(fHitCountButton.getSelection()); 293 hitCountChanged(); 294 } 295 }); 296 int hitCount = getBreakpoint().getHitCount(); 297 String hitCountString= EMPTY_STRING; 298 if (hitCount > 0) { 299 hitCountString = new Integer (hitCount).toString(); 300 fHitCountButton.setSelection(true); 301 } else { 302 fHitCountButton.setSelection(false); 303 } 304 fHitCountText= createText(hitCountComposite, hitCountString); 305 if (hitCount <= 0) { 306 fHitCountText.setEnabled(false); 307 } 308 fHitCountText.addModifyListener(new ModifyListener() { 309 public void modifyText(ModifyEvent e) { 310 hitCountChanged(); 311 } 312 }); 313 } 314 315 319 private void hitCountChanged() { 320 if (!fHitCountButton.getSelection()) { 321 removeErrorMessage(fgHitCountErrorMessage); 322 return; 323 } 324 String hitCountText= fHitCountText.getText(); 325 int hitCount= -1; 326 try { 327 hitCount = Integer.parseInt(hitCountText); 328 } 329 catch (NumberFormatException e1) { 330 addErrorMessage(fgHitCountErrorMessage); 331 return; 332 } 333 if (hitCount < 1) { 334 addErrorMessage(fgHitCountErrorMessage); 335 } else { 336 removeErrorMessage(fgHitCountErrorMessage); 337 } 338 } 339 340 345 protected void createEnabledButton(Composite parent) throws CoreException { 346 fEnabledButton = createCheckButton(parent, PropertyPageMessages.JavaBreakpointPage_5); 347 fEnabledButton.setSelection(getBreakpoint().isEnabled()); 348 } 349 350 354 protected IJavaBreakpoint getBreakpoint() { 355 return (IJavaBreakpoint) getElement(); 356 } 357 358 363 protected void createTypeSpecificLabels(Composite parent) {} 364 365 370 protected void createTypeSpecificEditors(Composite parent) throws CoreException {} 371 372 378 protected Text createText(Composite parent, String initialValue) { 379 return SWTFactory.createText(parent, SWT.SINGLE | SWT.BORDER, 1, initialValue); 380 } 381 382 388 protected Composite createComposite(Composite parent, int numColumns) { 389 return SWTFactory.createComposite(parent, parent.getFont(), numColumns, 1, GridData.FILL_HORIZONTAL, 0, 0); 390 } 391 392 398 protected Button createCheckButton(Composite parent, String text) { 399 return SWTFactory.createCheckButton(parent, text, null, false, 1); 400 } 401 402 408 protected Label createLabel(Composite parent, String text) { 409 return SWTFactory.createLabel(parent, text, 1); 410 } 411 412 418 protected Button createRadioButton(Composite parent, String text) { 419 return SWTFactory.createRadioButton(parent, text, 1); 420 } 421 422 425 public boolean performCancel() { 426 try { 427 if (getBreakpoint().getMarker().getAttribute(ATTR_DELETE_ON_CANCEL) != null) { 428 getBreakpoint().delete(); 430 } 431 } catch (CoreException e) { 432 JDIDebugUIPlugin.statusDialog(PropertyPageMessages.JavaBreakpointPage_9, e.getStatus()); 433 } 434 return super.performCancel(); 435 } 436 437 440 public void createControl(Composite parent) { 441 super.createControl(parent); 442 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IJavaDebugHelpContextIds.JAVA_BREAKPOINT_PROPERTY_PAGE); 443 } 444 } 445 | Popular Tags |