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;
37 public class ExternalBrowserDialog extends Dialog {
38 protected IExternalWebBrowserWorkingCopy browser;
39 protected boolean isEdit;
40 protected Button newPageCheckbox;
41 protected Button clearHistoryCheckbox;
42 protected Button browseButton;
43 protected Text browserNameTextfield;
44 protected Text browserLocationTextfield;
45 protected Text browserParametersTextfield;
46 private Button okButton;
48 interface StringModifyListener {
49 public void valueChanged(String s);
55 public ExternalBrowserDialog(Shell parentShell, IExternalWebBrowserWorkingCopy browser) {
57 this.browser = browser;
61 public ExternalBrowserDialog(Shell parentShell) {
63 browser = BrowserManager.getInstance().createExternalWebBrowser();
67 protected void configureShell(Shell shell) {
68 super.configureShell(shell);
71 shell.setText(WebBrowserUIPlugin.getResource("%editExternalBrowser"));
73 shell.setText(WebBrowserUIPlugin.getResource("%createBrowser"));
76 protected Text createText(Composite comp, String txt, final StringModifyListener listener) {
77 final Text text = new Text(comp, SWT.BORDER);
80 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
82 text.setLayoutData(data);
84 text.addModifyListener(new ModifyListener() {
85 public void modifyText(ModifyEvent e) {
86 listener.valueChanged(text.getText());
93 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
95 protected Control createDialogArea(Composite parent) {
96 Composite composite = (Composite) super.createDialogArea(parent);
97 ((GridLayout)composite.getLayout()).numColumns = 3;
100 PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, ContextIds.PREF_BROWSER_EXTERNAL_EDIT);
102 PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, ContextIds.PREF_BROWSER_EXTERNAL_ADD);
104 SWTUtil.createLabel(composite, WebBrowserUIPlugin.getResource("%name"));
105 browserNameTextfield = createText(composite, browser.getName(), new StringModifyListener() {
106 public void valueChanged(String s) {
112 new Label(composite, SWT.NONE);
114 SWTUtil.createLabel(composite, WebBrowserUIPlugin.getResource("%location"));
115 browserLocationTextfield = createText(composite, browser.getLocation(), new StringModifyListener() {
116 public void valueChanged(String s) {
117 browser.setLocation(s);
122 browseButton = SWTUtil.createButton(composite, WebBrowserUIPlugin.getResource("%browse"));
123 browseButton.addSelectionListener(new SelectionAdapter() {
124 public void widgetSelected(SelectionEvent e) {
125 FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
126 dialog.setText(WebBrowserUIPlugin.getResource("%browseMessage"));
128 String fname = browserLocationTextfield.getText();
130 dialog.setFileName(fname);
131 fname = dialog.open();
134 browserLocationTextfield.setText(fname);
138 SWTUtil.createLabel(composite, WebBrowserUIPlugin.getResource("%parameters"));
139 browserParametersTextfield = createText(composite, browser.getParameters(), new StringModifyListener() {
140 public void valueChanged(String s) {
141 browser.setParameters(s);
145 new Label(composite, SWT.NONE);
147 new Label(composite, SWT.NONE);
148 Label urlLabel = new Label(composite, SWT.NONE);
149 urlLabel.setText(WebBrowserUIPlugin.getResource("%parametersMessage", WebBrowserPreference.URL_PARAMETER));
156 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
158 protected void okPressed() {
159 // do simple field validation to at least ensure target directory entered is valid pathname
161 File file = new File(browser.getLocation());
163 WebBrowserUtil.openError(WebBrowserUIPlugin.getResource("%locationInvalid"));
168 WebBrowserUtil.openError(WebBrowserUIPlugin.getResource("%locationInvalid"));
176 private void setOKButtonEnabled(boolean curIsEnabled) {
177 if (okButton == null)
178 okButton = getButton(IDialogConstants.OK_ID);
180 if (okButton != null)
181 okButton.setEnabled(curIsEnabled);
184 protected Control createButtonBar(Composite parent) {
185 Control buttonControl = super.createButtonBar(parent);
187 return buttonControl;
190 protected void validateFields() {
191 boolean valid = true;
193 String name = browserNameTextfield.getText();
194 if (name == null || name.trim().length() < 1)
197 String location = browserLocationTextfield.getText();
198 if (location == null || location.trim().length() < 1)
201 setOKButtonEnabled(valid);