Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 22626082fba596184b84d9db49c8ccbad81a113b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
/*******************************************************************************
 * Copyright (c) 2004, 2008 QNX Software Systems and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * QNX Software Systems - Initial API and implementation
 * Nokia - https://bugs.eclipse.org/bugs/show_bug.cgi?id=145606
 * QNX Software Systems - Catchpoints support https://bugs.eclipse.org/bugs/show_bug.cgi?id=226689
 *******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.breakpoints;

import org.eclipse.cdt.debug.core.CDIDebugModel;
import org.eclipse.cdt.debug.core.cdi.model.ICDIMemorySpaceManagement;
import org.eclipse.cdt.debug.core.cdi.model.ICDITarget;
import org.eclipse.cdt.debug.core.model.ICAddressBreakpoint;
import org.eclipse.cdt.debug.core.model.ICBreakpoint;
import org.eclipse.cdt.debug.core.model.ICDebugTarget;
import org.eclipse.cdt.debug.core.model.ICFunctionBreakpoint;
import org.eclipse.cdt.debug.core.model.ICLineBreakpoint;
import org.eclipse.cdt.debug.core.model.ICWatchpoint;
import org.eclipse.cdt.debug.core.model.ICWatchpoint2;
import org.eclipse.cdt.debug.internal.ui.preferences.ComboFieldEditor;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.cdt.debug.ui.breakpoints.CBreakpointUIContributionFactory;
import org.eclipse.cdt.debug.ui.breakpoints.ICBreakpointContext;
import org.eclipse.cdt.debug.ui.breakpoints.ICBreakpointsUIContribution;
import org.eclipse.cdt.debug.ui.preferences.ReadOnlyFieldEditor;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.model.IDebugModelProvider;
import org.eclipse.debug.core.model.ILineBreakpoint;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.debug.ui.contexts.IDebugContextProvider;
import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.FieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.IntegerFieldEditor;
import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbenchPropertyPage;
import org.eclipse.ui.model.IWorkbenchAdapter;

/**
 * The preference page used to present the properties of a breakpoint as preferences. A CBreakpointPreferenceStore is used to interface between this page and
 * the breakpoint.
 */
public class CBreakpointPropertyPage extends FieldEditorPreferencePage implements IWorkbenchPropertyPage {

	class BreakpointIntegerFieldEditor extends IntegerFieldEditor {

		public BreakpointIntegerFieldEditor( String name, String labelText, Composite parent ) {
			super( name, labelText, parent );
			setErrorMessage( BreakpointsMessages.getString( "CBreakpointPropertyPage.0" ) ); //$NON-NLS-1$
		}

		/**
		 * @see IntegerFieldEditor#checkState()
		 */
		@Override
		protected boolean checkState() {
			Text control = getTextControl();
			if ( !control.isEnabled() ) {
				clearErrorMessage();
				return true;
			}
			return super.checkState();
		}

		/**
		 * Overrode here to be package visible.
		 */
		@Override
		protected void refreshValidState() {
			super.refreshValidState();
		}

		/**
		 * Only store if the text control is enabled
		 * 
		 * @see FieldEditor#doStore()
		 */
		@Override
		protected void doStore() {
			Text text = getTextControl();
			if ( text.isEnabled() ) {
				super.doStore();
			}
		}

		/**
		 * Clears the error message from the message line if the error message is the error message from this field editor.
		 */
		@Override
		protected void clearErrorMessage() {
			if ( getPage() != null ) {
				String message = getPage().getErrorMessage();
				if ( message != null ) {
					if ( getErrorMessage().equals( message ) ) {
						super.clearErrorMessage();
					}
				}
				else {
					super.clearErrorMessage();
				}
			}
		}
	}

	class BreakpointStringFieldEditor extends StringFieldEditor {

		public BreakpointStringFieldEditor( String name, String labelText, Composite parent ) {
			super( name, labelText, parent );
		}

		/**
		 * @see StringFieldEditor#checkState()
		 */
		@Override
		protected boolean checkState() {
			Text control = getTextControl();
			if ( !control.isEnabled() ) {
				clearErrorMessage();
				return true;
			}
			return super.checkState();
		}

