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