Package: VdmBreakpointPropertyPage$1

VdmBreakpointPropertyPage$1

nameinstructionbranchcomplexitylinemethod
run(IProgressMonitor)
M: 27 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
{...}
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * #%~
3: * org.overture.ide.debug
4: * %%
5: * Copyright (C) 2008 - 2014 Overture
6: * %%
7: * This program is free software: you can redistribute it and/or modify
8: * it under the terms of the GNU General Public License as
9: * published by the Free Software Foundation, either version 3 of the
10: * License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public
18: * License along with this program. If not, see
19: * <http://www.gnu.org/licenses/gpl-3.0.html>.
20: * #~%
21: */
22: package org.overture.ide.debug.ui.propertypages;
23:
24: import java.util.ArrayList;
25: import java.util.List;
26:
27: import org.eclipse.core.resources.IWorkspaceRunnable;
28: import org.eclipse.core.resources.ResourcesPlugin;
29: import org.eclipse.core.runtime.CoreException;
30: import org.eclipse.core.runtime.IProgressMonitor;
31: import org.eclipse.debug.internal.ui.SWTFactory;
32: import org.eclipse.swt.SWT;
33: import org.eclipse.swt.events.ModifyEvent;
34: import org.eclipse.swt.events.ModifyListener;
35: import org.eclipse.swt.events.SelectionAdapter;
36: import org.eclipse.swt.events.SelectionEvent;
37: import org.eclipse.swt.events.ShellEvent;
38: import org.eclipse.swt.events.ShellListener;
39: import org.eclipse.swt.layout.GridData;
40: import org.eclipse.swt.widgets.Button;
41: import org.eclipse.swt.widgets.Combo;
42: import org.eclipse.swt.widgets.Composite;
43: import org.eclipse.swt.widgets.Control;
44: import org.eclipse.swt.widgets.Label;
45: import org.eclipse.swt.widgets.Shell;
46: import org.eclipse.swt.widgets.Text;
47: import org.eclipse.ui.dialogs.PropertyPage;
48: import org.overture.ide.debug.core.IDebugConstants;
49: import org.overture.ide.debug.core.model.IVdmBreakpoint;
50:
51: @SuppressWarnings("restriction")
52: public class VdmBreakpointPropertyPage extends PropertyPage
53: {
54:
55:         // protected JavaElementLabelProvider fJavaLabelProvider= new
56:         // JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT);
57:         protected Button fEnabledButton;
58:         protected Button fHitValueButton;
59:         protected Text fHitValueText;
60:         protected Combo fSuspendPolicy;
61:         protected List<String> fErrorMessages = new ArrayList<String>();
62:
63:         /**
64:          * Attribute used to indicate that a breakpoint should be deleted when cancel is pressed.
65:          */
66:         public static final String ATTR_DELETE_ON_CANCEL = IDebugConstants.PLUGIN_ID
67:                         + ".ATTR_DELETE_ON_CANCEL"; //$NON-NLS-1$
68:
69:         /**
70:          * Constant for the empty string
71:          */
72:         protected static final String EMPTY_STRING = ""; //$NON-NLS-1$
73:
74:         /**
75:          * the hit count error message
76:          */
77:         private static final String fgHitCountErrorMessage = "Hit count must be a positive integer";// PropertyPageMessages.JavaBreakpointPage_0;
78:
79:         /**
80:          * Store the breakpoint properties.
81:          *
82:          * @see org.eclipse.jface.preference.IPreferencePage#performOk()
83:          */
84:         public boolean performOk()
85:         {
86:                 IWorkspaceRunnable wr = new IWorkspaceRunnable()
87:                 {
88:                         public void run(IProgressMonitor monitor) throws CoreException
89:                         {
90:                                 IVdmBreakpoint breakpoint = getBreakpoint();
91:•                                boolean delOnCancel = breakpoint.getMarker().getAttribute(ATTR_DELETE_ON_CANCEL) != null;
92:•                                if (delOnCancel)
93:                                 {
94:                                         // if this breakpoint is being created, remove the "delete on cancel" attribute
95:                                         // and register with the breakpoint manager
96:                                         breakpoint.getMarker().setAttribute(ATTR_DELETE_ON_CANCEL, (String) null);
97:                                         breakpoint.setRegistered(true);
98:                                 }
99:                                 doStore();
100:                         }
101:                 };
102:                 try
103:                 {
104:                         ResourcesPlugin.getWorkspace().run(wr, null, 0, null);
105:                 } catch (CoreException e)
106:                 {
107:                         // JDIDebugUIPlugin.statusDialog(e.getStatus());
108:                         // JDIDebugUIPlugin.log(e);
109:                 }
110:                 return super.performOk();
111:         }
112:
113:         /**
114:          * Adds the given error message to the errors currently displayed on this page. The page displays the most recently
115:          * added error message. Clients should retain messages that are passed into this method as the message should later
116:          * be passed into removeErrorMessage(String) to clear the error. This method should be used instead of
117:          * setErrorMessage(String).
118:          *
119:          * @param message
120:          * the error message to display on this page.
121:          */
122:         protected void addErrorMessage(String message)
123:         {
124:                 fErrorMessages.remove(message);
125:                 fErrorMessages.add(message);
126:                 setErrorMessage(message);
127:                 setValid(message == null);
128:         }
129:
130:         /**
131:          * Removes the given error message from the errors currently displayed on this page. When an error message is
132:          * removed, the page displays the error that was added before the given message. This is akin to popping the message
133:          * from a stack. Clients should call this method instead of setErrorMessage(null).
134:          *
135:          * @param message
136:          * the error message to clear
137:          */
138:         protected void removeErrorMessage(String message)
139:         {
140:                 fErrorMessages.remove(message);
141:                 if (fErrorMessages.isEmpty())
142:                 {
143:                         addErrorMessage(null);
144:                 } else
145:                 {
146:                         addErrorMessage((String) fErrorMessages.get(fErrorMessages.size() - 1));
147:                 }
148:         }
149:
150:         /**
151:          * Stores the values configured in this page. This method should be called from within a workspace runnable to
152:          * reduce the number of resource deltas.
153:          */
154:         protected void doStore() throws CoreException
155:         {
156:                 IVdmBreakpoint breakpoint = getBreakpoint();
157:                 // storeSuspendPolicy(breakpoint);
158:                 storeHitCount(breakpoint);
159:                 storeEnabled(breakpoint);
160:         }
161:
162:         /**
163:          * Stores the value of the enabled state in the breakpoint.
164:          *
165:          * @param breakpoint
166:          * the breakpoint to update
167:          * @throws CoreException
168:          * if an exception occurs while setting the enabled state
169:          */
170:         private void storeEnabled(IVdmBreakpoint breakpoint) throws CoreException
171:         {
172:                 breakpoint.setEnabled(fEnabledButton.getSelection());
173:         }
174:
175:         /**
176:          * Stores the value of the hit count in the breakpoint.
177:          *
178:          * @param breakpoint
179:          * the breakpoint to update
180:          * @throws CoreException
181:          * if an exception occurs while setting the hit count
182:          */
183:         private void storeHitCount(IVdmBreakpoint breakpoint) throws CoreException
184:         {
185:                 int hitCount = -1;
186:                 // if (fHitCountButton.getSelection())
187:                 // {
188:                 try
189:                 {
190:                         hitCount = Integer.parseInt(fHitValueText.getText());
191:                 } catch (NumberFormatException e)
192:                 {
193:                         //                                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)); //$NON-NLS-1$
194:                 }
195:                 // }
196:                 breakpoint.setHitValue(hitCount);
197:                 breakpoint.setHitCondition(fHitValueButton.getSelection() ? IVdmBreakpoint.HIT_CONDITION_GREATER_OR_EQUAL
198:                                 : -1);
199:         }
200:
201:         /**
202:          * Stores the value of the suspend policy in the breakpoint.
203:          *
204:          * @param breakpoint
205:          * the breakpoint to update
206:          * @throws CoreException
207:          * if an exception occurs while setting the suspend policy
208:          */
209:         // private void storeSuspendPolicy(IVdmBreakpoint breakpoint) throws CoreException {
210:         // int suspendPolicy = IVdmBreakpoint.SUSPEND_VM;
211:         // if(fSuspendPolicy.getSelectionIndex() == 0) {
212:         // suspendPolicy = IVdmBreakpoint.SUSPEND_THREAD;
213:         // }
214:         // breakpoint.setSuspendPolicy(suspendPolicy);
215:         // }
216:
217:         /**
218:          * Creates the labels and editors displayed for the breakpoint.
219:          *
220:          * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
221:          */
222:         protected Control createContents(Composite parent)
223:         {
224:                 setTitle("TODO: property title (VdmBreakpointPropertyPage)");
225:                 noDefaultAndApplyButton();
226:                 Composite mainComposite = createComposite(parent, 1);
227:                 createLabels(mainComposite);
228:                 try
229:                 {
230:                         createEnabledButton(mainComposite);
231:                         createHitValueEditor(mainComposite);
232:                         createTypeSpecificEditors(mainComposite);
233:                         // createSuspendPolicyEditor(mainComposite); // Suspend policy is considered uncommon. Add it last.
234:                 } catch (CoreException e)
235:                 {
236:                         
237:                 }
238:                 setValid(true);
239:                 // if this breakpoint is being created, change the shell title to indicate 'creation'
240:                 try
241:                 {
242:                         if (getBreakpoint().getMarker().getAttribute(ATTR_DELETE_ON_CANCEL) != null)
243:                         {
244:                                 getShell().addShellListener(new ShellListener()
245:                                 {
246:                                         public void shellActivated(ShellEvent e)
247:                                         {
248:                                                 Shell shell = (Shell) e.getSource();
249:                                                 shell.setText("TEXT HERE (VdmBreakpointPropertyPage)");// MessageFormat.format("TODO: property page 10 (VdmBreakpointPropertyPage)",
250:                                                                                                                                                                 // new
251:                                                                                                                                                                 // String[]{getName(getBreakpoint())}));
252:                                                 shell.removeShellListener(this);
253:                                         }
254:
255:                                         public void shellClosed(ShellEvent e)
256:                                         {
257:                                         }
258:
259:                                         public void shellDeactivated(ShellEvent e)
260:                                         {
261:                                         }
262:
263:                                         public void shellDeiconified(ShellEvent e)
264:                                         {
265:                                         }
266:
267:                                         public void shellIconified(ShellEvent e)
268:                                         {
269:                                         }
270:                                 });
271:                         }
272:                 } catch (CoreException e)
273:                 {
274:                 }
275:                 return mainComposite;
276:         }
277:
278:         // /**
279:         // * Returns the name of the given element.
280:         // *
281:         // * @param element the element
282:         // * @return the name of the element
283:         // */
284:         // private String getName(IAdaptable element) {
285:         // IWorkbenchAdapter adapter = (IWorkbenchAdapter) element.getAdapter(IWorkbenchAdapter.class);
286:         // if (adapter != null) {
287:         // return adapter.getLabel(element);
288:         // }
289:         // return EMPTY_STRING;
290:         // }
291:         //
292:         /**
293:          * Creates the labels displayed for the breakpoint.
294:          *
295:          * @param parent
296:          */
297:         protected void createLabels(Composite parent)
298:         {
299:                 Composite labelComposite = createComposite(parent, 2);
300:                 try
301:                 {
302:                         String typeName = ((IVdmBreakpoint) getElement()).getMessage();
303:                         if (typeName != null)
304:                         {
305:                                 String s = getTypeName(typeName);
306:                                 createLabel(labelComposite, "Filename:");
307:                                 Text text = SWTFactory.createText(labelComposite, SWT.READ_ONLY, 1, 1);
308:                                 text.setText(s);
309:                                 text.setBackground(parent.getBackground());
310:                         }
311:                         createTypeSpecificLabels(labelComposite);
312:                 } catch (CoreException ce)
313:                 {
314:                         // JDIDebugUIPlugin.log(ce);
315:                 }
316:         }
317:
318:         /**
319:          * Creates the editor for configuring the suspend policy (suspend VM or suspend thread) of the breakpoint.
320:          *
321:          * @param parent
322:          * the composite in which the suspend policy editor will be created.
323:          */
324:         // private void createSuspendPolicyEditor(Composite parent) throws CoreException {
325:         // Composite comp = createComposite(parent, 2);
326:         // createLabel(comp, "Suspend Policy");
327:         // boolean suspendThread= getBreakpoint().getSuspendPolicy() == IVdmBreakpoint.SUSPEND_THREAD;
328:         // fSuspendPolicy = new Combo(comp, SWT.BORDER | SWT.READ_ONLY);
329:         // fSuspendPolicy.add("Suspend Thread");
330:         // fSuspendPolicy.add("Suspend VM");
331:         // fSuspendPolicy.select(1);
332:         // if(suspendThread) {
333:         // fSuspendPolicy.select(0);
334:         // }
335:         // }
336:
337:         private String getTypeName(String typeName)
338:         {
339:                 String[] split = typeName.split(":");
340:                 String res = "";
341:
342:                 if (split.length == 3)
343:                 {
344:                         String[] split2 = split[1].split("\\[");
345:                         if (split2.length == 2)
346:                         {
347:                                 res = split2[0];
348:                         }
349:                 }
350:
351:                 return res;
352:         }
353:
354:         /**
355:          * @param parent
356:          * the composite in which the hit count editor will be created
357:          */
358:         private void createHitValueEditor(Composite parent) throws CoreException
359:         {
360:                 Composite hitCountComposite = createComposite(parent, 2);
361:                 fHitValueButton = createCheckButton(hitCountComposite, "Hit Counter:");
362:                 fHitValueButton.addSelectionListener(new SelectionAdapter()
363:                 {
364:                         public void widgetSelected(SelectionEvent event)
365:                         {
366:                                 fHitValueText.setEnabled(fHitValueButton.getSelection());
367:                                 hitCountChanged();
368:                         }
369:                 });
370:                 int hitValue = getBreakpoint().getHitValue();
371:                 String hitValueString = EMPTY_STRING;
372:                 if (hitValue > 0)
373:                 {
374:                         hitValueString = new Integer(hitValue).toString();
375:                 }
376:                 if (getBreakpoint().getHitCondition() != -1)
377:                 {
378:
379:                         fHitValueButton.setSelection(true);
380:                 } else
381:                 {
382:                         fHitValueButton.setSelection(false);
383:                 }
384:                 fHitValueText = createText(hitCountComposite, hitValueString);
385:                 // if (hitCount <= 0)
386:                 if (!fHitValueButton.getSelection())
387:                 {
388:                         fHitValueText.setEnabled(false);
389:                 }
390:                 fHitValueText.addModifyListener(new ModifyListener()
391:                 {
392:                         public void modifyText(ModifyEvent e)
393:                         {
394:                                 hitCountChanged();
395:                         }
396:                 });
397:         }
398:
399:         /**
400:          * Validates the current state of the hit count editor. Hit count value must be a positive integer.
401:          */
402:         private void hitCountChanged()
403:         {
404:                 if (!fHitValueButton.getSelection())
405:                 {
406:                         removeErrorMessage(fgHitCountErrorMessage);
407:                         return;
408:                 }
409:                 String hitCountText = fHitValueText.getText();
410:                 int hitCount = -1;
411:                 try
412:                 {
413:                         hitCount = Integer.parseInt(hitCountText);
414:                 } catch (NumberFormatException e1)
415:                 {
416:                         addErrorMessage(fgHitCountErrorMessage);
417:                         return;
418:                 }
419:                 if (hitCount < 1)
420:                 {
421:                         addErrorMessage(fgHitCountErrorMessage);
422:                 } else
423:                 {
424:                         removeErrorMessage(fgHitCountErrorMessage);
425:                 }
426:         }
427:
428:         /**
429:          * Creates the button to toggle enablement of the breakpoint
430:          *
431:          * @param parent
432:          * @throws CoreException
433:          */
434:         protected void createEnabledButton(Composite parent) throws CoreException
435:         {
436:                 fEnabledButton = createCheckButton(parent, "Enable");
437:                 fEnabledButton.setSelection(getBreakpoint().isEnabled());
438:         }
439:
440:         /**
441:          * Returns the breakpoint that this preference page configures
442:          *
443:          * @return the breakpoint this page configures
444:          */
445:         protected IVdmBreakpoint getBreakpoint()
446:         {
447:                 return (IVdmBreakpoint) getElement();
448:         }
449:
450:         /**
451:          * Allows subclasses to add type specific labels to the common Java breakpoint page.
452:          *
453:          * @param parent
454:          */
455:         protected void createTypeSpecificLabels(Composite parent)
456:         {
457:         }
458:
459:         /**
460:          * Allows subclasses to add type specific editors to the common Java breakpoint page.
461:          *
462:          * @param parent
463:          */
464:         protected void createTypeSpecificEditors(Composite parent)
465:                         throws CoreException
466:         {
467:         }
468:
469:         /**
470:          * Creates a fully configured text editor with the given initial value
471:          *
472:          * @param parent
473:          * @param initialValue
474:          * @return the configured text editor
475:          */
476:         protected Text createText(Composite parent, String initialValue)
477:         {
478:                 Text t = SWTFactory.createText(parent, SWT.SINGLE | SWT.BORDER, 1);
479:                 t.setText(initialValue);
480:                 return t;
481:         }
482:
483:         /**
484:          * Creates a fully configured composite with the given number of columns
485:          *
486:          * @param parent
487:          * @param numColumns
488:          * @return the configured composite
489:          */
490:         protected Composite createComposite(Composite parent, int numColumns)
491:         {
492:                 return SWTFactory.createComposite(parent, parent.getFont(), numColumns, 1, GridData.FILL_HORIZONTAL, 0, 0);
493:         }
494:
495:         /**
496:          * Creates a fully configured check button with the given text.
497:          *
498:          * @param parent
499:          * the parent composite
500:          * @param text
501:          * the label of the returned check button
502:          * @return a fully configured check button
503:          */
504:         protected Button createCheckButton(Composite parent, String text)
505:         {
506:                 return SWTFactory.createCheckButton(parent, text, null, false, 1);
507:         }
508:
509:         /**
510:          * Creates a fully configured label with the given text.
511:          *
512:          * @param parent
513:          * the parent composite
514:          * @param text
515:          * the test of the returned label
516:          * @return a fully configured label
517:          */
518:         protected Label createLabel(Composite parent, String text)
519:         {
520:                 return SWTFactory.createLabel(parent, text, 1);
521:         }
522:
523:         /**
524:          * Creates a fully configured radio button with the given text.
525:          *
526:          * @param parent
527:          * the parent composite
528:          * @param text
529:          * the label of the returned radio button
530:          * @return a fully configured radio button
531:          */
532:
533:         protected Button createRadioButton(Composite parent, String text)
534:         {
535:                 return SWTFactory.createRadioButton(parent, text);
536:         }
537:
538:         /**
539:          * Check to see if the breakpoint should be deleted.
540:          */
541:         public boolean performCancel()
542:         {
543:                 try
544:                 {
545:                         if (getBreakpoint().getMarker().getAttribute(ATTR_DELETE_ON_CANCEL) != null)
546:                         {
547:                                 // if this breakpoint is being created, delete on cancel
548:                                 getBreakpoint().delete();
549:                         }
550:                 } catch (CoreException e)
551:                 {
552:                         // JDIDebugUIPlugin.statusDialog(PropertyPageMessages.JavaBreakpointPage_9, e.getStatus());
553:                 }
554:                 return super.performCancel();
555:         }
556:
557:         /*
558:          * (non-Javadoc)
559:          * @see org.eclipse.jface.preference.PreferencePage#createControl(org.eclipse.swt.widgets.Composite)
560:          */
561:         public void createControl(Composite parent)
562:         {
563:                 super.createControl(parent);
564:                 // TODO:PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(),
565:                 // IJavaDebugHelpContextIds.JAVA_BREAKPOINT_PROPERTY_PAGE);
566:         }
567:
568: }