		@Override
		protected void doStore() {
			Text text = getTextControl();
			if ( text.isEnabled() ) {
				super.doStore();
			}
		}
		protected void doLoad()  {
			String value = getPreferenceStore().getString(getPreferenceName());
            setStringValue(value);
		}

		/**
		 * @see FieldEditor#refreshValidState()
		 */
		@Override
		protected void refreshValidState() {
			super.refreshValidState();
		}

		/**
		 * Clears the error message from the message line if the error message is the error message from this field editor.
		 */
		@Override
		protected void clearErrorMessage() {
			if ( getPage() != null ) {
				String message = getPage().getErrorMessage();
				if ( message != null ) {
					if ( getErrorMessage().equals( message ) ) {
						super.clearErrorMessage();
					}
				}
				else {
					super.clearErrorMessage();
				}
			}
		}
	}

    class WatchpointRangeFieldEditor extends IntegerFieldEditor {

        private static final String DISABLED_VALUE = "0"; //$NON-NLS-1$
        private Button fCheckbox;
        private boolean fWasSelected;
        
        public WatchpointRangeFieldEditor( String name, String labelText, Composite parent ) {
            super( name, labelText, parent );
        }
        
        @Override
        protected void doFillIntoGrid(Composite parent, int numColumns) {
            getCheckboxControl(parent);
            super.doFillIntoGrid(parent, numColumns);
        }

        private Button getCheckboxControl(Composite parent) {
            if (fCheckbox == null) {
                Composite inner= new Composite(parent, SWT.NULL);
                final GridLayout layout= new GridLayout(2, false);
                layout.marginWidth = 0;
                inner.setLayout(layout);
                fCheckbox= new Button(inner, SWT.CHECK);
                fCheckbox.setFont(parent.getFont());
                fCheckbox.setText(getLabelText());
                // create and hide label from base class
                Label label = getLabelControl(inner);
                label.setText(""); //$NON-NLS-1$
                label.setVisible(false);
                fCheckbox.addSelectionListener(new SelectionAdapter() {
                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        boolean isSelected = fCheckbox.getSelection();
                        valueChanged(fWasSelected, isSelected);
                        fWasSelected = isSelected;
                    }
                });
            } else {
                checkParent(fCheckbox.getParent(), parent);
            }
            return fCheckbox;
        }

        @Override
        protected boolean checkState() {
            if (fCheckbox != null && !fCheckbox.getSelection()) {
                clearErrorMessage();
                return true;
            }
            return super.checkState();
        }
        
        @Override
        public Label getLabelControl(Composite parent) {
            final Label label= getLabelControl();
            if (label == null) {
                return super.getLabelControl(parent);
            } else {
                checkParent(label.getParent(), parent);
            }
            return label;
        }

        @Override
        protected void doLoad() {
            if (getTextControl() != null && fCheckbox != null && getLabelControl() != null) {
                oldValue = getPreferenceStore().getString(getPreferenceName());
                boolean enabled = !DISABLED_VALUE.equals(oldValue);
                getTextControl().setText(enabled ? oldValue : ""); //$NON-NLS-1$
                fCheckbox.setSelection(enabled);
                fWasSelected = enabled;
                getTextControl().setEnabled(enabled);
                getLabelControl().setEnabled(enabled);
            }
        }

        @Override
        protected void doStore() {
            if (fCheckbox != null && !fCheckbox.getSelection()) {
                getPreferenceStore().setValue(getPreferenceName(), DISABLED_VALUE);
            } else {
                Text text = getTextControl();
                if (text != null) {
                    getPreferenceStore().setValue(getPreferenceName(), text.getText().trim());
                }
            }
        }

        @Override
        public int getIntValue() throws NumberFormatException {
            if (fCheckbox != null && !fCheckbox.getSelection()) {
                return 0;
            } else {
                return super.getIntValue();
            }
        }
        
