|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
|
2 // Use of this source code is governed by a BSD-style license that can be |
|
3 // found in the LICENSE file. |
|
4 |
|
5 package org.chromium.debug.ui.propertypages; |
|
6 |
|
7 import java.util.ArrayList; |
|
8 import java.util.List; |
|
9 |
|
10 import org.chromium.debug.core.ChromiumDebugPlugin; |
|
11 import org.chromium.debug.core.model.ChromiumLineBreakpoint; |
|
12 import org.chromium.debug.core.util.ChromiumDebugPluginUtil; |
|
13 import org.eclipse.core.resources.IWorkspaceRunnable; |
|
14 import org.eclipse.core.resources.ResourcesPlugin; |
|
15 import org.eclipse.core.runtime.CoreException; |
|
16 import org.eclipse.core.runtime.IProgressMonitor; |
|
17 import org.eclipse.jface.resource.JFaceResources; |
|
18 import org.eclipse.swt.SWT; |
|
19 import org.eclipse.swt.events.ModifyEvent; |
|
20 import org.eclipse.swt.events.ModifyListener; |
|
21 import org.eclipse.swt.events.SelectionAdapter; |
|
22 import org.eclipse.swt.events.SelectionEvent; |
|
23 import org.eclipse.swt.layout.GridData; |
|
24 import org.eclipse.swt.layout.GridLayout; |
|
25 import org.eclipse.swt.widgets.Button; |
|
26 import org.eclipse.swt.widgets.Composite; |
|
27 import org.eclipse.swt.widgets.Control; |
|
28 import org.eclipse.swt.widgets.Label; |
|
29 import org.eclipse.swt.widgets.Text; |
|
30 import org.eclipse.ui.dialogs.PropertyPage; |
|
31 |
|
32 /** |
|
33 * A JavaScript line breakpoint property page. |
|
34 */ |
|
35 public class JsLineBreakpointPage extends PropertyPage { |
|
36 |
|
37 private final List<String> errorMessages = new ArrayList<String>(2); |
|
38 |
|
39 private Button enabledCheckbox; |
|
40 |
|
41 private Button ignoreCountCheckbox; |
|
42 |
|
43 private Text ignoreCountText; |
|
44 |
|
45 private Button conditionCheckbox; |
|
46 |
|
47 private Text conditionText; |
|
48 |
|
49 @Override |
|
50 protected Control createContents(Composite parent) { |
|
51 noDefaultAndApplyButton(); |
|
52 Composite mainComposite = createComposite(parent, 2, 1); |
|
53 try { |
|
54 createBreakpointDataControls(mainComposite); |
|
55 createInfoControls(mainComposite); |
|
56 createEnabledControls(mainComposite); |
|
57 createIgnoreCountControls(mainComposite); |
|
58 createConditionControls(mainComposite); |
|
59 } catch (CoreException e) { |
|
60 ChromiumDebugPlugin.log(e); |
|
61 } |
|
62 setValid(true); |
|
63 return mainComposite; |
|
64 } |
|
65 |
|
66 @Override |
|
67 public boolean performOk() { |
|
68 IWorkspaceRunnable runnable = new IWorkspaceRunnable() { |
|
69 public void run(IProgressMonitor monitor) throws CoreException { |
|
70 storePrefs(); |
|
71 } |
|
72 }; |
|
73 try { |
|
74 ResourcesPlugin.getWorkspace().run(runnable, null, 0, null); |
|
75 } catch (CoreException e) { |
|
76 ChromiumDebugPlugin.log(e); |
|
77 } |
|
78 return super.performOk(); |
|
79 } |
|
80 |
|
81 private void storePrefs() throws CoreException { |
|
82 ChromiumLineBreakpoint breakpoint = getBreakpoint(); |
|
83 breakpoint.setEnabled(enabledCheckbox.getSelection()); |
|
84 breakpoint.setIgnoreCount(ignoreCountCheckbox.getSelection() |
|
85 ? Integer.valueOf(ignoreCountText.getText()) |
|
86 : -1); |
|
87 String condition = null; |
|
88 if (conditionCheckbox.getSelection()) { |
|
89 String text = conditionText.getText().trim(); |
|
90 if (text.length() > 0) { |
|
91 condition = text; |
|
92 } |
|
93 } |
|
94 breakpoint.setCondition(condition); |
|
95 } |
|
96 |
|
97 private void createBreakpointDataControls(Composite mainComposite) { |
|
98 // new Label |
|
99 } |
|
100 |
|
101 private void createInfoControls(Composite parent) { |
|
102 Composite infoComposite = createComposite(parent, 2, 2); |
|
103 Label resourceLabel = new Label(infoComposite, SWT.NONE); |
|
104 resourceLabel.setText(Messages.JsLineBreakpointPage_ResourceLabel); |
|
105 Label resourceNameLabel = new Label(infoComposite, SWT.NONE); |
|
106 resourceNameLabel.setText(getBreakpoint().getMarker().getResource().getName()); |
|
107 |
|
108 Label lineNumberLabel = new Label(infoComposite, SWT.NONE); |
|
109 lineNumberLabel.setText(Messages.JsLineBreakpointPage_LineNumberLabel); |
|
110 Label lineNumberValueLabel = new Label(infoComposite, SWT.NONE); |
|
111 String lineNumber = Messages.JsLineBreakpointPage_UnknownLineNumber; |
|
112 try { |
|
113 lineNumber = String.valueOf(getBreakpoint().getLineNumber()); |
|
114 } catch (CoreException e) { |
|
115 ChromiumDebugPlugin.log(e); |
|
116 } |
|
117 lineNumberValueLabel.setText(lineNumber); |
|
118 } |
|
119 |
|
120 private void createEnabledControls(Composite parent) throws CoreException { |
|
121 enabledCheckbox = new Button(parent, SWT.CHECK); |
|
122 GridData gd = new GridData(); |
|
123 gd.horizontalSpan = 2; |
|
124 enabledCheckbox.setLayoutData(gd); |
|
125 enabledCheckbox.setSelection(getBreakpoint().isEnabled()); |
|
126 enabledCheckbox.setText(Messages.JavascriptLineBreakpointPage_Enabled); |
|
127 } |
|
128 |
|
129 private void createIgnoreCountControls(Composite parent) throws CoreException { |
|
130 ignoreCountCheckbox = new Button(parent, SWT.CHECK); |
|
131 Integer ignoreCount = getBreakpoint().getIgnoreCount(); |
|
132 ignoreCountCheckbox.setSelection(ignoreCount != null); |
|
133 ignoreCountCheckbox.addSelectionListener(new SelectionAdapter() { |
|
134 @Override |
|
135 public void widgetSelected(SelectionEvent e) { |
|
136 ignoreCountText.setEnabled(ignoreCountCheckbox.getSelection()); |
|
137 ignoreCountChanged(); |
|
138 } |
|
139 }); |
|
140 ignoreCountCheckbox.setText(Messages.JavascriptLineBreakpointPage_IgnoreCount); |
|
141 ignoreCountText = new Text(parent, SWT.SINGLE | SWT.BORDER); |
|
142 ignoreCountText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); |
|
143 ignoreCountText.setTextLimit(10); |
|
144 ignoreCountText.setEnabled(ignoreCountCheckbox.getSelection()); |
|
145 if (ignoreCount != null) { |
|
146 ignoreCountText.setText(String.valueOf(ignoreCount)); |
|
147 } |
|
148 ignoreCountText.addModifyListener(new ModifyListener() { |
|
149 public void modifyText(ModifyEvent e) { |
|
150 ignoreCountChanged(); |
|
151 } |
|
152 }); |
|
153 } |
|
154 |
|
155 private void ignoreCountChanged() { |
|
156 boolean isOn = ignoreCountCheckbox.getSelection(); |
|
157 if (!isOn) { |
|
158 removeErrorMessage(Messages.JavascriptLineBreakpointPage_IgnoreCountErrorMessage); |
|
159 return; |
|
160 } |
|
161 String value = ignoreCountText.getText(); |
|
162 int ignoreCount = -1; |
|
163 if (!ChromiumDebugPluginUtil.isInteger(value)) { |
|
164 addErrorMessage(Messages.JavascriptLineBreakpointPage_IgnoreCountErrorMessage); |
|
165 return; |
|
166 } |
|
167 ignoreCount = Integer.valueOf(value); |
|
168 if (ignoreCount < 1) { |
|
169 addErrorMessage(Messages.JavascriptLineBreakpointPage_IgnoreCountErrorMessage); |
|
170 } else { |
|
171 removeErrorMessage(Messages.JavascriptLineBreakpointPage_IgnoreCountErrorMessage); |
|
172 } |
|
173 } |
|
174 |
|
175 private void addErrorMessage(String message) { |
|
176 errorMessages.remove(message); |
|
177 errorMessages.add(message); |
|
178 setErrorMessage(message); |
|
179 } |
|
180 |
|
181 private void removeErrorMessage(String message) { |
|
182 errorMessages.remove(message); |
|
183 if (errorMessages.isEmpty()) { |
|
184 setErrorMessage(null); |
|
185 } else { |
|
186 setErrorMessage(errorMessages.get(errorMessages.size() - 1)); |
|
187 } |
|
188 } |
|
189 |
|
190 @Override |
|
191 public void setErrorMessage(String newMessage) { |
|
192 super.setErrorMessage(newMessage); |
|
193 setValid(newMessage == null); |
|
194 } |
|
195 |
|
196 private void createConditionControls(Composite parent) { |
|
197 conditionCheckbox = new Button(parent, SWT.CHECK); |
|
198 conditionCheckbox.setSelection(getBreakpoint().getCondition() != null); |
|
199 conditionCheckbox.addSelectionListener(new SelectionAdapter() { |
|
200 @Override |
|
201 public void widgetSelected(SelectionEvent e) { |
|
202 conditionText.setEnabled(conditionCheckbox.getSelection()); |
|
203 conditionChanged(); |
|
204 } |
|
205 }); |
|
206 conditionCheckbox.setText(Messages.JavascriptLineBreakpointPage_EnableCondition); |
|
207 GridData gd = new GridData(); |
|
208 gd.horizontalSpan = 2; |
|
209 conditionCheckbox.setLayoutData(gd); |
|
210 conditionText = new Text(parent, SWT.MULTI | SWT.BORDER); |
|
211 gd = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1); |
|
212 conditionText.setLayoutData(gd); |
|
213 conditionText.setTextLimit(300); |
|
214 conditionText.setFont(JFaceResources.getTextFont()); |
|
215 conditionText.setEnabled(conditionCheckbox.getSelection()); |
|
216 conditionText.addModifyListener(new ModifyListener() { |
|
217 public void modifyText(ModifyEvent e) { |
|
218 conditionChanged(); |
|
219 } |
|
220 }); |
|
221 conditionText.setText(maskNull(getBreakpoint().getCondition())); |
|
222 } |
|
223 |
|
224 private static String maskNull(String value) { |
|
225 return value == null |
|
226 ? "" : value; //$NON-NLS-1$ |
|
227 } |
|
228 |
|
229 private void conditionChanged() { |
|
230 boolean isOn = conditionCheckbox.getSelection(); |
|
231 if (!isOn) { |
|
232 removeErrorMessage(Messages.JavascriptLineBreakpointPage_BreakpointConditionErrorMessage); |
|
233 return; |
|
234 } |
|
235 String value = conditionText.getText(); |
|
236 if (value == null) { |
|
237 addErrorMessage(Messages.JavascriptLineBreakpointPage_BreakpointConditionErrorMessage); |
|
238 } else { |
|
239 removeErrorMessage(Messages.JavascriptLineBreakpointPage_BreakpointConditionErrorMessage); |
|
240 } |
|
241 } |
|
242 |
|
243 private Composite createComposite(Composite parent, int columns, int horizontalSpan) { |
|
244 Composite composite = new Composite(parent, SWT.NONE); |
|
245 GridLayout layout = new GridLayout(columns, false); |
|
246 layout.marginWidth = 0; |
|
247 layout.marginHeight = 0; |
|
248 composite.setLayout(layout); |
|
249 composite.setFont(parent.getFont()); |
|
250 GridData gridData = new GridData(GridData.FILL_HORIZONTAL); |
|
251 gridData.horizontalSpan = horizontalSpan; |
|
252 composite.setLayoutData(gridData); |
|
253 return composite; |
|
254 } |
|
255 |
|
256 protected ChromiumLineBreakpoint getBreakpoint() { |
|
257 return (ChromiumLineBreakpoint) getElement(); |
|
258 } |
|
259 } |