1) Breakpoint properties dialog (for skip counts and condition).
[phpeclipse.git] / net.sourceforge.phpeclipse.debug.ui / src / net / sourceforge / phpdt / internal / debug / ui / properties / PHPBreakpointPropertiesDialog.java
1
2 package net.sourceforge.phpdt.internal.debug.ui.properties;
3
4 import org.eclipse.core.runtime.CoreException;
5 import org.eclipse.debug.internal.ui.actions.*;
6 import org.eclipse.jface.dialogs.StatusDialog;
7 import org.eclipse.jface.resource.JFaceResources;
8 import org.eclipse.jface.text.Document;
9 import org.eclipse.jface.text.DocumentEvent;
10 import org.eclipse.jface.text.IDocument;
11 import org.eclipse.jface.text.IDocumentListener;
12 import org.eclipse.jface.text.source.SourceViewer;
13 import org.eclipse.jface.text.source.SourceViewerConfiguration;
14 import org.eclipse.swt.SWT;
15 import org.eclipse.swt.graphics.Font;
16 import org.eclipse.swt.layout.GridData;
17 import org.eclipse.swt.layout.GridLayout;
18 import org.eclipse.swt.widgets.Button;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.swt.widgets.Control;
21 import org.eclipse.swt.widgets.Label;
22 import org.eclipse.swt.widgets.Shell;
23 import org.eclipse.swt.widgets.Spinner;
24
25 import net.sourceforge.phpdt.internal.debug.core.breakpoints.PHPLineBreakpoint;
26
27 public class PHPBreakpointPropertiesDialog extends StatusDialog {
28
29         private PHPLineBreakpoint fBreakpoint;
30         private SourceViewer      fSnippetViewer;
31         private Button            fCheckBox;
32         private Spinner               fSpinner;
33         
34         public PHPBreakpointPropertiesDialog(Shell parentShell, PHPLineBreakpoint bp) {
35                 super(parentShell);
36                 
37                 fBreakpoint = bp;
38         }
39         
40
41         protected Control createDialogArea (Composite parent) {
42                 Composite  container;
43                 GridLayout layout;
44                 GridData   gd;
45                 IDocument  document;
46                 Control    control;
47                 Label      label;
48                 Spinner    spinner;
49                 String     condition = "";
50                 boolean    enabled   = false;
51                 int        hitCount  = 0;
52                 
53                 try {
54                         condition = fBreakpoint.getCondition ();
55                         enabled   = fBreakpoint.isConditionEnabled ();
56                         hitCount  = fBreakpoint.getHitCount();
57                 }
58                 catch (CoreException e) {
59                 }
60                 
61                 Font font = parent.getFont();                                                           // Get the dialog's font
62                 container = new Composite(parent, SWT.NONE);                            // Create a new container for our controls
63                 layout    = new GridLayout();                                                           // Create a grid for control layouting
64                 
65                 container.setLayout (layout);                                                           // Set the grid to the container
66                 gd        = new GridData (SWT.FILL, SWT.FILL, true, true);
67                 container.setLayoutData (gd);
68
69                 label     = new Label (container, SWT.NONE);                            // spinner label
70                 label.setText ("Skip count");                                                           // $NON-NLS-1$
71                 
72                 gd        = new GridData (SWT.BEGINNING);                                       // Left align of label text
73                 label.setLayoutData (gd);                                                                       // 
74                 label.setFont (font);                                                                           // Set the label's font
75                 
76                 fSpinner  = new Spinner (container, SWT.BORDER);
77                 fSpinner.setMinimum (0);
78                 fSpinner.setMaximum (100000);
79                 fSpinner.setIncrement (1);
80                 fSpinner.setPageIncrement (100);
81                 fSpinner.setSelection (hitCount);
82                 gd        = new GridData (SWT.BEGINNING);
83                 label.setLayoutData (gd);                                                                       // 
84                 label.setFont (font);                                                                           // Set the label's font
85                 
86                 label     = new Label (container, SWT.NONE);                            // snippet label
87                 label.setText ("Break Condition");                                                      // $NON-NLS-1$
88                 
89                 gd        = new GridData (SWT.BEGINNING);                                       // Left align of label text
90                 label.setLayoutData (gd);                                                                       // 
91                 label.setFont (font);                                                                           // Set the label's font
92                 
93                 fSnippetViewer = new SourceViewer (container, null, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
94                 fSnippetViewer.setInput (this);
95                 
96                 document       = new Document();
97                 
98                 //IDocumentPartitioner partitioner= new RuleBasedPartitioner(...);
99                 //document.setDocumentPartitioner(partitioner);
100                 //partitioner.connect(document);
101                 
102                 fSnippetViewer.configure (new SourceViewerConfiguration());
103                 fSnippetViewer.setEditable (true);
104                 fSnippetViewer.setDocument (document);
105                 
106                 document.addDocumentListener (new IDocumentListener() {
107                         public void documentAboutToBeChanged(DocumentEvent event) {
108                         }
109                         public void documentChanged(DocumentEvent event) {
110                                 checkValues();
111                         }
112                 });
113
114                 fSnippetViewer.getTextWidget ().setFont (JFaceResources.getTextFont());
115
116                 control       = fSnippetViewer.getControl ();
117                 gd            = new GridData (GridData.FILL_BOTH);
118                 gd.heightHint = convertHeightInCharsToPixels (10);
119                 gd.widthHint  = convertWidthInCharsToPixels (80);
120                 
121                 control.setLayoutData (gd);
122                 fSnippetViewer.getDocument ().set (condition);
123
124                 // enable checkbox
125                 fCheckBox = new Button (container, SWT.CHECK | SWT.LEFT);
126                 fCheckBox.setText ("Enable Condition"); //$NON-NLS-1$
127                 fCheckBox.setSelection (enabled);
128                 fCheckBox.setFont (font);
129
130                 applyDialogFont(container);
131                 fSnippetViewer.getControl().setFocus();
132                 
133                 checkValues ();
134                 
135                 return container;
136         }
137         
138         protected void okPressed () {
139                 try {
140                         fBreakpoint.setCondition (fSnippetViewer.getDocument().get());
141                         fBreakpoint.setConditionEnabled (fCheckBox.getSelection());
142                         fBreakpoint.setHitCount(fSpinner.getSelection());
143                         
144                         int id = fBreakpoint.getChangeID();
145                         id++;
146                         fBreakpoint.setChangeID(id);
147                 }
148                 catch (CoreException e) {
149                 }
150                 
151                 super.okPressed ();
152         }
153         
154         /**
155          * Check the field values and display a message in the status if needed.
156          */
157         private void checkValues() {
158                 StatusInfo status;
159                 
160                 status = new StatusInfo ();
161                 /*
162                 StatusInfo status = new StatusInfo();
163                                 if (fSnippetViewer.getDocument().get().trim().length() == 0) {
164                         status.setError(ActionMessages.WatchExpressionDialog_4); //$NON-NLS-1$
165                 }
166                 */
167                 updateStatus(status);
168         }
169 }