Author: yradtsevich
Date: 2011-11-04 06:30:44 -0400 (Fri, 04 Nov 2011)
New Revision: 36170
Added:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/EditDevicesDialog.java
Modified:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/META-INF/MANIFEST.MF
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ManageDevicesDialog.java
Log:
https://issues.jboss.org/browse/JBIDE-9539 : Browsersim app for testing mobile/desktop web
apps
- added EditDevicesDialog
- made some usability improvements
Modified:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/META-INF/MANIFEST.MF
===================================================================
---
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/META-INF/MANIFEST.MF 2011-11-04
01:43:51 UTC (rev 36169)
+++
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/META-INF/MANIFEST.MF 2011-11-04
10:30:44 UTC (rev 36170)
@@ -5,5 +5,6 @@
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.eclipse.swt;bundle-version="3.7.0",
- org.jboss.tools.browsersim.webkit;bundle-version="1.0.0"
+ org.jboss.tools.browsersim.webkit;bundle-version="1.0.0",
+ org.eclipse.core.runtime;bundle-version="3.7.0"
Export-Package: org.jboss.tools.browsersim
Added:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/EditDevicesDialog.java
===================================================================
---
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/EditDevicesDialog.java
(rev 0)
+++
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/EditDevicesDialog.java 2011-11-04
10:30:44 UTC (rev 36170)
@@ -0,0 +1,156 @@
+package org.jboss.tools.browsersim;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.FocusAdapter;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.VerifyEvent;
+import org.eclipse.swt.events.VerifyListener;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Dialog;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+public class EditDevicesDialog extends Dialog {
+ protected Object result;
+ protected Shell shell;
+ private Text textName;
+ private Text textWidth;
+ private Text textHeight;
+ private Text textUserAgent;
+
+ /**
+ * Create the dialog.
+ * @param parent
+ * @param style
+ */
+ public EditDevicesDialog(Shell parent, int style) {
+ super(parent, style);
+ setText("SWT Dialog");
+ }
+
+ /**
+ * Open the dialog.
+ * @return the result
+ */
+ public Object open() {
+ createContents();
+ shell.open();
+ shell.layout();
+ shell.setSize(shell.computeSize(300, SWT.DEFAULT));
+ Display display = getParent().getDisplay();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Create contents of the dialog.
+ */
+ private void createContents() {
+ shell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.MIN | SWT.MAX);
+ shell.setSize(450, 300);
+ shell.setText("Edit Device");
+ shell.setLayout(new GridLayout(2, false));
+
+ Label labelName = new Label(shell, SWT.NONE);
+ labelName.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ labelName.setText("Name:");
+
+ textName = new Text(shell, SWT.BORDER);
+ textName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
+ textName.addFocusListener(new FocusGainedTextListener());
+
+ Label labelWidth = new Label(shell, SWT.NONE);
+ labelWidth.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ labelWidth.setText("Width:");
+
+ textWidth = new Text(shell, SWT.BORDER);
+ textWidth.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
+ textWidth.setTextLimit(4);
+ textWidth.addVerifyListener(new VerifyDigitsListener());
+ textWidth.addFocusListener(new FocusLostDigitsListener());
+ textWidth.addFocusListener(new FocusGainedTextListener());
+
+ Label labelHeight = new Label(shell, SWT.NONE);
+ labelHeight.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ labelHeight.setText("Height:");
+
+ textHeight = new Text(shell, SWT.BORDER);
+ textHeight.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
+ textHeight.setTextLimit(4);
+ textHeight.addVerifyListener(new VerifyDigitsListener());
+ textHeight.addFocusListener(new FocusLostDigitsListener());
+ textHeight.addFocusListener(new FocusGainedTextListener());
+
+ Label labelUseragent = new Label(shell, SWT.NONE);
+ labelUseragent.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ labelUseragent.setText("User-Agent:");
+
+ textUserAgent = new Text(shell, SWT.BORDER);
+ textUserAgent.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
+ textUserAgent.addFocusListener(new FocusGainedTextListener());
+
+ Composite composite = new Composite(shell, SWT.NONE);
+ composite.setLayout(new FillLayout(SWT.HORIZONTAL));
+ composite.setLayoutData(new GridData(SWT.RIGHT, SWT.BOTTOM, true, true, 2, 1));
+
+ Button buttonOk = new Button(composite, SWT.NONE);
+ buttonOk.setText("OK");
+ buttonOk.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ result = new Device(textName.getText(), Integer.valueOf(textWidth.getText()),
+ Integer.valueOf(textHeight.getText()), textUserAgent.getText());
+ shell.close();
+ }
+ });
+ shell.setDefaultButton(buttonOk);
+
+ Button buttonCancel = new Button(composite, SWT.NONE);
+ buttonCancel.setText("Cancel");
+ buttonCancel.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ result = null;
+ shell.close();
+ }
+ });
+ }
+}
+
+final class VerifyDigitsListener implements VerifyListener {
+ public void verifyText(VerifyEvent e) {
+ for (char c : e.text.toCharArray()) {
+ if (!('0' <= c && c <= '9')) {
+ e.doit = false;
+ return;
+ }
+ }
+ }
+}
+
+final class FocusLostDigitsListener extends FocusAdapter {
+ public void focusLost(FocusEvent e) {
+ Text text = ((Text) e.widget);
+ if (text.getText().trim().isEmpty()) {
+ text.setText("0");
+ }
+ }
+}
+
+final class FocusGainedTextListener extends FocusAdapter {
+ public void focusGained(FocusEvent e) {
+ Text text = ((Text) e.widget);
+ text.setSelection(0, text.getText().length());
+ }
+}
Modified:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ManageDevicesDialog.java
===================================================================
---
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ManageDevicesDialog.java 2011-11-04
01:43:51 UTC (rev 36169)
+++
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ManageDevicesDialog.java 2011-11-04
10:30:44 UTC (rev 36170)
@@ -10,6 +10,9 @@
******************************************************************************/
package org.jboss.tools.browsersim;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
@@ -20,6 +23,7 @@
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
/**
* @author Yahor Radtsevich (yradtsevich)
@@ -28,8 +32,6 @@
protected Object result;
protected Shell shell;
-
-
private Table table;
/**
@@ -67,7 +69,7 @@
shell.setSize(450, 300);
shell.setText(getText());
shell.setLayout(new GridLayout(2, false));
-
+
table = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION);
table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
table.setHeaderVisible(true);
@@ -95,6 +97,16 @@
Button buttonAdd = new Button(compositeControls, SWT.NONE);
buttonAdd.setText("Add");
+ buttonAdd.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ Device newDevice = (Device) new EditDevicesDialog(shell, SWT.APPLICATION_MODAL |
SWT.SHELL_TRIM).open();
+ if (newDevice != null) {
+ DevicesManager.getInstance().getDevices().add(newDevice);
+ updateDevices();
+ }
+ }
+ });
Button buttonEdit = new Button(compositeControls, SWT.NONE);
buttonEdit.setText("Edit");
@@ -111,9 +123,25 @@
Button buttonOk = new Button(compositeOkCancel, SWT.NONE);
buttonOk.setText("OK");
+ shell.setDefaultButton(buttonOk);
Button buttonCancel = new Button(compositeOkCancel, SWT.NONE);
buttonCancel.setText("Cancel");
+ buttonCancel.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ shell.close();
+ }
+ });
+
+ updateDevices();
+ updateDevices();
}
-
+
+ public void updateDevices() {
+ table.removeAll();
+ for (Device device : DevicesManager.getInstance().getDevices()) {
+ TableItem tableItem = new TableItem(table, SWT.NONE);
+ tableItem.setText(new String[] {device.getName(), String.valueOf(device.getWidth()),
String.valueOf(device.getHeight()), device.getUserAgent()});
+ }
+ }
}