        protected void valueChanged(boolean oldValue, boolean newValue) {
            if (oldValue != newValue) {
                valueChanged();
                fireStateChanged(VALUE, oldValue, newValue);
                getTextControl().setEnabled(newValue);
                getLabelControl().setEnabled(newValue);
            }
        }
        
    }

    class WatchpointMemorySpaceFieldEditor extends ComboFieldEditor {

        private static final String DISABLED_VALUE = ""; //$NON-NLS-1$
        private Button fCheckbox;
        private boolean fWasSelected;
        
        public WatchpointMemorySpaceFieldEditor( String name, String labelText, String[] memorySpaces, Composite parent ) {
            super( name, labelText, makeArray2D(memorySpaces), parent );
        }        
        
        @Override
        protected void doFillIntoGrid(Composite parent, int numColumns) {
            getCheckboxControl(parent);
            super.doFillIntoGrid(parent, numColumns);
        }

        private Button getCheckboxControl(Composite parent) {
            if (fCheckbox == null) {
                Composite inner= new Composite(parent, SWT.NULL);
                final GridLayout layout= new GridLayout(2, false);
                layout.marginWidth = 0;
                inner.setLayout(layout);
                fCheckbox= new Button(inner, SWT.CHECK);
                fCheckbox.setFont(parent.getFont());
                fCheckbox.setText(getLabelText());
                // create and hide label from base class
                Label label = getLabelControl(inner);
                label.setText(""); //$NON-NLS-1$
                label.setVisible(false);
                fCheckbox.addSelectionListener(new SelectionAdapter() {
                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        boolean isSelected = fCheckbox.getSelection();
                        valueChanged(fWasSelected, isSelected);
                        fWasSelected = isSelected;
                    }
                });
            } else {
                checkParent(fCheckbox.getParent(), parent);
            }
            return fCheckbox;
        }

        @Override
        public Label getLabelControl(Composite parent) {
            final Label label= getLabelControl();
            if (label == null) {
                return super.getLabelControl(parent);
            } else {
                checkParent(label.getParent(), parent);
            }
            return label;
        }

        @Override
        protected void doLoad() {
            super.doLoad();
            if (fCheckbox != null && getLabelControl() != null) {
                String value = getPreferenceStore().getString(getPreferenceName());
                boolean enabled = !DISABLED_VALUE.equals(value);
                fCheckbox.setSelection(enabled);
                fWasSelected = enabled;
                getComboBoxControl().setEnabled(enabled);
                getLabelControl().setEnabled(enabled);
            }
        }

        @Override
        protected void doStore() {
            if (fCheckbox != null && !fCheckbox.getSelection()) {
                getPreferenceStore().setValue(getPreferenceName(), DISABLED_VALUE);
            } else {
                super.doStore();
            }
        }

        protected void valueChanged(boolean oldValue, boolean newValue) {
            if (oldValue != newValue) {
                fireStateChanged(VALUE, oldValue, newValue);
                getComboBoxControl().setEnabled(newValue);
                getLabelControl().setEnabled(newValue);
            }
        }
        
    }

    private String[][] makeArray2D(String[] array) {
        String[][] array2d = new String[array.length][];
        for (int i = 0; i < array.length; i++) {
            array2d[i] = new String[2];
            array2d[i][0] = array2d[i][1] =  array[i];
        }
        return array2d;
    }

    private ICDIMemorySpaceManagement getMemorySpaceManagement(){
        Object debugViewElement = getDebugContext();
        ICDIMemorySpaceManagement memMgr = null;
        
        if ( debugViewElement != null ) {
            ICDebugTarget debugTarget = (ICDebugTarget)DebugPlugin.getAdapter(debugViewElement, ICDebugTarget.class);
            
            if ( debugTarget != null ){
                ICDITarget target = (ICDITarget)debugTarget.getAdapter(ICDITarget.class);
            
                if (target instanceof ICDIMemorySpaceManagement)
                    memMgr = (ICDIMemorySpaceManagement)target;
            }
        }
        
        return memMgr;
    }
    
	class LabelFieldEditor extends ReadOnlyFieldEditor {
		private String fValue;

		public LabelFieldEditor( Composite parent, String title, String value ) {
			super(title, title, parent);
			fValue = value;
		}

		@Override
		protected void doLoad() {
			if (textField != null) {
				textField.setText(fValue);
			}
		}
		@Override
		protected void doLoadDefault() {
			// nothing
		}

	}

	private BooleanFieldEditor fEnabled;

	private BreakpointStringFieldEditor fCondition;

	private Text fIgnoreCountTextControl;

	private BreakpointIntegerFieldEditor fIgnoreCount;

	private IAdaptable fElement;

	/**
	 * The preference store used to interface between the breakpoint and the 
	 * breakpoint preference page.  This preference store is initialized only
	 * when the preference store cannot be retrieved from the preference 
	 * dialog's element.
	 * @see #getPreferenceStore()
	 */
	private CBreakpointPreferenceStore fCBreakpointPreferenceStore;

	/**
	 * Constructor for CBreakpointPropertyPage.
	 * 
	 * @param breakpoint
	 */
	public CBreakpointPropertyPage() {
		super( GRID );
		noDefaultAndApplyButton();
//		Control control = getControl();
//		fCBreakpointPreferenceStore = new CBreakpointPreferenceStore();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors()
	 */
	@Override
	protected void createFieldEditors() {
		ICBreakpoint breakpoint = getBreakpoint();
		createMainLabel(breakpoint);
		createContributedFieldEditors(breakpoint, ICBreakpointsUIContribution.BREAKPOINT_LABELS);
		createTypeSpecificLabelFieldEditors( breakpoint );
		createEnabledField( getFieldEditorParent() );
		createConditionEditor( getFieldEditorParent() );
		createIgnoreCountEditor( getFieldEditorParent() );
        createContributedFieldEditors(breakpoint, ICBreakpointsUIContribution.BREAKPOINT_EDITORS);
	}

	private void createMainLabel(ICBreakpoint breakpoint) {
	    String label = getBreakpointMainLabel(breakpoint); 
		addField( createLabelEditor( 
		    getFieldEditorParent(), 
		    BreakpointsMessages.getString( "CBreakpointPropertyPage.breakpointType_label" ),  //$NON-NLS-1$
		    label) );
	}

	/**
	 * Method createTypeSpecificLabelFieldEditors.
	 * 
	 * @param breakpoint
	 */
	private void createTypeSpecificLabelFieldEditors( ICBreakpoint breakpoint ) {

		if ( breakpoint instanceof ICFunctionBreakpoint ) {
		    createFunctionEditor(getFieldEditorParent());
		}
		else if ( breakpoint instanceof ICAddressBreakpoint ) {
	        String title = BreakpointsMessages.getString( "CBreakpointPropertyPage.address_label" ); //$NON-NLS-1$
	        
            String address = getPreferenceStore().getString(ICLineBreakpoint.ADDRESS);
            if (address == null || address.trim().length() == 0) {
                address = BreakpointsMessages.getString( "CBreakpointPropertyPage.address_valueNotAvailable_label" ); //$NON-NLS-1$
            }
            addField( createLabelEditor( getFieldEditorParent(), title, address ) ); 
		}
		else if ( breakpoint instanceof ICWatchpoint ) {
			IResource resource = getResource();
			if (resource != null) {
    			IProject project = resource.getProject();
    			if ( project != null ) {
    				addField( createLabelEditor( getFieldEditorParent(), BreakpointsMessages.getString( "CBreakpointPropertyPage.project_label" ), project.getName() ) ); //$NON-NLS-1$
    			}
			} 
			String filename = getPreferenceStore().getString(ICBreakpoint.SOURCE_HANDLE);
			if (filename != null && !"".equals(filename)) { //$NON-NLS-1$
				addField( createLabelEditor( getFieldEditorParent(), BreakpointsMessages.getString( "CBreakpointPropertyPage.sourceHandle_label" ), filename ) ); //$NON-NLS-1$
			}
			createWatchExpressionEditor(getFieldEditorParent());
            createWatchMemorySpaceEditor(getFieldEditorParent());
			createWatchRangeEditor(getFieldEditorParent());
			createWatchTypeEditors(getFieldEditorParent());
			
		}
		else if ( breakpoint instanceof ILineBreakpoint ) {
		    String fileName = getPreferenceStore().getString(ICBreakpoint.SOURCE_HANDLE);
			if ( fileName != null ) {
				addField( createLabelEditor( getFieldEditorParent(), BreakpointsMessages.getString( "CBreakpointPropertyPage.sourceHandle_label" ), fileName ) ); //$NON-NLS-1$
			}
			int lNumber = getPreferenceStore().getInt(IMarker.LINE_NUMBER);
			if (lNumber > 0) {
				getPreferenceStore().setValue( IMarker.LINE_NUMBER, lNumber);
				createLineNumberEditor(getFieldEditorParent());
			}
		}
	}

	private String getBreakpointMainLabel(ICBreakpoint breakpoint) {
	    if (breakpoint instanceof ICWatchpoint  && breakpoint.getMarker() != null) {
	        // For an existing breakpoint, calculate watchpoint label based 
	        // on read/write type.
            boolean isReadType = getPreferenceStore().getBoolean(ICWatchpoint.READ);
            boolean isWriteType = getPreferenceStore().getBoolean(ICWatchpoint.WRITE);
            if (isReadType && !isWriteType) {
                return BreakpointsMessages.getString("CBreakpointPropertyPage.breakpointType_watchpoint_read_label"); //$NON-NLS-1$
            } else if (!isReadType && isWriteType) {
                return BreakpointsMessages.getString("CBreakpointPropertyPage.breakpointType_watchpoint_label"); //$NON-NLS-1$
            } else {
                return BreakpointsMessages.getString("CBreakpointPropertyPage.watchpointType_breakpointType_watchpoint_access_label"); //$NON-NLS-1$
            }
	    }
	    
	    IWorkbenchAdapter labelProvider = (IWorkbenchAdapter)getElement().getAdapter(IWorkbenchAdapter.class);
	    if (labelProvider != null) {
	        return labelProvider.getLabel(getElement());
	    }
        // default main label is the label of marker type for the breakpoint
        return CDIDebugModel.calculateMarkerType(breakpoint);
	}
	
    protected void createFunctionEditor( Composite parent ) {
            
        ICBreakpoint breakpoint = getBreakpoint();
        String title = BreakpointsMessages.getString("CBreakpointPropertyPage.function_label"); //$NON-NLS-1$
        if (breakpoint == null || breakpoint.getMarker() == null) {
            BreakpointStringFieldEditor expressionEditor = new BreakpointStringFieldEditor(
                ICLineBreakpoint.FUNCTION, title, parent);
            expressionEditor.setErrorMessage(BreakpointsMessages.getString("CBreakpointPropertyPage.function_value_errorMessage")); //$NON-NLS-1$
            expressionEditor.setEmptyStringAllowed(false);
            addField(expressionEditor);
        } else {
            String function = getPreferenceStore().getString(ICLineBreakpoint.FUNCTION); 
            if ( function == null ) { 
                function = BreakpointsMessages.getString( "CBreakpointPropertyPage.function_valueNotAvailable_label" ); //$NON-NLS-1$
            }
            addField( createLabelEditor( getFieldEditorParent(), BreakpointsMessages.getString( "CBreakpointPropertyPage.function_label" ), function ) ); //$NON-NLS-1$
        }
    }
	
	protected void createLineNumberEditor( Composite parent ) {
		 String title = BreakpointsMessages.getString( "CBreakpointPropertyPage.lineNumber_label" ); //$NON-NLS-1$
		 BreakpointIntegerFieldEditor labelFieldEditor =new BreakpointIntegerFieldEditor( IMarker.LINE_NUMBER ,title, parent);
		 labelFieldEditor.setValidRange( 1, Integer.MAX_VALUE );
		 addField( labelFieldEditor );
	}

    protected void createWatchExpressionEditor( Composite parent ) {
        ICBreakpoint breakpoint = getBreakpoint();
        if (breakpoint == null || breakpoint.getMarker() == null) {
            BreakpointStringFieldEditor expressionEditor =new BreakpointStringFieldEditor(
                 ICWatchpoint.EXPRESSION,
                 BreakpointsMessages.getString("CBreakpointPropertyPage.watchpoint_expression_label"), //$NON-NLS-1$
                 parent);
            expressionEditor.setErrorMessage(BreakpointsMessages.getString("CBreakpointPropertyPage.watchpoint_expression_errorMessage")); //$NON-NLS-1$
            expressionEditor.setEmptyStringAllowed(false);
            addField(expressionEditor);
        } else {
            addField(createLabelEditor(
                parent, 
                BreakpointsMessages.getString("CBreakpointPropertyPage.watchpoint_expression_label"), //$NON-NLS-1$
                getPreferenceStore().getString(ICWatchpoint.EXPRESSION) ));
        }
    }

    protected void createWatchMemorySpaceEditor( Composite parent ) {
        ICBreakpoint breakpoint = getBreakpoint();
        if (breakpoint == null || breakpoint.getMarker() == null) {
            ICDIMemorySpaceManagement memSpaceMgmt = getMemorySpaceManagement();
            if (memSpaceMgmt != null) {
                String[] memorySpaces = memSpaceMgmt.getMemorySpaces();
                if (memorySpaces != null && memorySpaces.length != 0) {
                    addField( new WatchpointMemorySpaceFieldEditor(
                         ICWatchpoint2.MEMORYSPACE,
                         BreakpointsMessages.getString("CBreakpointPropertyPage.watchpoint_memorySpace_label"), //$NON-NLS-1$
                         memorySpaces,
                         parent) ); 
                }
            }
        } else {
            String memorySpace = getPreferenceStore().getString(ICWatchpoint2.MEMORYSPACE);
            if (memorySpace != null && memorySpace.length() != 0) {
                addField(createLabelEditor(
                    parent, 
                    BreakpointsMessages.getString("CBreakpointPropertyPage.watchpoint_memorySpace_label"), //$NON-NLS-1$
                    getPreferenceStore().getString(ICWatchpoint2.MEMORYSPACE) ));
            }
        }
    }
    
    protected void createWatchRangeEditor( Composite parent ) {
        ICBreakpoint breakpoint = getBreakpoint();
        if (breakpoint == null || breakpoint.getMarker() == null) {
            addField( new WatchpointRangeFieldEditor(
                 ICWatchpoint2.RANGE,
                 BreakpointsMessages.getString("CBreakpointPropertyPage.watchpoint_range_label"), //$NON-NLS-1$
                 parent) ); 
        } else {
            addField(createLabelEditor(
                parent, 
                BreakpointsMessages.getString("CBreakpointPropertyPage.watchpoint_range_label"), //$NON-NLS-1$
                getPreferenceStore().getString(ICWatchpoint2.RANGE) ));
        }
    }

    protected void createWatchTypeEditors( Composite parent ) {
        // Edit read/write options only when creating the breakpoint.
        ICBreakpoint breakpoint = getBreakpoint();
        if (breakpoint != null && breakpoint.getMarker() == null) {
            addField( new BooleanFieldEditor(
                 ICWatchpoint.READ,
                 BreakpointsMessages.getString("CBreakpointPropertyPage.watchpointType_read_label"), //$NON-NLS-1$
                 parent) );
            addField( new BooleanFieldEditor(
                ICWatchpoint.WRITE,
                BreakpointsMessages.getString("CBreakpointPropertyPage.watchpointType_write_label"), //$NON-NLS-1$
                parent) );
        }
    }

	protected void createEnabledField( Composite parent ) {
		fEnabled = new BooleanFieldEditor( ICBreakpoint.ENABLED, BreakpointsMessages.getString( "CBreakpointPropertyPage.enabled_label" ), parent ); //$NON-NLS-1$
		addField( fEnabled );
	}

	protected void createConditionEditor( Composite parent ) {
		fCondition = new BreakpointStringFieldEditor( ICBreakpoint.CONDITION, BreakpointsMessages.getString( "CBreakpointPropertyPage.condition_label" ), parent ); //$NON-NLS-1$
		fCondition.setEmptyStringAllowed( true );
		fCondition.setErrorMessage( BreakpointsMessages.getString( "CBreakpointPropertyPage.condition_invalidValue_message" ) ); //$NON-NLS-1$
		addField( fCondition );
	}

	protected void createIgnoreCountEditor( Composite parent ) {
		fIgnoreCount = new BreakpointIntegerFieldEditor( ICBreakpoint.IGNORE_COUNT, BreakpointsMessages.getString( "CBreakpointPropertyPage.ignoreCount_label" ), parent ); //$NON-NLS-1$
		fIgnoreCount.setValidRange( 0, Integer.MAX_VALUE );
		fIgnoreCountTextControl = fIgnoreCount.getTextControl( parent );
		fIgnoreCountTextControl.setEnabled( getPreferenceStore().getInt(ICBreakpoint.IGNORE_COUNT) >= 0 );
		addField( fIgnoreCount );
	}

	protected FieldEditor createLabelEditor( Composite parent, String title, String value ) {
		return new LabelFieldEditor( parent, title, value );
	}

	protected ICBreakpoint getBreakpoint() {
		IAdaptable element = getElement();
		if (element instanceof ICBreakpoint) {
		    return (ICBreakpoint)element;
		} else if (element instanceof ICBreakpointContext) {
		    return ((ICBreakpointContext)element).getBreakpoint();
		} else {
		    return (ICBreakpoint)element.getAdapter(ICBreakpoint.class);
		}
	}

	protected Object getDebugContext() {
        IDebugContextProvider provider = (IDebugContextProvider)getElement().getAdapter(IDebugContextProvider.class);
        if (provider != null) {
            ISelection selection = provider.getActiveContext();
            if (selection instanceof IStructuredSelection) {
                return ((IStructuredSelection) selection).getFirstElement();
            }
            return null;
        }
        return DebugUITools.getDebugContext();        
	}

	
	protected IResource getResource() {
        IAdaptable element = getElement();
        if (element instanceof ICBreakpoint) {
            IMarker marker = ((ICBreakpoint)element).getMarker();
            if (marker != null) {
                return marker.getResource();
            }
        } else if (element instanceof ICBreakpointContext) {
            return ((ICBreakpointContext)element).getResource();
        } 
        return null;
	}

	public IPreferenceStore getPreferenceStore() {
	    IAdaptable element = getElement();
	    if (element instanceof ICBreakpointContext) {
	        return ((ICBreakpointContext)element).getPreferenceStore();
	    }

	    if (fCBreakpointPreferenceStore == null) {
	        CBreakpointContext bpContext = element instanceof CBreakpointContext ? 
	            (CBreakpointContext)element : null;
	        fCBreakpointPreferenceStore = new CBreakpointPreferenceStore(bpContext, null);
	    }
	    return fCBreakpointPreferenceStore;
	}

	@Override
	public boolean performCancel() {
	    IPreferenceStore store = getPreferenceStore();
	    if (store instanceof CBreakpointPreferenceStore) {
	        ((CBreakpointPreferenceStore)store).setCanceled(true);
	    }
	    return super.performCancel();
	}

	@Override
    public boolean performOk() {
        IPreferenceStore store = getPreferenceStore();
        if (store instanceof CBreakpointPreferenceStore) {
            ((CBreakpointPreferenceStore)store).setCanceled(false);
        }
        return super.performOk();
    }

	/* (non-Javadoc)
	 * @see org.eclipse.ui.IWorkbenchPropertyPage#getElement()
	 */
	@Override
	public IAdaptable getElement() {
		return fElement;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ui.IWorkbenchPropertyPage#setElement(org.eclipse.core.runtime.IAdaptable)
	 */
	@Override
	public void setElement( IAdaptable element ) {
		fElement = element;
	}

	/**
	 * Creates field editors contributed using breakpointUIContribution extension point
	 */
	private void createContributedFieldEditors(ICBreakpoint breakpoint, String conMainElement) {
		Composite parent = getFieldEditorParent();
		String[] debugModelIds = CBreakpointUIContributionFactory.DEBUG_MODEL_IDS_DEFAULT;
		IDebugModelProvider debugModelProvider = (IDebugModelProvider)DebugPlugin.getAdapter(
		    getDebugContext(), IDebugModelProvider.class);
		if (debugModelProvider != null) {
		    debugModelIds = debugModelProvider.getModelIdentifiers();
		}
		
		try {
		    ICBreakpointsUIContribution[] cons;
		    CBreakpointUIContributionFactory factory = CBreakpointUIContributionFactory.getInstance();
		    IPreferenceStore prefStore = getPreferenceStore();
		    if (prefStore instanceof CBreakpointPreferenceStore) {
		        cons = factory.getBreakpointUIContributions(
		            debugModelIds, breakpoint, ((CBreakpointPreferenceStore) prefStore).getAttributes());
		    } else {
                cons = factory.getBreakpointUIContributions(breakpoint);
		    }
		    
			for (ICBreakpointsUIContribution con : cons) {
			    if ( conMainElement.equals(con.getMainElement()) ) {
    				FieldEditor fieldEditor = con.getFieldEditor(con.getId(), con.getLabel() + ":", parent); //$NON-NLS-1$
    				if (fieldEditor != null) {
    					addField(fieldEditor);
    				}
			    }
			}
		} catch (CoreException ce) {
			CDebugUIPlugin.log(ce);
		}

	}

}

Back to the top