1 package net.sourceforge.phpeclipse.xdebug.ui;
4 import java.util.ArrayList;
5 import java.util.HashMap;
6 import java.util.Iterator;
10 import org.eclipse.debug.ui.IDebugUIConstants;
11 import org.eclipse.debug.ui.StringVariableSelectionDialog;
12 import org.eclipse.jface.dialogs.Dialog;
13 import org.eclipse.jface.dialogs.IDialogConstants;
14 import org.eclipse.swt.SWT;
15 import org.eclipse.swt.events.ModifyEvent;
16 import org.eclipse.swt.events.ModifyListener;
17 import org.eclipse.swt.events.SelectionAdapter;
18 import org.eclipse.swt.events.SelectionEvent;
19 import org.eclipse.swt.layout.GridData;
20 import org.eclipse.swt.layout.GridLayout;
21 import org.eclipse.swt.widgets.Button;
22 import org.eclipse.swt.widgets.Composite;
23 import org.eclipse.swt.widgets.Control;
24 import org.eclipse.swt.widgets.DirectoryDialog;
25 import org.eclipse.swt.widgets.Label;
26 import org.eclipse.swt.widgets.Shell;
27 import org.eclipse.swt.widgets.Text;
29 public class MultipleInputDialog extends Dialog {
30 protected static final String FIELD_NAME = "FIELD_NAME"; //$NON-NLS-1$
32 protected static final int TEXT = 100;
34 protected static final int BROWSE = 101;
36 protected static final int VARIABLE = 102;
38 protected Composite panel;
40 protected List fieldList = new ArrayList();
42 protected List controlList = new ArrayList();
44 protected List validators = new ArrayList();
46 protected Map valueMap = new HashMap();
50 public MultipleInputDialog(Shell shell, String title) {
53 setShellStyle(getShellStyle() | SWT.RESIZE);
59 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
61 protected void configureShell(Shell shell) {
62 super.configureShell(shell);
72 * @see org.eclipse.jface.dialogs.Dialog#createButtonBar(org.eclipse.swt.widgets.Composite)
74 protected Control createButtonBar(Composite parent) {
75 Control bar = super.createButtonBar(parent);
83 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
85 protected Control createDialogArea(Composite parent) {
86 Composite container = (Composite) super.createDialogArea(parent);
87 container.setLayout(new GridLayout(2, false));
88 container.setLayoutData(new GridData(GridData.FILL_BOTH));
90 panel = new Composite(container, SWT.NONE);
91 GridLayout layout = new GridLayout(2, false);
92 panel.setLayout(layout);
93 panel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
95 for (Iterator i = fieldList.iterator(); i.hasNext();) {
96 FieldSummary field = (FieldSummary) i.next();
99 createTextField(field.name, field.initialValue,
103 createBrowseField(field.name, field.initialValue,
107 createVariablesField(field.name, field.initialValue,
113 fieldList = null; // allow it to be gc'd
114 Dialog.applyDialogFont(container);
118 public void addBrowseField(String labelText, String initialValue,
119 boolean allowsEmpty) {
120 fieldList.add(new FieldSummary(BROWSE, labelText, initialValue,
124 public void addTextField(String labelText, String initialValue,
125 boolean allowsEmpty) {
126 fieldList.add(new FieldSummary(TEXT, labelText, initialValue,
130 public void addVariablesField(String labelText, String initialValue,
131 boolean allowsEmpty) {
132 fieldList.add(new FieldSummary(VARIABLE, labelText, initialValue,
136 protected void createTextField(String labelText, String initialValue,
137 boolean allowEmpty) {
138 Label label = new Label(panel, SWT.NONE);
139 label.setText(labelText);
140 label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
142 final Text text = new Text(panel, SWT.SINGLE | SWT.BORDER);
143 text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
144 text.setData(FIELD_NAME, labelText);
146 // make sure rows are the same height on both panels.
147 label.setSize(label.getSize().x, text.getSize().y);
149 if (initialValue != null) {
150 text.setText(initialValue);
154 validators.add(new Validator() {
155 public boolean validate() {
156 return !text.getText().equals(""); //$NON-NLS-1$
159 text.addModifyListener(new ModifyListener() {
160 public void modifyText(ModifyEvent e) {
166 controlList.add(text);
169 protected void createBrowseField(String labelText, String initialValue,
170 boolean allowEmpty) {
171 Label label = new Label(panel, SWT.NONE);
172 label.setText(labelText);
173 label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
175 Composite comp = new Composite(panel, SWT.NONE);
176 GridLayout layout = new GridLayout();
177 layout.marginHeight = 0;
178 layout.marginWidth = 0;
179 comp.setLayout(layout);
180 comp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
182 final Text text = new Text(comp, SWT.SINGLE | SWT.BORDER);
183 GridData data = new GridData(GridData.FILL_HORIZONTAL);
184 data.widthHint = 200;
185 text.setLayoutData(data);
186 text.setData(FIELD_NAME, labelText);
188 // make sure rows are the same height on both panels.
189 label.setSize(label.getSize().x, text.getSize().y);
191 if (initialValue != null) {
192 text.setText(initialValue);
196 validators.add(new Validator() {
197 public boolean validate() {
198 return !text.getText().equals(""); //$NON-NLS-1$
202 text.addModifyListener(new ModifyListener() {
203 public void modifyText(ModifyEvent e) {
209 Button button = createButton(comp, IDialogConstants.IGNORE_ID,
210 "&Browse...", false);
211 button.addSelectionListener(new SelectionAdapter() {
212 public void widgetSelected(SelectionEvent e) {
213 DirectoryDialog dialog = new DirectoryDialog(getShell());
214 dialog.setMessage("Select a file:");
215 String currentWorkingDir = text.getText();
216 if (!currentWorkingDir.trim().equals("")) { //$NON-NLS-1$
217 File path = new File(currentWorkingDir);
219 dialog.setFilterPath(currentWorkingDir);
223 String selectedDirectory = dialog.open();
224 if (selectedDirectory != null) {
225 text.setText(selectedDirectory);
230 controlList.add(text);
234 public void createVariablesField(String labelText, String initialValue,
235 boolean allowEmpty) {
236 Label label = new Label(panel, SWT.NONE);
237 label.setText(labelText);
238 label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
240 Composite comp = new Composite(panel, SWT.NONE);
241 GridLayout layout = new GridLayout();
242 layout.marginHeight = 0;
243 layout.marginWidth = 0;
244 comp.setLayout(layout);
245 comp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
247 final Text text = new Text(comp, SWT.SINGLE | SWT.BORDER);
248 GridData data = new GridData(GridData.FILL_HORIZONTAL);
249 data.widthHint = 200;
250 text.setLayoutData(data);
251 text.setData(FIELD_NAME, labelText);
253 // make sure rows are the same height on both panels.
254 label.setSize(label.getSize().x, text.getSize().y);
256 if (initialValue != null) {
257 text.setText(initialValue);
261 validators.add(new Validator() {
262 public boolean validate() {
263 return !text.getText().equals(""); //$NON-NLS-1$
267 text.addModifyListener(new ModifyListener() {
268 public void modifyText(ModifyEvent e) {
274 Button button = createButton(comp, IDialogConstants.IGNORE_ID,
275 "Varia&bles...", false);
276 button.addSelectionListener(new SelectionAdapter() {
277 public void widgetSelected(SelectionEvent e) {
278 StringVariableSelectionDialog dialog = new StringVariableSelectionDialog(
280 int code = dialog.open();
281 if (code == IDialogConstants.OK_ID) {
282 String variable = dialog.getVariableExpression();
283 if (variable != null) {
284 text.insert(variable);
290 controlList.add(text);
297 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
299 protected void okPressed() {
300 for (Iterator i = controlList.iterator(); i.hasNext();) {
301 Control control = (Control) i.next();
302 if (control instanceof Text) {
303 valueMap.put(control.getData(FIELD_NAME), ((Text) control)
314 * @see org.eclipse.jface.window.Window#open()
317 applyDialogFont(panel);
321 public Object getValue(String key) {
322 return valueMap.get(key);
325 public String getStringValue(String key) {
326 return (String) getValue(key);
329 public void validateFields() {
330 for (Iterator i = validators.iterator(); i.hasNext();) {
331 Validator validator = (Validator) i.next();
332 if (!validator.validate()) {
333 getButton(IDialogConstants.OK_ID).setEnabled(false);
337 getButton(IDialogConstants.OK_ID).setEnabled(true);
342 // org.eclipse.jface.window.Window#getInitialLocation(org.eclipse.swt.graphics.Point)
344 // protected Point getInitialLocation(Point initialSize) {
345 // Point initialLocation=
346 // DialogSettingsHelper.getInitialLocation(getDialogSettingsSectionName());
347 // if (initialLocation != null) {
348 // return initialLocation;
350 // return super.getInitialLocation(initialSize);
353 protected String getDialogSettingsSectionName() {
354 return IDebugUIConstants.PLUGIN_ID + ".MULTIPLE_INPUT_DIALOG_2"; //$NON-NLS-1$
358 // * @see org.eclipse.jface.window.Window#getInitialSize()
360 // protected Point getInitialSize() {
361 // Point size = super.getInitialSize();
363 // DialogSettingsHelper.getInitialSize(getDialogSettingsSectionName(),
368 // * @see org.eclipse.jface.window.Window#close()
370 // public boolean close() {
371 // DialogSettingsHelper.persistShellGeometry(getShell(),
372 // getDialogSettingsSectionName());
373 // return super.close();
376 protected class FieldSummary {
385 public FieldSummary(int type, String name, String initialValue,
386 boolean allowsEmpty) {
389 this.initialValue = initialValue;
390 this.allowsEmpty = allowsEmpty;
394 protected class Validator {