1 /**********************************************************************
2 * Copyright (c) 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM - Initial API and implementation
10 **********************************************************************/
11 package net.sourceforge.phpeclipse.webbrowser.internal;
15 import net.sourceforge.phpeclipse.webbrowser.IExternalWebBrowserWorkingCopy;
17 import org.eclipse.jface.dialogs.Dialog;
18 import org.eclipse.jface.dialogs.IDialogConstants;
19 import org.eclipse.swt.SWT;
20 import org.eclipse.swt.events.ModifyEvent;
21 import org.eclipse.swt.events.ModifyListener;
22 import org.eclipse.swt.events.SelectionAdapter;
23 import org.eclipse.swt.events.SelectionEvent;
24 import org.eclipse.swt.layout.GridData;
25 import org.eclipse.swt.layout.GridLayout;
26 import org.eclipse.swt.widgets.Button;
27 import org.eclipse.swt.widgets.Composite;
28 import org.eclipse.swt.widgets.Control;
29 import org.eclipse.swt.widgets.FileDialog;
30 import org.eclipse.swt.widgets.Label;
31 import org.eclipse.swt.widgets.Shell;
32 import org.eclipse.swt.widgets.Text;
33 import org.eclipse.ui.PlatformUI;
38 public class ExternalBrowserDialog extends Dialog {
39 protected IExternalWebBrowserWorkingCopy browser;
41 protected boolean isEdit;
43 protected Button newPageCheckbox;
45 protected Button clearHistoryCheckbox;
47 protected Button browseButton;
49 protected Text browserNameTextfield;
51 protected Text browserLocationTextfield;
53 protected Text browserParametersTextfield;
55 private Button okButton;
57 interface StringModifyListener {
58 public void valueChanged(String s);
64 public ExternalBrowserDialog(Shell parentShell,
65 IExternalWebBrowserWorkingCopy browser) {
67 this.browser = browser;
71 public ExternalBrowserDialog(Shell parentShell) {
73 browser = BrowserManager.getInstance().createExternalWebBrowser();
77 protected void configureShell(Shell shell) {
78 super.configureShell(shell);
81 shell.setText(WebBrowserUIPlugin
82 .getResource("%editExternalBrowser"));
84 shell.setText(WebBrowserUIPlugin.getResource("%createBrowser"));
87 protected Text createText(Composite comp, String txt,
88 final StringModifyListener listener) {
89 final Text text = new Text(comp, SWT.BORDER);
92 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL
93 | GridData.VERTICAL_ALIGN_BEGINNING);
95 text.setLayoutData(data);
97 text.addModifyListener(new ModifyListener() {
98 public void modifyText(ModifyEvent e) {
99 listener.valueChanged(text.getText());
108 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
110 protected Control createDialogArea(Composite parent) {
111 Composite composite = (Composite) super.createDialogArea(parent);
112 ((GridLayout) composite.getLayout()).numColumns = 3;
115 PlatformUI.getWorkbench().getHelpSystem().setHelp(composite,
116 ContextIds.PREF_BROWSER_EXTERNAL_EDIT);
118 PlatformUI.getWorkbench().getHelpSystem().setHelp(composite,
119 ContextIds.PREF_BROWSER_EXTERNAL_ADD);
121 SWTUtil.createLabel(composite, WebBrowserUIPlugin.getResource("%name"));
122 browserNameTextfield = createText(composite, browser.getName(),
123 new StringModifyListener() {
124 public void valueChanged(String s) {
130 new Label(composite, SWT.NONE);
132 SWTUtil.createLabel(composite, WebBrowserUIPlugin
133 .getResource("%location"));
134 browserLocationTextfield = createText(composite, browser.getLocation(),
135 new StringModifyListener() {
136 public void valueChanged(String s) {
137 browser.setLocation(s);
142 browseButton = SWTUtil.createButton(composite, WebBrowserUIPlugin
143 .getResource("%browse"));
144 browseButton.addSelectionListener(new SelectionAdapter() {
145 public void widgetSelected(SelectionEvent e) {
146 FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
148 .setText(WebBrowserUIPlugin
149 .getResource("%browseMessage"));
151 String fname = browserLocationTextfield.getText();
153 dialog.setFileName(fname);
154 fname = dialog.open();
157 browserLocationTextfield.setText(fname);
161 SWTUtil.createLabel(composite, WebBrowserUIPlugin
162 .getResource("%parameters"));
163 browserParametersTextfield = createText(composite, browser
164 .getParameters(), new StringModifyListener() {
165 public void valueChanged(String s) {
166 browser.setParameters(s);
170 new Label(composite, SWT.NONE);
172 new Label(composite, SWT.NONE);
173 Label urlLabel = new Label(composite, SWT.NONE);
174 urlLabel.setText(WebBrowserUIPlugin.getResource("%parametersMessage",
175 WebBrowserPreference.URL_PARAMETER));
183 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
185 protected void okPressed() {
186 // do simple field validation to at least ensure target directory
187 // entered is valid pathname
189 File file = new File(browser.getLocation());
190 if (!file.isFile()) {
191 WebBrowserUtil.openError(WebBrowserUIPlugin
192 .getResource("%locationInvalid"));
195 } catch (Exception e) {
196 WebBrowserUtil.openError(WebBrowserUIPlugin
197 .getResource("%locationInvalid"));
205 private void setOKButtonEnabled(boolean curIsEnabled) {
206 if (okButton == null)
207 okButton = getButton(IDialogConstants.OK_ID);
209 if (okButton != null)
210 okButton.setEnabled(curIsEnabled);
213 protected Control createButtonBar(Composite parent) {
214 Control buttonControl = super.createButtonBar(parent);
216 return buttonControl;
219 protected void validateFields() {
220 boolean valid = true;
222 String name = browserNameTextfield.getText();
223 if (name == null || name.trim().length() < 1)
226 String location = browserLocationTextfield.getText();
227 if (location == null || location.trim().length() < 1)
230 setOKButtonEnabled(valid);