JBoss Tools SVN: r36410 - in workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim: ui and 1 other directory.
by jbosstools-commits@lists.jboss.org
Author: yradtsevich
Date: 2011-11-17 14:13:02 -0500 (Thu, 17 Nov 2011)
New Revision: 36410
Added:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/DevicesListHolder.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/DevicesListStorage.java
Removed:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/DevicesManager.java
Modified:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/BrowserSim.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/ManageDevicesDialog.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/Messages.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/messages.properties
Log:
https://issues.jboss.org/browse/JBIDE-9539 : Browsersim app for testing mobile/desktop web apps
- refactored source
- added missing WebKit handling
Copied: workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/DevicesListHolder.java (from rev 36409, workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/DevicesManager.java)
===================================================================
--- workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/DevicesListHolder.java (rev 0)
+++ workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/DevicesListHolder.java 2011-11-17 19:13:02 UTC (rev 36410)
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.browsersim.model;
+
+import java.util.Observable;
+
+
+/**
+ * @author Yahor Radtsevich (yradtsevich)
+ */
+public class DevicesListHolder extends Observable {
+ private static DevicesListHolder instance;
+ private DevicesList devicesList;
+
+ protected DevicesListHolder() {
+ }
+
+ public static DevicesListHolder getInstance() {
+ if (instance == null) {
+ instance = new DevicesListHolder();
+ }
+ return instance;
+ }
+
+ public DevicesList getDevicesList() {
+ return devicesList;
+ }
+
+ public void setDevicesList(DevicesList devicesList) {
+ if (this.devicesList != devicesList) {
+ this.devicesList = devicesList;
+ setChanged();
+ }
+ }
+}
Added: workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/DevicesListStorage.java
===================================================================
--- workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/DevicesListStorage.java (rev 0)
+++ workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/DevicesListStorage.java 2011-11-17 19:13:02 UTC (rev 36410)
@@ -0,0 +1,170 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.browsersim.model;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.jboss.tools.browsersim.util.ResourcesUtil;
+
+/**
+ * @author Yahor Radtsevich (yradtsevich)
+ */
+public class DevicesListStorage {
+
+ private static final String DEFAULT_PREFERENCES_RESOURCE = "/org/jboss/tools/browsersim/resources/config/devices.cfg";
+ private static final String USER_PREFERENCES_FILE = "devices.cfg";
+ private static final String USER_PREFERENCES_FOLDER = "org.jboss.tools.browsersim";
+
+ public static void saveUserDefinedDevicesList(DevicesList devicesList) {
+ File configFolder = new File(USER_PREFERENCES_FOLDER);
+ configFolder.mkdir();
+ File configFile = new File(configFolder, USER_PREFERENCES_FILE);
+
+ try {
+ saveDevicesList(devicesList, configFile);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static DevicesList loadUserDefinedDevicesList() {
+ File customConfigFile = new File(USER_PREFERENCES_FOLDER + '/' + USER_PREFERENCES_FILE);
+ DevicesList devicesList = null;
+ if (customConfigFile.exists()) {
+ try {
+ devicesList = loadDevicesList(customConfigFile);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ return devicesList;
+ }
+
+ public static DevicesList loadDefaultDevicesList() {
+ DevicesList devicesList;
+ try {
+ devicesList = loadDevicesList(ResourcesUtil.getResourceAsStream(
+ DEFAULT_PREFERENCES_RESOURCE));
+ } catch (IOException e) {
+ e.printStackTrace();
+ devicesList = new DevicesList(new ArrayList<Device>(), 0);
+ }
+
+ return devicesList;
+ }
+
+ private static void saveDevicesList(DevicesList devicesList, File file) throws IOException {
+ BufferedWriter writer = new BufferedWriter(new FileWriter(file));
+
+ writer.write(String.valueOf(devicesList.getSelectedDeviceIndex()));
+ writer.write('\n');
+
+ for (Device device : devicesList.getDevices()) {
+ writer.write( encode(device.getName() ));
+ writer.write('\t');
+ writer.write(encode( String.valueOf(device.getWidth()) ));
+ writer.write('\t');
+ writer.write(encode( String.valueOf(device.getHeight()) ));
+ writer.write('\t');
+ writer.write( encode(device.getUserAgent() ));
+ writer.write('\n');
+ }
+
+ writer.close();
+ }
+
+ private static DevicesList loadDevicesList(File file) throws IOException {
+ InputStream inputStream = new FileInputStream(file);
+ return loadDevicesList(inputStream);
+ }
+
+ private static DevicesList loadDevicesList(InputStream inputStream) throws IOException {
+ BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
+
+ String nextLine = reader.readLine();
+ int selectedDeviceIndex = 0;
+ if (nextLine != null) {
+ selectedDeviceIndex = Integer.parseInt(nextLine);
+ }
+ Pattern devicePattern = Pattern.compile("^(.*)\\t([0-9]*)\\t([0-9]*)\\t(.*)$");
+
+ List<Device> devices = new ArrayList<Device>();
+ while ((nextLine = reader.readLine()) != null) {
+ Matcher deviceMatcher = devicePattern.matcher(nextLine);
+ if (deviceMatcher.matches()) {
+ devices.add(new Device(
+ decode(deviceMatcher.group(1)),
+ Integer.parseInt(deviceMatcher.group(2)),
+ Integer.parseInt(deviceMatcher.group(3)),
+ decode(deviceMatcher.group(4))
+ ));
+ }
+ }
+
+ reader.close();
+
+ return new DevicesList(devices, selectedDeviceIndex);
+ }
+
+ private static String encode(String string) {
+ return string.replace("\\", "\\\\").replace("\n", "\\n").replace("\t", "\\t");
+ }
+
+ private static String decode(String string) {
+ StringBuilder result = new StringBuilder();
+
+ int i = 0;
+ while (i < string.length() - 1) {
+ char c0 = string.charAt(i);
+ if (c0 == '\\') {
+ char c1 = string.charAt(i + 1);
+ switch (c1) {
+ case '\\':
+ result.append('\\');
+ i++;
+ break;
+ case 'n':
+ result.append('\n');
+ i++;
+ break;
+ case 't':
+ result.append('\t');
+ i++;
+ break;
+ default:
+ result.append(c0);
+ break;
+ }
+ } else {
+ result.append(c0);
+ }
+ i++;
+ }
+
+ if (i < string.length()) {
+ result.append(string.charAt(i));
+ }
+
+ return result.toString();
+ }
+}
Deleted: workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/DevicesManager.java
===================================================================
--- workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/DevicesManager.java 2011-11-17 16:27:48 UTC (rev 36409)
+++ workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/DevicesManager.java 2011-11-17 19:13:02 UTC (rev 36410)
@@ -1,158 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007-2011 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributor:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.browsersim.model;
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Observable;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-
-/**
- * @author Yahor Radtsevich (yradtsevich)
- */
-public class DevicesManager extends Observable {
- private static DevicesManager instance;
- private DevicesList devicesList;
- public static final String IPHONE_OS_4_0_USER_AGENT = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7";
-
- protected DevicesManager() {
- }
-
- public static DevicesManager getInstance() {
- if (instance == null) {
- instance = new DevicesManager();
- }
- return instance;
- }
-
- public DevicesList getDevicesList() {
- return devicesList;
- }
-
- public void setDevicesList(DevicesList devicesList) {
- if (this.devicesList != devicesList) {
- this.devicesList = devicesList;
- setChanged();
- }
- }
-
-// List<Device> devices = new ArrayList<Device>();
-// devices.add(new Device("Apple iPhone 3", 320, 480, IPHONE_OS_4_0_USER_AGENT));
-// devices.add(new Device("Apple iPhone 4", 640, 960, IPHONE_OS_4_0_USER_AGENT));
-// devices.add(new Device("BlackBerry Bold Touch 9900", 640, 480, "Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en-US) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.246 Mobile Safari/534.1+"));
-// devices.add(new Device("Samsung Galaxy S II", 640, 800, "Mozilla/5.0 (Linux; U; Android 2.3; en-us; GT-I9100 Build/GRH78) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"));
-
-
- public static String encode(String string) {
- return string.replace("\\", "\\\\").replace("\n", "\\n").replace("\t", "\\t");
- }
-
- public static String decode(String string) {
- StringBuilder result = new StringBuilder();
-
- int i = 0;
- while (i < string.length() - 1) {
- char c0 = string.charAt(i);
- if (c0 == '\\') {
- char c1 = string.charAt(i + 1);
- switch (c1) {
- case '\\':
- result.append('\\');
- i++;
- break;
- case 'n':
- result.append('\n');
- i++;
- break;
- case 't':
- result.append('\t');
- i++;
- break;
- default:
- result.append(c0);
- break;
- }
- } else {
- result.append(c0);
- }
- i++;
- }
-
- if (i < string.length()) {
- result.append(string.charAt(i));
- }
-
- return result.toString();
- }
-
- public static void saveDevicesList(DevicesList devicesList, File file) throws IOException {
- BufferedWriter writer = new BufferedWriter(new FileWriter(file));
-
- writer.write(String.valueOf(devicesList.getSelectedDeviceIndex()));
- writer.write('\n');
-
- for (Device device : devicesList.getDevices()) {
- writer.write( encode(device.getName() ));
- writer.write('\t');
- writer.write(encode( String.valueOf(device.getWidth()) ));
- writer.write('\t');
- writer.write(encode( String.valueOf(device.getHeight()) ));
- writer.write('\t');
- writer.write( encode(device.getUserAgent() ));
- writer.write('\n');
- }
-
- writer.close();
- }
-
- public static DevicesList loadDevicesList(File file) throws IOException {
- InputStream inputStream = new FileInputStream(file);
- return loadDevicesList(inputStream);
- }
-
- public static DevicesList loadDevicesList(InputStream inputStream) throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
-
- String nextLine = reader.readLine();
- int selectedDeviceIndex = 0;
- if (nextLine != null) {
- selectedDeviceIndex = Integer.parseInt(nextLine);
- }
- Pattern devicePattern = Pattern.compile("^(.*)\\t([0-9]*)\\t([0-9]*)\\t(.*)$");
-
- List<Device> devices = new ArrayList<Device>();
- while ((nextLine = reader.readLine()) != null) {
- Matcher deviceMatcher = devicePattern.matcher(nextLine);
- if (deviceMatcher.matches()) {
- devices.add(new Device(
- decode(deviceMatcher.group(1)),
- Integer.parseInt(deviceMatcher.group(2)),
- Integer.parseInt(deviceMatcher.group(3)),
- decode(deviceMatcher.group(4))
- ));
- }
- }
-
- reader.close();
-
- return new DevicesList(devices, selectedDeviceIndex);
- }
-}
Modified: workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/BrowserSim.java
===================================================================
--- workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/BrowserSim.java 2011-11-17 16:27:48 UTC (rev 36409)
+++ workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/BrowserSim.java 2011-11-17 19:13:02 UTC (rev 36410)
@@ -41,6 +41,7 @@
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
@@ -48,7 +49,8 @@
import org.eclipse.swt.widgets.ToolItem;
import org.jboss.tools.browsersim.model.Device;
import org.jboss.tools.browsersim.model.DevicesList;
-import org.jboss.tools.browsersim.model.DevicesManager;
+import org.jboss.tools.browsersim.model.DevicesListHolder;
+import org.jboss.tools.browsersim.model.DevicesListStorage;
import org.jboss.tools.browsersim.util.ResourcesUtil;
import org.jboss.tools.browsersim.webkit.AbstractWebKitBrowser;
import org.jboss.tools.browsersim.webkit.WebKitBrowserFactory;
@@ -66,7 +68,7 @@
private ProgressBar progressBar;
private String initialUrl;
private Menu devicesMenu;
- private DevicesManager devicesManager;
+ private DevicesListHolder devicesManager;
public static void main(String[] args) {
String initialUrl;
@@ -95,13 +97,8 @@
shell = new Shell(display);
shell.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
- try {
- File configFolder = new File(this.getClass().getPackage().getName());
- configFolder.mkdir();
- DevicesManager.saveDevicesList(devicesManager.getDevicesList(),
- new File(configFolder, "devices.cfg"));
- } catch (IOException ex) {
- ex.printStackTrace();
+ if (devicesManager != null) {
+ DevicesListStorage.saveUserDefinedDevicesList(devicesManager.getDevicesList());
}
}
});
@@ -135,6 +132,12 @@
browser = WebKitBrowserFactory.createWebKitBrowser(shell, SWT.NONE);
} catch (SWTError e) {
System.out.println(Messages.BrowserSim_COULD_NOT_INSTANTIATE_BROWSER + e.getMessage());
+
+ MessageBox messageBox = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
+ messageBox.setText("Error");
+ messageBox.setMessage(Messages.BrowserSim_COULD_NOT_INSTANTIATE_BROWSER + e.getMessage());
+ messageBox.open();
+
display.dispose();
return;
}
@@ -189,7 +192,7 @@
}
});
- DevicesList devicesList = DevicesManager.getInstance().getDevicesList();
+ DevicesList devicesList = DevicesListHolder.getInstance().getDevicesList();
if (devicesList != null && devicesList.getDevices() != null
&& devicesList.getSelectedDeviceIndex() < devicesList.getDevices().size()) {
setDevice(devicesList.getDevices().get(devicesList.getSelectedDeviceIndex()));
@@ -284,10 +287,10 @@
});
devicesMenu = createDropDownMenu(appMenuBar, Messages.BrowserSim_DEVICES);
- devicesManager = DevicesManager.getInstance();
+ devicesManager = DevicesListHolder.getInstance();
devicesManager.addObserver(new Observer() {
public void update(Observable o, Object arg) {
- DevicesManager devicesManager = (DevicesManager) o;
+ DevicesListHolder devicesManager = (DevicesListHolder) o;
DevicesList devicesList = devicesManager.getDevicesList();
setDevicesListForMenu(devicesList);
setDevice(devicesList.getDevices().get(devicesList.getSelectedDeviceIndex()));
@@ -299,18 +302,11 @@
}
});
- DevicesList devicesList;
- try {
- File customConfigFile = new File(this.getClass().getPackage().getName() + "/devices.cfg");
- if (customConfigFile.exists()) {
- devicesList = DevicesManager.loadDevicesList(customConfigFile);
- } else {
- devicesList = DevicesManager.loadDevicesList(ResourcesUtil.getResourceAsStream(
- "/org/jboss/tools/browsersim/resources/config/devices.cfg"));
- }
- } catch (IOException e) {
- devicesList = new DevicesList(new ArrayList<Device>(), 0);
+ DevicesList devicesList = DevicesListStorage.loadUserDefinedDevicesList();
+ if (devicesList == null) {
+ devicesList = DevicesListStorage.loadDefaultDevicesList();
}
+
devicesManager.setDevicesList(devicesList);
devicesManager.notifyObservers();
Modified: workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/ManageDevicesDialog.java
===================================================================
--- workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/ManageDevicesDialog.java 2011-11-17 16:27:48 UTC (rev 36409)
+++ workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/ManageDevicesDialog.java 2011-11-17 19:13:02 UTC (rev 36410)
@@ -30,7 +30,7 @@
import org.eclipse.swt.widgets.TableItem;
import org.jboss.tools.browsersim.model.Device;
import org.jboss.tools.browsersim.model.DevicesList;
-import org.jboss.tools.browsersim.model.DevicesManager;
+import org.jboss.tools.browsersim.model.DevicesListStorage;
import org.jboss.tools.browsersim.util.ResourcesUtil;
/**
@@ -147,7 +147,6 @@
buttonRemove.setText(Messages.ManageDevicesDialog_REMOVE);
buttonRemove.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
- System.out.println(devices.size());
if (devices.size() > 1) {
devices.remove(selectedDeviceIndex);
if (selectedDeviceIndex >= devices.size()) {
@@ -159,7 +158,7 @@
});
Button buttonReset = new Button(compositeControls, SWT.NONE);
- buttonReset.setText(Messages.ManageDevicesDialog_RESET);
+ buttonReset.setText(Messages.ManageDevicesDialog_REVERT_ALL);
buttonReset.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
@@ -175,16 +174,10 @@
buttonLoadDefaults.setText(Messages.ManageDevicesDialog_LOAD_DEFAULTS);
buttonLoadDefaults.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
- DevicesList defaultDevicesList;
- try {
- defaultDevicesList = DevicesManager.loadDevicesList(ResourcesUtil.getResourceAsStream(
- "/org/jboss/tools/browsersim/resources/config/devices.cfg"));
- devices = defaultDevicesList.getDevices();
- selectedDeviceIndex = defaultDevicesList.getSelectedDeviceIndex();
- updateDevices();
- } catch (IOException e1) {
- e1.printStackTrace();
- }
+ DevicesList defaultDevicesList = DevicesListStorage.loadDefaultDevicesList();
+ devices = defaultDevicesList.getDevices();
+ selectedDeviceIndex = defaultDevicesList.getSelectedDeviceIndex();
+ updateDevices();
}
});
Modified: workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/Messages.java
===================================================================
--- workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/Messages.java 2011-11-17 16:27:48 UTC (rev 36409)
+++ workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/Messages.java 2011-11-17 19:13:02 UTC (rev 36410)
@@ -21,6 +21,7 @@
public static String BrowserSim_BROWSER_SIM;
public static String BrowserSim_COULD_NOT_INSTANTIATE_BROWSER;
public static String BrowserSim_DEVICES;
+ public static String BrowserSim_ERROR;
public static String BrowserSim_EXIT;
public static String BrowserSim_FILE;
public static String BrowserSim_MORE;
@@ -42,7 +43,7 @@
public static String ManageDevicesDialog_NEW_USER_AGENT;
public static String ManageDevicesDialog_OK;
public static String ManageDevicesDialog_REMOVE;
- public static String ManageDevicesDialog_RESET;
+ public static String ManageDevicesDialog_REVERT_ALL;
public static String ManageDevicesDialog_LOAD_DEFAULTS;
public static String ManageDevicesDialog_USER_AGENT;
public static String ManageDevicesDialog_WIDTH;
Modified: workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/messages.properties
===================================================================
--- workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/messages.properties 2011-11-17 16:27:48 UTC (rev 36409)
+++ workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/messages.properties 2011-11-17 19:13:02 UTC (rev 36410)
@@ -2,6 +2,7 @@
BrowserSim_BROWSER_SIM=BrowserSim
BrowserSim_COULD_NOT_INSTANTIATE_BROWSER=Could not instantiate Browser:
BrowserSim_DEVICES=Devices
+BrowserSim_ERROR=Error
BrowserSim_EXIT=Exit
BrowserSim_FILE=File
BrowserSim_MORE=More...
@@ -23,7 +24,7 @@
ManageDevicesDialog_NEW_USER_AGENT=New User-Agent
ManageDevicesDialog_OK=OK
ManageDevicesDialog_REMOVE=Remove
-ManageDevicesDialog_RESET=Reset
+ManageDevicesDialog_REVERT_ALL=Revert All
ManageDevicesDialog_LOAD_DEFAULTS=Load Defaults
ManageDevicesDialog_USER_AGENT=User-Agent
ManageDevicesDialog_WIDTH=Width
14 years, 5 months
JBoss Tools SVN: r36409 - in workspace/yradtsevich/browsersim/swt-webkit-browsersim: org.jboss.tools.browsersim/META-INF and 8 other directories.
by jbosstools-commits@lists.jboss.org
Author: yradtsevich
Date: 2011-11-17 11:27:48 -0500 (Thu, 17 Nov 2011)
New Revision: 36409
Added:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/org.jboss.tools.browsersim.ui/
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/org.jboss.tools.browsersim.ui/devices.cfg
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/Device.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/DevicesList.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/DevicesManager.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/BrowserSim.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/EditDeviceDialog.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/ManageDevicesDialog.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/Messages.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/messages.properties
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/util/
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/util/NLS.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/util/ResourcesUtil.java
Removed:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/BrowserSim.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/Device.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/DevicesList.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/DevicesManager.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/EditDeviceDialog.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/IWebViewProxy.java
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/Messages.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/NLS.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/messages.properties
Modified:
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim.eclipse/src/org/jboss/tools/browsersim/eclipse/util/BrowserSimLauncher.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim.webkit/src/org/jboss/tools/browsersim/webkit/WebKitBrowserFactory.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim.webkit/src/org/jboss/tools/browsersim/webkit/internal/WebKitBrowser_webkit_cocoa_macos.java
workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/META-INF/MANIFEST.MF
Log:
https://issues.jboss.org/browse/JBIDE-9539 : Browsersim app for testing mobile/desktop web apps
- added automatic saving of settings on window disposing
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-17 14:54:19 UTC (rev 36408)
+++ workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/META-INF/MANIFEST.MF 2011-11-17 16:27:48 UTC (rev 36409)
@@ -6,4 +6,4 @@
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"
-Export-Package: org.jboss.tools.browsersim
+Export-Package: org.jboss.tools.browsersim.ui
Added: workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/org.jboss.tools.browsersim.ui/devices.cfg
===================================================================
--- workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/org.jboss.tools.browsersim.ui/devices.cfg (rev 0)
+++ workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/org.jboss.tools.browsersim.ui/devices.cfg 2011-11-17 16:27:48 UTC (rev 36409)
@@ -0,0 +1,4 @@
+0
+Apple iPhone 3 320 480 Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7
+Apple iPhone 4 640 960 Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7
+Samsung Galaxy S II 640 800 Mozilla/5.0 (Linux; U; Android 2.3; en-us; GT-I9100 Build/GRH78) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
Deleted: workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/BrowserSim.java
===================================================================
--- workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/BrowserSim.java 2011-11-17 14:54:19 UTC (rev 36408)
+++ workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/BrowserSim.java 2011-11-17 16:27:48 UTC (rev 36409)
@@ -1,400 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007-2011 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributor:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.browsersim;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.Observable;
-import java.util.Observer;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTError;
-import org.eclipse.swt.browser.LocationEvent;
-import org.eclipse.swt.browser.LocationListener;
-import org.eclipse.swt.browser.ProgressEvent;
-import org.eclipse.swt.browser.ProgressListener;
-import org.eclipse.swt.browser.StatusTextEvent;
-import org.eclipse.swt.browser.StatusTextListener;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Menu;
-import org.eclipse.swt.widgets.MenuItem;
-import org.eclipse.swt.widgets.ProgressBar;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.swt.widgets.ToolBar;
-import org.eclipse.swt.widgets.ToolItem;
-import org.jboss.tools.browsersim.webkit.AbstractWebKitBrowser;
-import org.jboss.tools.browsersim.webkit.WebKitBrowserFactory;
-
-/**
- * @author Yahor Radtsevich (yradtsevich)
- */
-public class BrowserSim implements Runnable {
- private static final String DEFAULT_URL = "http://www.w3schools.com/js/tryit_view.asp?filename=try_nav_useragent"; //$NON-NLS-1$
- private AbstractWebKitBrowser browser;
- private Display display;
- private Shell shell;
- private Text locationText;
- private Label statusLabel;
- private ProgressBar progressBar;
- private String initialUrl;
- private Menu devicesMenu;
- private DevicesManager devicesManager;
-
- public static void main(String[] args) {
-
-
-
-
- String initialUrl;
- if (args.length > 0) {
- String lastArg = args[args.length - 1];
- try {
- new URI(lastArg); // validate URL
- initialUrl = lastArg;
- } catch (URISyntaxException e) {
- initialUrl = DEFAULT_URL;
- }
- } else {
- initialUrl = DEFAULT_URL;
- }
-
- new BrowserSim(new Display(), initialUrl).run();
- }
-
- public BrowserSim(Display display, String initialUrl) {
- this.display = display;
- this.initialUrl = initialUrl;
- }
-
- @Override
- public void run() {
- shell = new Shell(display);
- shell.setText(Messages.BrowserSim_BROWSER_SIM);
- GridLayout gridLayout = new GridLayout();
- gridLayout.numColumns = 3;
- shell.setLayout(gridLayout);
- Menu appMenuBar = display.getMenuBar();
- if (appMenuBar == null) {
- appMenuBar = new Menu(shell, SWT.BAR);
- shell.setMenuBar(appMenuBar);
- }
-
- ToolBar toolbar = createControlBar();
- GridData data = new GridData();
- data.horizontalSpan = 3;
- toolbar.setLayoutData(data);
-
- Label labelAddress = new Label(shell, SWT.NONE);
- labelAddress.setText(Messages.BrowserSim_ADDRESS);
-
- locationText = new Text(shell, SWT.BORDER);
- data = new GridData();
- data.horizontalAlignment = GridData.FILL;
- data.horizontalSpan = 2;
- data.grabExcessHorizontalSpace = true;
- data.widthHint = 0;
- locationText.setLayoutData(data);
-
- try {
- browser = WebKitBrowserFactory.createWebKitBrowser(shell, SWT.NONE);
- } catch (SWTError e) {
- System.out.println(Messages.BrowserSim_COULD_NOT_INSTANTIATE_BROWSER + e.getMessage());
- display.dispose();
- return;
- }
-
- data = new GridData();
- data.horizontalAlignment = GridData.FILL;
- data.verticalAlignment = GridData.FILL;
- data.horizontalSpan = 3;
- data.grabExcessHorizontalSpace = true;
- data.grabExcessVerticalSpace = true;
- browser.setLayoutData(data);
-
- statusLabel = new Label(shell, SWT.NONE);
- data = new GridData(GridData.FILL_HORIZONTAL);
- data.horizontalSpan = 2;
- data.widthHint = 0;
- statusLabel.setLayoutData(data);
-
- progressBar = new ProgressBar(shell, SWT.NONE);
- data = new GridData();
- data.horizontalAlignment = GridData.END;
- progressBar.setLayoutData(data);
-
- browser.addProgressListener(new ProgressListener() {
- public void changed(ProgressEvent event) {
- if (event.total == 0) return;
- int ratio = event.current * 100 / event.total;
- progressBar.setSelection(ratio);
- }
- public void completed(ProgressEvent event) {
- progressBar.setSelection(0);
- }
- });
- browser.addStatusTextListener(new StatusTextListener() {
- public void changed(StatusTextEvent event) {
- statusLabel.setText(event.text);
- }
- });
- browser.addLocationListener(new LocationListener() {
- public void changed(LocationEvent event) {
- if (event.top) locationText.setText(event.location);
- }
- public void changing(LocationEvent event) {
- }
- });
-
- fillMenuBar(appMenuBar);
-
- locationText.addListener(SWT.DefaultSelection, new Listener() {
- public void handleEvent(Event e) {
- browser.setUrl(locationText.getText());
- }
- });
-
- if (!DevicesManager.getInstance().getDevicesList().getDevices().isEmpty()) {
- setDevice(DevicesManager.getInstance().getDevicesList().getDevices().get(0));
- }
- shell.open();
- browser.setUrl(initialUrl);
-
- while (!shell.isDisposed()) {
- if (!display.readAndDispatch())
- display.sleep();
- }
- display.dispose();
- }
-
- public ToolBar createControlBar() {
- ToolBar toolbar = new ToolBar(shell, SWT.NONE);
- ToolItem itemBack = new ToolItem(toolbar, SWT.PUSH);
-// itemBack.setText("Back");
- itemBack.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event event) {
- browser.back();
- }
- });
-
- ToolItem itemForward = new ToolItem(toolbar, SWT.PUSH);
-// itemForward.setText("Forward");
- itemForward.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event event) {
- browser.forward();
- }
- });
-
- ToolItem itemStop = new ToolItem(toolbar, SWT.PUSH);
-// itemStop.setText("Stop");
- itemStop.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event event) {
- browser.stop();
- }
- });
-
- ToolItem itemRefresh = new ToolItem(toolbar, SWT.PUSH);
-// itemRefresh.setText("Refresh");
- itemRefresh.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event event) {
- browser.refresh();
- }
- });
-
- ToolItem itemGo = new ToolItem(toolbar, SWT.PUSH);
-// itemGo.setText("Go");
- itemGo.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event event) {
- browser.setUrl(locationText.getText());
- }
- });
-
- final Image imageBack = new Image(display, getResourceAsStream("/org/jboss/tools/browsersim/resources/icons/nav_backward.gif")); //$NON-NLS-1$
- final Image imageForward = new Image(display, getResourceAsStream("/org/jboss/tools/browsersim/resources/icons/nav_forward.gif")); //$NON-NLS-1$
- final Image imageStop = new Image(display, getResourceAsStream("/org/jboss/tools/browsersim/resources/icons/nav_stop.gif")); //$NON-NLS-1$
- final Image imageRefresh = new Image(display, getResourceAsStream("/org/jboss/tools/browsersim/resources/icons/nav_refresh.gif")); //$NON-NLS-1$
- final Image imageGo = new Image(display, getResourceAsStream("/org/jboss/tools/browsersim/resources/icons/nav_go.gif")); //$NON-NLS-1$
-
- itemBack.setImage(imageBack);
- itemForward.setImage(imageForward);
- itemStop.setImage(imageStop);
- itemRefresh.setImage(imageRefresh);
- itemGo.setImage(imageGo);
- shell.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- imageBack.dispose();
- imageForward.dispose();
- imageStop.dispose();
- imageRefresh.dispose();
- imageGo.dispose();
- }
- });
-
- itemForward.setImage(imageForward);
-
-
- return toolbar;
- }
-
- private InputStream getResourceAsStream(String name) {
- return this.getClass().getResourceAsStream(name);
- }
-
- private File getResourceAsFile(String name) {
- return new File(this.getClass().getResource(name).getFile());
- }
-
- public void fillMenuBar(Menu appMenuBar) {
- Menu file = createDropDownMenu(appMenuBar, Messages.BrowserSim_FILE);
- MenuItem exit = new MenuItem(file, SWT.PUSH);
- exit.setText(Messages.BrowserSim_EXIT);
- exit.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- display.dispose();
- };
- });
-
- devicesMenu = createDropDownMenu(appMenuBar, Messages.BrowserSim_DEVICES);
- devicesManager = DevicesManager.getInstance();
- devicesManager.addObserver(new Observer() {
- public void update(Observable o, Object arg) {
- DevicesManager devicesManager = (DevicesManager) o;
- DevicesList devicesList = devicesManager.getDevicesList();
- setDevicesListForMenu(devicesList);
- setDevice(devicesList.getDevices().get(devicesList.getSelectedDeviceIndex()));
- devicesList.addObserver(new Observer() {
- public void update(Observable o, Object arg) {
- setDevice(((DevicesList)o).getDevices().get(((DevicesList)o).getSelectedDeviceIndex()));
- }
- });
- }
- });
-
- DevicesList devicesList;
- try {
- devicesList = DevicesManager.loadDevicesList(getResourceAsStream(
- "/org/jboss/tools/browsersim/resources/config/devices.cfg"));
- } catch (IOException e) {
- devicesList = new DevicesList(new ArrayList<Device>(), 0);
- }
- devicesManager.setDevicesList(devicesList);
- devicesManager.notifyObservers();
-
- new MenuItem(devicesMenu, SWT.BAR);
- MenuItem manageDevicesMenuItem = new MenuItem(devicesMenu, SWT.PUSH);
- manageDevicesMenuItem.setText(Messages.BrowserSim_MORE);
- manageDevicesMenuItem.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- DevicesList newDevicesList = new ManageDevicesDialog(shell, SWT.APPLICATION_MODAL | SWT.SHELL_TRIM,
- devicesManager.getDevicesList()).open();
- if (newDevicesList != null) {
- devicesManager.setDevicesList(newDevicesList);
- devicesManager.notifyObservers();
- }
- }
- });
- }
-
- private void setDevicesListForMenu(DevicesList devicesList) {
- for (MenuItem item : devicesMenu.getItems()) {
- if (item.getData() instanceof Device) {
- item.dispose();
- }
- }
-
- int currentIndex = 0;
- for (Device device : devicesList.getDevices()) {
- MenuItem deviceMenuItem = new MenuItem(devicesMenu, SWT.RADIO, currentIndex);
- deviceMenuItem.setText(device.getName());
- deviceMenuItem.setData(device);
- deviceMenuItem.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- MenuItem menuItem = (MenuItem)e.widget;
- if (menuItem.getSelection()) {
- DevicesList devicesList = devicesManager.getDevicesList();
- int selectedDeviceIndex = devicesList.getDevices().indexOf(menuItem.getData());
- if (selectedDeviceIndex < 0) {
- selectedDeviceIndex = 0;
- }
- devicesList.setSelectedDeviceIndex(selectedDeviceIndex);
- devicesList.notifyObservers();
- }
- };
- });
-
- currentIndex++;
- }
- }
-
- private Menu createDropDownMenu(Menu menuBar, String name) {
- MenuItem manuItem = new MenuItem(menuBar, SWT.CASCADE);
- manuItem.setText(name);
- Menu dropdown = new Menu(menuBar);
- manuItem.setMenu(dropdown);
- return dropdown;
- }
-
- public void setDevice(final Device device) {
- for (MenuItem menuItem : devicesMenu.getItems()) {
- if (menuItem.getData() instanceof Device) {
- menuItem.setSelection(menuItem.getData() == device);
- }
- }
-
- browser.setDefaultUserAgent(device.getUserAgent());
- GridData data = (GridData) browser.getLayoutData();
- data.widthHint = device.getWidth();
- data.heightHint = device.getHeight();
- Point shellSize = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
- Rectangle clientArea = display.getClientArea();
- shellSize.x = Math.min(shellSize.x, clientArea.width);
- shellSize.y = Math.min(shellSize.y, clientArea.height);
- shell.setSize(shellSize);
-
- Rectangle shellBounds = shell.getBounds();
- int bottomOverlap = shellBounds.y + shellBounds.height - (clientArea.y + clientArea.height);
- if (bottomOverlap > 0) {
- if (shellBounds.y > bottomOverlap) {
- shellBounds.y -= bottomOverlap;
- } else {
- shellBounds.y = 0;
- }
- }
-
- int rightOverlap = shellBounds.x + shellBounds.width - (clientArea.x + clientArea.width);
- if (rightOverlap > 0) {
- if (shellBounds.x > rightOverlap) {
- shellBounds.x -= rightOverlap;
- } else {
- shellBounds.x = 0;
- }
- }
-
- shell.setBounds(shellBounds);
- browser.refresh();
- }
-}
Deleted: workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/Device.java
===================================================================
--- workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/Device.java 2011-11-17 14:54:19 UTC (rev 36408)
+++ workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/Device.java 2011-11-17 16:27:48 UTC (rev 36409)
@@ -1,46 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007-2011 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributor:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.browsersim;
-
-/**
- * @author Yahor Radtsevich (yradtsevich)
- */
-public class Device {
- public static final int DEFAULT_SIZE = -1;
-
- private String name;
- private int width;
- private int height;
- private String userAgent;
-
- public Device(String name, int width, int height, String userAgent) {
- this.name = name;
- this.width = width;
- this.height = height;
- this.userAgent = userAgent;
- }
-
- public int getWidth() {
- return width;
- }
-
- public int getHeight() {
- return height;
- }
-
- public String getUserAgent() {
- return userAgent;
- }
-
- public String getName() {
- return name;
- }
-}
Deleted: workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/DevicesList.java
===================================================================
--- workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/DevicesList.java 2011-11-17 14:54:19 UTC (rev 36408)
+++ workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/DevicesList.java 2011-11-17 16:27:48 UTC (rev 36409)
@@ -1,44 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007-2011 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributor:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.browsersim;
-
-import java.util.List;
-import java.util.Observable;
-
-/**
- * An unmodifiable list of {@link Device}s, with modifiable {@link #selectedDeviceIndex}.
- *
- * @author Yahor Radtsevich (yradtsevich)
- */
-public class DevicesList extends Observable {
- private List<Device> devices;
- private int selectedDeviceIndex;
-
- public DevicesList(List<Device> devices, int selectedDeviceIndex) {
- this.devices = devices;
- this.selectedDeviceIndex = selectedDeviceIndex;
- }
-
- public List<Device> getDevices() {
- return devices;
- }
-
- public int getSelectedDeviceIndex() {
- return selectedDeviceIndex;
- }
-
- public void setSelectedDeviceIndex(int currentDeviceIndex) {
- if (this.selectedDeviceIndex != currentDeviceIndex) {
- this.selectedDeviceIndex = currentDeviceIndex;
- setChanged();
- }
- }
-}
Deleted: workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/DevicesManager.java
===================================================================
--- workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/DevicesManager.java 2011-11-17 14:54:19 UTC (rev 36408)
+++ workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/DevicesManager.java 2011-11-17 16:27:48 UTC (rev 36409)
@@ -1,152 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007-2011 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributor:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.browsersim;
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Observable;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-
-/**
- * @author Yahor Radtsevich (yradtsevich)
- */
-public class DevicesManager extends Observable {
- private static DevicesManager instance;
- private DevicesList devicesList;
- public static final String IPHONE_OS_4_0_USER_AGENT = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7";
-
- protected DevicesManager() {
- }
-
- public static DevicesManager getInstance() {
- if (instance == null) {
- instance = new DevicesManager();
- }
- return instance;
- }
-
- public DevicesList getDevicesList() {
- return devicesList;
- }
-
- public void setDevicesList(DevicesList devicesList) {
- if (this.devicesList != devicesList) {
- this.devicesList = devicesList;
- setChanged();
- }
- }
-
-// List<Device> devices = new ArrayList<Device>();
-// devices.add(new Device("Apple iPhone 3", 320, 480, IPHONE_OS_4_0_USER_AGENT));
-// devices.add(new Device("Apple iPhone 4", 640, 960, IPHONE_OS_4_0_USER_AGENT));
-// devices.add(new Device("BlackBerry Bold Touch 9900", 640, 480, "Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en-US) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.246 Mobile Safari/534.1+"));
-// devices.add(new Device("Samsung Galaxy S II", 640, 800, "Mozilla/5.0 (Linux; U; Android 2.3; en-us; GT-I9100 Build/GRH78) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"));
-
-
- public static String encode(String string) {
- return string.replace("\\", "\\\\").replace("\n", "\\n").replace("\t", "\\t");
- }
-
- public static String decode(String string) {
- StringBuilder result = new StringBuilder();
-
- int i = 0;
- while (i < string.length() - 1) {
- char c0 = string.charAt(i);
- if (c0 == '\\') {
- char c1 = string.charAt(i + 1);
- switch (c1) {
- case '\\':
- result.append('\\');
- i++;
- break;
- case 'n':
- result.append('\n');
- i++;
- break;
- case 't':
- result.append('\t');
- i++;
- break;
- default:
- result.append(c0);
- break;
- }
- } else {
- result.append(c0);
- }
- i++;
- }
-
- if (i < string.length()) {
- result.append(string.charAt(i));
- }
-
- return result.toString();
- }
-
- public static void saveDevicesList(DevicesList devicesList, File file) throws IOException {
- BufferedWriter writer = new BufferedWriter(new FileWriter(file));
-
- writer.write(String.valueOf(devicesList.getSelectedDeviceIndex()));
- writer.write('\n');
-
- for (Device device : devicesList.getDevices()) {
- writer.write( encode(device.getName() ));
- writer.write('\t');
- writer.write(encode( String.valueOf(device.getWidth()) ));
- writer.write('\t');
- writer.write(encode( String.valueOf(device.getHeight()) ));
- writer.write('\t');
- writer.write( encode(device.getUserAgent() ));
- writer.write('\n');
- }
-
- writer.close();
- }
-
- public static DevicesList loadDevicesList(InputStream inputStream) throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
-
- String nextLine = reader.readLine();
- int selectedDeviceIndex = 0;
- if (nextLine != null) {
- selectedDeviceIndex = Integer.parseInt(nextLine);
- }
- Pattern devicePattern = Pattern.compile("^(.*)\\t([0-9]*)\\t([0-9]*)\\t(.*)$");
-
- List<Device> devices = new ArrayList<Device>();
- while ((nextLine = reader.readLine()) != null) {
- Matcher deviceMatcher = devicePattern.matcher(nextLine);
- if (deviceMatcher.matches()) {
- devices.add(new Device(
- decode(deviceMatcher.group(1)),
- Integer.parseInt(deviceMatcher.group(2)),
- Integer.parseInt(deviceMatcher.group(3)),
- decode(deviceMatcher.group(4))
- ));
- }
- }
-
- reader.close();
-
- return new DevicesList(devices, selectedDeviceIndex);
- }
-}
Deleted: workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/EditDeviceDialog.java
===================================================================
--- workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/EditDeviceDialog.java 2011-11-17 14:54:19 UTC (rev 36408)
+++ workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/EditDeviceDialog.java 2011-11-17 16:27:48 UTC (rev 36409)
@@ -1,162 +0,0 @@
-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 EditDeviceDialog extends Dialog {
- protected Device resultDevice;
- protected Device initialDevice;
- protected Shell shell;
- private Text textName;
- private Text textWidth;
- private Text textHeight;
- private Text textUserAgent;
-
- /**
- * Create the dialog.
- * @param parent
- * @param style
- */
- public EditDeviceDialog(Shell parent, int style, Device initialDevice) {
- super(parent, style);
- setText(Messages.EditDeviceDialog_MANAGE_DEVICES);
- this.initialDevice = initialDevice;
- }
-
- /**
- * Open the dialog.
- * @return the newDevicesList
- */
- public Device 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 resultDevice;
- }
-
- /**
- * 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(Messages.EditDeviceDialog_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(Messages.EditDeviceDialog_NAME);
-
- textName = new Text(shell, SWT.BORDER);
- textName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
- textName.addFocusListener(new FocusGainedTextListener());
- textName.setText(initialDevice.getName());
-
- Label labelWidth = new Label(shell, SWT.NONE);
- labelWidth.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
- labelWidth.setText(Messages.EditDeviceDialog_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());
- textWidth.setText(String.valueOf(initialDevice.getWidth()));
-
- Label labelHeight = new Label(shell, SWT.NONE);
- labelHeight.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
- labelHeight.setText(Messages.EditDeviceDialog_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());
- textHeight.setText(String.valueOf(initialDevice.getHeight()));
-
- Label labelUseragent = new Label(shell, SWT.NONE);
- labelUseragent.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
- labelUseragent.setText(Messages.EditDeviceDialog_USER_AGENT);
-
- textUserAgent = new Text(shell, SWT.BORDER);
- textUserAgent.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
- textUserAgent.addFocusListener(new FocusGainedTextListener());
- textUserAgent.setText(initialDevice.getUserAgent());
-
- 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(Messages.EditDeviceDialog_OK);
- buttonOk.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- resultDevice = 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(Messages.EditDeviceDialog_CANCEL);
- buttonCancel.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- resultDevice = 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"); //$NON-NLS-1$
- }
- }
-}
-
-final class FocusGainedTextListener extends FocusAdapter {
- public void focusGained(FocusEvent e) {
- Text text = ((Text) e.widget);
- text.setSelection(0, text.getText().length());
- }
-}
Deleted: workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/IWebViewProxy.java
===================================================================
--- workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/IWebViewProxy.java 2011-11-17 14:54:19 UTC (rev 36408)
+++ workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/IWebViewProxy.java 2011-11-17 16:27:48 UTC (rev 36409)
@@ -1,134 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007-2011 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributor:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-//package org.jboss.tools.browsersim;
-//import org.eclipse.swt.internal.ole.win32.COM;
-//import org.eclipse.swt.internal.ole.win32.GUID;
-//import org.eclipse.swt.internal.webkit.IWebView;
-//import org.eclipse.swt.internal.win32.RECT;
-//
-///**
-// * @author Yahor Radtsevich (yradtsevich)
-// */
-//public class IWebViewProxy extends IWebView {
-// private IWebView webView;
-// private int defaultUserAgent;
-//
-// public void setDefaultUserAgent(String defaultUserAgentString) {
-// if (defaultUserAgentString == null) {
-// this.defaultUserAgent = 0;
-// } else {
-// char[] data = (defaultUserAgentString + '\0').toCharArray ();
-// this.defaultUserAgent = COM.SysAllocString(data);
-// }
-// setCustomUserAgent(this.defaultUserAgent);
-// }
-//
-// public int setCustomUserAgent(int valueString) {
-// if (valueString == 0) {
-// return webView.setCustomUserAgent(defaultUserAgent);
-// } else {
-// return webView.setCustomUserAgent(valueString);
-// }
-// }
-//
-// public IWebViewProxy(IWebView webView) {
-// super(webView.getAddress());
-// this.webView = webView;
-// }
-//
-// public int AddRef() {
-// return webView.AddRef();
-// }
-//
-// public int getAddress() {
-// return webView.getAddress();
-// }
-//
-// public int canShowMIMEType(int mimeType, int[] canShow) {
-// return webView.canShowMIMEType(mimeType, canShow);
-// }
-//
-// public int QueryInterface(GUID riid, int[] ppvObject) {
-// return webView.QueryInterface(riid, ppvObject);
-// }
-//
-// public int initWithFrame(RECT frame, int frameName, int groupName) {
-// return webView.initWithFrame(frame, frameName, groupName);
-// }
-//
-// public int Release() {
-// return webView.Release();
-// }
-//
-// public int setUIDelegate(int delegate) {
-// return webView.setUIDelegate(delegate);
-// }
-//
-// public int setResourceLoadDelegate(int delegate) {
-// return webView.setResourceLoadDelegate(delegate);
-// }
-//
-// public int setDownloadDelegate(int delegate) {
-// return webView.setDownloadDelegate(delegate);
-// }
-//
-// public int setFrameLoadDelegate(int delegate) {
-// return webView.setFrameLoadDelegate(delegate);
-// }
-//
-// public int setPolicyDelegate(int delegate) {
-// return webView.setPolicyDelegate(delegate);
-// }
-//
-// public int hashCode() {
-// return webView.hashCode();
-// }
-//
-// public int mainFrame(int[] frame) {
-// return webView.mainFrame(frame);
-// }
-//
-// public int goBack(int[] succeeded) {
-// return webView.goBack(succeeded);
-// }
-//
-// public int goForward(int[] succeeded) {
-// return webView.goForward(succeeded);
-// }
-//
-// public int setPreferences(int prefs) {
-// return webView.setPreferences(prefs);
-// }
-//
-// public int preferences(int[] prefs) {
-// return webView.preferences(prefs);
-// }
-//
-// public int setHostWindow(int window) {
-// return webView.setHostWindow(window);
-// }
-//
-// public int hostWindow(int[] window) {
-// return webView.hostWindow(window);
-// }
-//
-// public int estimatedProgress(int estimatedProgress) {
-// return webView.estimatedProgress(estimatedProgress);
-// }
-//
-// public boolean equals(Object obj) {
-// return webView.equals(obj);
-// }
-//
-// public String toString() {
-// return webView.toString();
-// }
-//}
Deleted: 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-17 14:54:19 UTC (rev 36408)
+++ workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ManageDevicesDialog.java 2011-11-17 16:27:48 UTC (rev 36409)
@@ -1,200 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007-2011 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributor:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.browsersim;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-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.Shell;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableColumn;
-import org.eclipse.swt.widgets.TableItem;
-
-/**
- * @author Yahor Radtsevich (yradtsevich)
- */
-public class ManageDevicesDialog extends Dialog {
-
- protected DevicesList oldDevicesList;
- protected List<Device> devices;
- protected int selectedDeviceIndex;
- protected Shell shell;
- private Table table;
- private DevicesList resultDevicesList;
-
- /**
- * Create the dialog.
- * @param parent
- * @param style
- * @param oldDevicesList
- */
- public ManageDevicesDialog(Shell parent, int style, DevicesList oldDevicesList) {
- super(parent, style);
- setText(Messages.ManageDevicesDialog_DEVICES);
- this.oldDevicesList = oldDevicesList;
- this.devices = new ArrayList<Device>(oldDevicesList.getDevices());
- this.selectedDeviceIndex = oldDevicesList.getSelectedDeviceIndex();
- }
-
- /**
- * Open the dialog.
- * @return the newDevicesList
- */
- public DevicesList open() {
- createContents();
- shell.open();
- shell.layout();
- Display display = getParent().getDisplay();
- while (!shell.isDisposed()) {
- if (!display.readAndDispatch()) {
- display.sleep();
- }
- }
- return resultDevicesList;
- }
-
- /**
- * Create contents of the dialog.
- */
- private void createContents() {
- shell = new Shell(getParent(), getStyle());
- 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);
- table.setLinesVisible(true);
- table.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- selectedDeviceIndex = ((Table)e.widget).getSelectionIndex();
- }
- });
-
- TableColumn tableColumnName = new TableColumn(table, SWT.NONE);
- tableColumnName.setWidth(100);
- tableColumnName.setText(Messages.ManageDevicesDialog_NAME);
-
- TableColumn tableColumnWidth = new TableColumn(table, SWT.NONE);
- tableColumnWidth.setWidth(100);
- tableColumnWidth.setText(Messages.ManageDevicesDialog_WIDTH);
-
- TableColumn tableColumnHeight = new TableColumn(table, SWT.NONE);
- tableColumnHeight.setWidth(100);
- tableColumnHeight.setText(Messages.ManageDevicesDialog_HEIGHT);
-
- TableColumn tableColumnUseragent = new TableColumn(table, SWT.NONE);
- tableColumnUseragent.setWidth(100);
- tableColumnUseragent.setText(Messages.ManageDevicesDialog_USER_AGENT);
-
- Composite compositeControls = new Composite(shell, SWT.NONE);
- compositeControls.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
- compositeControls.setLayout(new FillLayout(SWT.VERTICAL));
-
- Button buttonAdd = new Button(compositeControls, SWT.NONE);
- buttonAdd.setText(Messages.ManageDevicesDialog_ADD);
- buttonAdd.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- Device newDevice = new EditDeviceDialog(shell, SWT.APPLICATION_MODAL | SWT.SHELL_TRIM,
- new Device(Messages.ManageDevicesDialog_NEW_DEVICE, 480, 800, Messages.ManageDevicesDialog_NEW_USER_AGENT)).open();
- if (newDevice != null) {
- devices.add(newDevice);
- selectedDeviceIndex = devices.size() - 1;
- updateDevices();
- }
- }
- });
-
- Button buttonEdit = new Button(compositeControls, SWT.NONE);
- buttonEdit.setText(Messages.ManageDevicesDialog_EDIT);
- buttonEdit.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- Device newDevice = new EditDeviceDialog(shell, SWT.APPLICATION_MODAL | SWT.SHELL_TRIM,
- devices.get(selectedDeviceIndex)).open();
- if (newDevice != null) {
- devices.remove(selectedDeviceIndex);
- devices.add(selectedDeviceIndex, newDevice);
- updateDevices();
- }
- }
- });
-
- Button buttonRemove = new Button(compositeControls, SWT.NONE);
- buttonRemove.setText(Messages.ManageDevicesDialog_REMOVE);
- buttonRemove.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- System.out.println(devices.size());
- if (devices.size() > 1) {
- devices.remove(selectedDeviceIndex);
- if (selectedDeviceIndex >= devices.size()) {
- selectedDeviceIndex = devices.size() - 1;
- }
- updateDevices();
- }
- }
- });
-
- Button buttonReset = new Button(compositeControls, SWT.NONE);
- buttonReset.setText(Messages.ManageDevicesDialog_RESET);
- buttonReset.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- devices = new ArrayList<Device>(oldDevicesList.getDevices());
- selectedDeviceIndex = oldDevicesList.getSelectedDeviceIndex();
- updateDevices();
- }
- });
-
- Composite compositeOkCancel = new Composite(shell, SWT.NONE);
- compositeOkCancel.setLayout(new FillLayout(SWT.HORIZONTAL));
- compositeOkCancel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 2, 1));
-
- Button buttonOk = new Button(compositeOkCancel, SWT.NONE);
- buttonOk.setText(Messages.ManageDevicesDialog_OK);
- shell.setDefaultButton(buttonOk);
- buttonOk.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- resultDevicesList = new DevicesList(devices, selectedDeviceIndex);
- shell.close();
- }
- });
-
- Button buttonCancel = new Button(compositeOkCancel, SWT.NONE);
- buttonCancel.setText(Messages.ManageDevicesDialog_CANCEL);
- buttonCancel.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- resultDevicesList = null;
- shell.close();
- }
- });
-
-
- updateDevices();
- }
-
- public void updateDevices() {
- table.removeAll();
- for (Device device : devices) {
- TableItem tableItem = new TableItem(table, SWT.NONE);
- tableItem.setText(new String[] {device.getName(), String.valueOf(device.getWidth()), String.valueOf(device.getHeight()), device.getUserAgent()});
- }
- table.setSelection(selectedDeviceIndex);
- }
-}
Deleted: workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/Messages.java
===================================================================
--- workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/Messages.java 2011-11-17 14:54:19 UTC (rev 36408)
+++ workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/Messages.java 2011-11-17 16:27:48 UTC (rev 36409)
@@ -1,39 +0,0 @@
-package org.jboss.tools.browsersim;
-
-public class Messages {
- private static final String BUNDLE_NAME = "org.jboss.tools.browsersim.messages"; //$NON-NLS-1$
- public static String BrowserSim_ADDRESS;
- public static String BrowserSim_BROWSER_SIM;
- public static String BrowserSim_COULD_NOT_INSTANTIATE_BROWSER;
- public static String BrowserSim_DEVICES;
- public static String BrowserSim_EXIT;
- public static String BrowserSim_FILE;
- public static String BrowserSim_MORE;
- public static String EditDeviceDialog_CANCEL;
- public static String EditDeviceDialog_EDIT_DEVICE;
- public static String EditDeviceDialog_HEIGHT;
- public static String EditDeviceDialog_MANAGE_DEVICES;
- public static String EditDeviceDialog_NAME;
- public static String EditDeviceDialog_OK;
- public static String EditDeviceDialog_USER_AGENT;
- public static String EditDeviceDialog_WIDTH;
- public static String ManageDevicesDialog_ADD;
- public static String ManageDevicesDialog_CANCEL;
- public static String ManageDevicesDialog_DEVICES;
- public static String ManageDevicesDialog_EDIT;
- public static String ManageDevicesDialog_HEIGHT;
- public static String ManageDevicesDialog_NAME;
- public static String ManageDevicesDialog_NEW_DEVICE;
- public static String ManageDevicesDialog_NEW_USER_AGENT;
- public static String ManageDevicesDialog_OK;
- public static String ManageDevicesDialog_REMOVE;
- public static String ManageDevicesDialog_RESET;
- public static String ManageDevicesDialog_USER_AGENT;
- public static String ManageDevicesDialog_WIDTH;
- static {
- NLS.initializeMessages(BUNDLE_NAME, Messages.class);
- }
-
- private Messages() {
- }
-}
Deleted: workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/NLS.java
===================================================================
--- workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/NLS.java 2011-11-17 14:54:19 UTC (rev 36408)
+++ workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/NLS.java 2011-11-17 16:27:48 UTC (rev 36409)
@@ -1,33 +0,0 @@
-package org.jboss.tools.browsersim;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-
-public class NLS {
- private static final int MOD_EXPECTED = Modifier.PUBLIC | Modifier.STATIC;
-
- private NLS(){};
-
- public static void initializeMessages(String bundleName, Class<?> clazz) {
- ResourceBundle resourceBundle = ResourceBundle.getBundle(bundleName);
-
- try {
- for (Field field : clazz.getDeclaredFields()) {
- // if it is a public static uninitialized String field
- if ((field.getModifiers() & MOD_EXPECTED) == MOD_EXPECTED
- && field.getType() == String.class
- && field.get(null) == null) {
- try {
- field.set(null, resourceBundle.getString(field.getName()));
- } catch (MissingResourceException e) {
- field.set(null, '!' + field.getName() + '!');
- }
- }
- }
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- }
-}
Deleted: workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/messages.properties
===================================================================
--- workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/messages.properties 2011-11-17 14:54:19 UTC (rev 36408)
+++ workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/messages.properties 2011-11-17 16:27:48 UTC (rev 36409)
@@ -1,28 +0,0 @@
-BrowserSim_ADDRESS=Address
-BrowserSim_BROWSER_SIM=BrowserSim
-BrowserSim_COULD_NOT_INSTANTIATE_BROWSER=Could not instantiate Browser:
-BrowserSim_DEVICES=Devices
-BrowserSim_EXIT=Exit
-BrowserSim_FILE=File
-BrowserSim_MORE=More...
-EditDeviceDialog_CANCEL=Cancel
-EditDeviceDialog_EDIT_DEVICE=Edit Device
-EditDeviceDialog_HEIGHT=Height:
-EditDeviceDialog_MANAGE_DEVICES=Manage Devices
-EditDeviceDialog_NAME=Name:
-EditDeviceDialog_OK=OK
-EditDeviceDialog_USER_AGENT=User-Agent:
-EditDeviceDialog_WIDTH=Width:
-ManageDevicesDialog_ADD=Add
-ManageDevicesDialog_CANCEL=Cancel
-ManageDevicesDialog_DEVICES=Devices
-ManageDevicesDialog_EDIT=Edit
-ManageDevicesDialog_HEIGHT=Height
-ManageDevicesDialog_NAME=Name
-ManageDevicesDialog_NEW_DEVICE=New Device
-ManageDevicesDialog_NEW_USER_AGENT=New User-Agent
-ManageDevicesDialog_OK=OK
-ManageDevicesDialog_REMOVE=Remove
-ManageDevicesDialog_RESET=Reset
-ManageDevicesDialog_USER_AGENT=User-Agent
-ManageDevicesDialog_WIDTH=Width
Copied: workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/Device.java (from rev 36176, workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/Device.java)
===================================================================
--- workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/Device.java (rev 0)
+++ workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/Device.java 2011-11-17 16:27:48 UTC (rev 36409)
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.browsersim.model;
+
+/**
+ * @author Yahor Radtsevich (yradtsevich)
+ */
+public class Device {
+ public static final int DEFAULT_SIZE = -1;
+
+ private String name;
+ private int width;
+ private int height;
+ private String userAgent;
+
+ public Device(String name, int width, int height, String userAgent) {
+ this.name = name;
+ this.width = width;
+ this.height = height;
+ this.userAgent = userAgent;
+ }
+
+ public int getWidth() {
+ return width;
+ }
+
+ public int getHeight() {
+ return height;
+ }
+
+ public String getUserAgent() {
+ return userAgent;
+ }
+
+ public String getName() {
+ return name;
+ }
+}
Copied: workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/DevicesList.java (from rev 36251, workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/DevicesList.java)
===================================================================
--- workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/DevicesList.java (rev 0)
+++ workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/DevicesList.java 2011-11-17 16:27:48 UTC (rev 36409)
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.browsersim.model;
+
+import java.util.List;
+import java.util.Observable;
+
+/**
+ * An unmodifiable list of {@link Device}s, with modifiable {@link #selectedDeviceIndex}.
+ *
+ * @author Yahor Radtsevich (yradtsevich)
+ */
+public class DevicesList extends Observable {
+ private List<Device> devices;
+ private int selectedDeviceIndex;
+
+ public DevicesList(List<Device> devices, int selectedDeviceIndex) {
+ this.devices = devices;
+ this.selectedDeviceIndex = selectedDeviceIndex;
+ }
+
+ public List<Device> getDevices() {
+ return devices;
+ }
+
+ public int getSelectedDeviceIndex() {
+ return selectedDeviceIndex;
+ }
+
+ public void setSelectedDeviceIndex(int currentDeviceIndex) {
+ if (this.selectedDeviceIndex != currentDeviceIndex) {
+ this.selectedDeviceIndex = currentDeviceIndex;
+ setChanged();
+ }
+ }
+}
Copied: workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/DevicesManager.java (from rev 36344, workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/DevicesManager.java)
===================================================================
--- workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/DevicesManager.java (rev 0)
+++ workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/model/DevicesManager.java 2011-11-17 16:27:48 UTC (rev 36409)
@@ -0,0 +1,158 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.browsersim.model;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Observable;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+
+/**
+ * @author Yahor Radtsevich (yradtsevich)
+ */
+public class DevicesManager extends Observable {
+ private static DevicesManager instance;
+ private DevicesList devicesList;
+ public static final String IPHONE_OS_4_0_USER_AGENT = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7";
+
+ protected DevicesManager() {
+ }
+
+ public static DevicesManager getInstance() {
+ if (instance == null) {
+ instance = new DevicesManager();
+ }
+ return instance;
+ }
+
+ public DevicesList getDevicesList() {
+ return devicesList;
+ }
+
+ public void setDevicesList(DevicesList devicesList) {
+ if (this.devicesList != devicesList) {
+ this.devicesList = devicesList;
+ setChanged();
+ }
+ }
+
+// List<Device> devices = new ArrayList<Device>();
+// devices.add(new Device("Apple iPhone 3", 320, 480, IPHONE_OS_4_0_USER_AGENT));
+// devices.add(new Device("Apple iPhone 4", 640, 960, IPHONE_OS_4_0_USER_AGENT));
+// devices.add(new Device("BlackBerry Bold Touch 9900", 640, 480, "Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en-US) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.246 Mobile Safari/534.1+"));
+// devices.add(new Device("Samsung Galaxy S II", 640, 800, "Mozilla/5.0 (Linux; U; Android 2.3; en-us; GT-I9100 Build/GRH78) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"));
+
+
+ public static String encode(String string) {
+ return string.replace("\\", "\\\\").replace("\n", "\\n").replace("\t", "\\t");
+ }
+
+ public static String decode(String string) {
+ StringBuilder result = new StringBuilder();
+
+ int i = 0;
+ while (i < string.length() - 1) {
+ char c0 = string.charAt(i);
+ if (c0 == '\\') {
+ char c1 = string.charAt(i + 1);
+ switch (c1) {
+ case '\\':
+ result.append('\\');
+ i++;
+ break;
+ case 'n':
+ result.append('\n');
+ i++;
+ break;
+ case 't':
+ result.append('\t');
+ i++;
+ break;
+ default:
+ result.append(c0);
+ break;
+ }
+ } else {
+ result.append(c0);
+ }
+ i++;
+ }
+
+ if (i < string.length()) {
+ result.append(string.charAt(i));
+ }
+
+ return result.toString();
+ }
+
+ public static void saveDevicesList(DevicesList devicesList, File file) throws IOException {
+ BufferedWriter writer = new BufferedWriter(new FileWriter(file));
+
+ writer.write(String.valueOf(devicesList.getSelectedDeviceIndex()));
+ writer.write('\n');
+
+ for (Device device : devicesList.getDevices()) {
+ writer.write( encode(device.getName() ));
+ writer.write('\t');
+ writer.write(encode( String.valueOf(device.getWidth()) ));
+ writer.write('\t');
+ writer.write(encode( String.valueOf(device.getHeight()) ));
+ writer.write('\t');
+ writer.write( encode(device.getUserAgent() ));
+ writer.write('\n');
+ }
+
+ writer.close();
+ }
+
+ public static DevicesList loadDevicesList(File file) throws IOException {
+ InputStream inputStream = new FileInputStream(file);
+ return loadDevicesList(inputStream);
+ }
+
+ public static DevicesList loadDevicesList(InputStream inputStream) throws IOException {
+ BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
+
+ String nextLine = reader.readLine();
+ int selectedDeviceIndex = 0;
+ if (nextLine != null) {
+ selectedDeviceIndex = Integer.parseInt(nextLine);
+ }
+ Pattern devicePattern = Pattern.compile("^(.*)\\t([0-9]*)\\t([0-9]*)\\t(.*)$");
+
+ List<Device> devices = new ArrayList<Device>();
+ while ((nextLine = reader.readLine()) != null) {
+ Matcher deviceMatcher = devicePattern.matcher(nextLine);
+ if (deviceMatcher.matches()) {
+ devices.add(new Device(
+ decode(deviceMatcher.group(1)),
+ Integer.parseInt(deviceMatcher.group(2)),
+ Integer.parseInt(deviceMatcher.group(3)),
+ decode(deviceMatcher.group(4))
+ ));
+ }
+ }
+
+ reader.close();
+
+ return new DevicesList(devices, selectedDeviceIndex);
+ }
+}
Copied: workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/BrowserSim.java (from rev 36347, workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/BrowserSim.java)
===================================================================
--- workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/BrowserSim.java (rev 0)
+++ workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/BrowserSim.java 2011-11-17 16:27:48 UTC (rev 36409)
@@ -0,0 +1,410 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.browsersim.ui;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Observable;
+import java.util.Observer;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.SWTError;
+import org.eclipse.swt.browser.LocationEvent;
+import org.eclipse.swt.browser.LocationListener;
+import org.eclipse.swt.browser.ProgressEvent;
+import org.eclipse.swt.browser.ProgressListener;
+import org.eclipse.swt.browser.StatusTextEvent;
+import org.eclipse.swt.browser.StatusTextListener;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.swt.widgets.ProgressBar;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.ToolBar;
+import org.eclipse.swt.widgets.ToolItem;
+import org.jboss.tools.browsersim.model.Device;
+import org.jboss.tools.browsersim.model.DevicesList;
+import org.jboss.tools.browsersim.model.DevicesManager;
+import org.jboss.tools.browsersim.util.ResourcesUtil;
+import org.jboss.tools.browsersim.webkit.AbstractWebKitBrowser;
+import org.jboss.tools.browsersim.webkit.WebKitBrowserFactory;
+
+/**
+ * @author Yahor Radtsevich (yradtsevich)
+ */
+public class BrowserSim implements Runnable {
+ private static final String DEFAULT_URL = "http://www.w3schools.com/js/tryit_view.asp?filename=try_nav_useragent"; //$NON-NLS-1$
+ private AbstractWebKitBrowser browser;
+ private Display display;
+ private Shell shell;
+ private Text locationText;
+ private Label statusLabel;
+ private ProgressBar progressBar;
+ private String initialUrl;
+ private Menu devicesMenu;
+ private DevicesManager devicesManager;
+
+ public static void main(String[] args) {
+ String initialUrl;
+ if (args.length > 0) {
+ String lastArg = args[args.length - 1];
+ try {
+ new URI(lastArg); // validate URL
+ initialUrl = lastArg;
+ } catch (URISyntaxException e) {
+ initialUrl = DEFAULT_URL;
+ }
+ } else {
+ initialUrl = DEFAULT_URL;
+ }
+
+ new BrowserSim(new Display(), initialUrl).run();
+ }
+
+ public BrowserSim(Display display, String initialUrl) {
+ this.display = display;
+ this.initialUrl = initialUrl;
+ }
+
+ @Override
+ public void run() {
+ shell = new Shell(display);
+ shell.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ try {
+ File configFolder = new File(this.getClass().getPackage().getName());
+ configFolder.mkdir();
+ DevicesManager.saveDevicesList(devicesManager.getDevicesList(),
+ new File(configFolder, "devices.cfg"));
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ }
+ }
+ });
+ shell.setText(Messages.BrowserSim_BROWSER_SIM);
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.numColumns = 3;
+ shell.setLayout(gridLayout);
+ Menu appMenuBar = display.getMenuBar();
+ if (appMenuBar == null) {
+ appMenuBar = new Menu(shell, SWT.BAR);
+ shell.setMenuBar(appMenuBar);
+ }
+
+ ToolBar toolbar = createControlBar();
+ GridData data = new GridData();
+ data.horizontalSpan = 3;
+ toolbar.setLayoutData(data);
+
+ Label labelAddress = new Label(shell, SWT.NONE);
+ labelAddress.setText(Messages.BrowserSim_ADDRESS);
+
+ locationText = new Text(shell, SWT.BORDER);
+ data = new GridData();
+ data.horizontalAlignment = GridData.FILL;
+ data.horizontalSpan = 2;
+ data.grabExcessHorizontalSpace = true;
+ data.widthHint = 0;
+ locationText.setLayoutData(data);
+
+ try {
+ browser = WebKitBrowserFactory.createWebKitBrowser(shell, SWT.NONE);
+ } catch (SWTError e) {
+ System.out.println(Messages.BrowserSim_COULD_NOT_INSTANTIATE_BROWSER + e.getMessage());
+ display.dispose();
+ return;
+ }
+
+ data = new GridData();
+ data.horizontalAlignment = GridData.FILL;
+ data.verticalAlignment = GridData.FILL;
+ data.horizontalSpan = 3;
+ data.grabExcessHorizontalSpace = true;
+ data.grabExcessVerticalSpace = true;
+ browser.setLayoutData(data);
+
+ statusLabel = new Label(shell, SWT.NONE);
+ data = new GridData(GridData.FILL_HORIZONTAL);
+ data.horizontalSpan = 2;
+ data.widthHint = 0;
+ statusLabel.setLayoutData(data);
+
+ progressBar = new ProgressBar(shell, SWT.NONE);
+ data = new GridData();
+ data.horizontalAlignment = GridData.END;
+ progressBar.setLayoutData(data);
+
+ browser.addProgressListener(new ProgressListener() {
+ public void changed(ProgressEvent event) {
+ if (event.total == 0) return;
+ int ratio = event.current * 100 / event.total;
+ progressBar.setSelection(ratio);
+ }
+ public void completed(ProgressEvent event) {
+ progressBar.setSelection(0);
+ }
+ });
+ browser.addStatusTextListener(new StatusTextListener() {
+ public void changed(StatusTextEvent event) {
+ statusLabel.setText(event.text);
+ }
+ });
+ browser.addLocationListener(new LocationListener() {
+ public void changed(LocationEvent event) {
+ if (event.top) locationText.setText(event.location);
+ }
+ public void changing(LocationEvent event) {
+ }
+ });
+
+ fillMenuBar(appMenuBar);
+
+ locationText.addListener(SWT.DefaultSelection, new Listener() {
+ public void handleEvent(Event e) {
+ browser.setUrl(locationText.getText());
+ }
+ });
+
+ DevicesList devicesList = DevicesManager.getInstance().getDevicesList();
+ if (devicesList != null && devicesList.getDevices() != null
+ && devicesList.getSelectedDeviceIndex() < devicesList.getDevices().size()) {
+ setDevice(devicesList.getDevices().get(devicesList.getSelectedDeviceIndex()));
+ }
+ shell.open();
+ browser.setUrl(initialUrl);
+
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+ display.dispose();
+ }
+
+ public ToolBar createControlBar() {
+ ToolBar toolbar = new ToolBar(shell, SWT.NONE);
+ ToolItem itemBack = new ToolItem(toolbar, SWT.PUSH);
+// itemBack.setText("Back");
+ itemBack.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ browser.back();
+ }
+ });
+
+ ToolItem itemForward = new ToolItem(toolbar, SWT.PUSH);
+// itemForward.setText("Forward");
+ itemForward.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ browser.forward();
+ }
+ });
+
+ ToolItem itemStop = new ToolItem(toolbar, SWT.PUSH);
+// itemStop.setText("Stop");
+ itemStop.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ browser.stop();
+ }
+ });
+
+ ToolItem itemRefresh = new ToolItem(toolbar, SWT.PUSH);
+// itemRefresh.setText("Refresh");
+ itemRefresh.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ browser.refresh();
+ }
+ });
+
+ ToolItem itemGo = new ToolItem(toolbar, SWT.PUSH);
+// itemGo.setText("Go");
+ itemGo.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ browser.setUrl(locationText.getText());
+ }
+ });
+
+ final Image imageBack = new Image(display, ResourcesUtil.getResourceAsStream("/org/jboss/tools/browsersim/resources/icons/nav_backward.gif")); //$NON-NLS-1$
+ final Image imageForward = new Image(display, ResourcesUtil.getResourceAsStream("/org/jboss/tools/browsersim/resources/icons/nav_forward.gif")); //$NON-NLS-1$
+ final Image imageStop = new Image(display, ResourcesUtil.getResourceAsStream("/org/jboss/tools/browsersim/resources/icons/nav_stop.gif")); //$NON-NLS-1$
+ final Image imageRefresh = new Image(display, ResourcesUtil.getResourceAsStream("/org/jboss/tools/browsersim/resources/icons/nav_refresh.gif")); //$NON-NLS-1$
+ final Image imageGo = new Image(display, ResourcesUtil.getResourceAsStream("/org/jboss/tools/browsersim/resources/icons/nav_go.gif")); //$NON-NLS-1$
+
+ itemBack.setImage(imageBack);
+ itemForward.setImage(imageForward);
+ itemStop.setImage(imageStop);
+ itemRefresh.setImage(imageRefresh);
+ itemGo.setImage(imageGo);
+ shell.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ imageBack.dispose();
+ imageForward.dispose();
+ imageStop.dispose();
+ imageRefresh.dispose();
+ imageGo.dispose();
+ }
+ });
+
+ itemForward.setImage(imageForward);
+
+
+ return toolbar;
+ }
+
+ public void fillMenuBar(Menu appMenuBar) {
+ Menu file = createDropDownMenu(appMenuBar, Messages.BrowserSim_FILE);
+ MenuItem exit = new MenuItem(file, SWT.PUSH);
+ exit.setText(Messages.BrowserSim_EXIT);
+ exit.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ display.dispose();
+ };
+ });
+
+ devicesMenu = createDropDownMenu(appMenuBar, Messages.BrowserSim_DEVICES);
+ devicesManager = DevicesManager.getInstance();
+ devicesManager.addObserver(new Observer() {
+ public void update(Observable o, Object arg) {
+ DevicesManager devicesManager = (DevicesManager) o;
+ DevicesList devicesList = devicesManager.getDevicesList();
+ setDevicesListForMenu(devicesList);
+ setDevice(devicesList.getDevices().get(devicesList.getSelectedDeviceIndex()));
+ devicesList.addObserver(new Observer() {
+ public void update(Observable o, Object arg) {
+ setDevice(((DevicesList)o).getDevices().get(((DevicesList)o).getSelectedDeviceIndex()));
+ }
+ });
+ }
+ });
+
+ DevicesList devicesList;
+ try {
+ File customConfigFile = new File(this.getClass().getPackage().getName() + "/devices.cfg");
+ if (customConfigFile.exists()) {
+ devicesList = DevicesManager.loadDevicesList(customConfigFile);
+ } else {
+ devicesList = DevicesManager.loadDevicesList(ResourcesUtil.getResourceAsStream(
+ "/org/jboss/tools/browsersim/resources/config/devices.cfg"));
+ }
+ } catch (IOException e) {
+ devicesList = new DevicesList(new ArrayList<Device>(), 0);
+ }
+ devicesManager.setDevicesList(devicesList);
+ devicesManager.notifyObservers();
+
+ new MenuItem(devicesMenu, SWT.BAR);
+ MenuItem manageDevicesMenuItem = new MenuItem(devicesMenu, SWT.PUSH);
+ manageDevicesMenuItem.setText(Messages.BrowserSim_MORE);
+ manageDevicesMenuItem.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ DevicesList newDevicesList = new ManageDevicesDialog(shell, SWT.APPLICATION_MODAL | SWT.SHELL_TRIM,
+ devicesManager.getDevicesList()).open();
+ if (newDevicesList != null) {
+ devicesManager.setDevicesList(newDevicesList);
+ devicesManager.notifyObservers();
+ }
+ }
+ });
+ }
+
+ private void setDevicesListForMenu(DevicesList devicesList) {
+ for (MenuItem item : devicesMenu.getItems()) {
+ if (item.getData() instanceof Device) {
+ item.dispose();
+ }
+ }
+
+ int currentIndex = 0;
+ for (Device device : devicesList.getDevices()) {
+ MenuItem deviceMenuItem = new MenuItem(devicesMenu, SWT.RADIO, currentIndex);
+ deviceMenuItem.setText(device.getName());
+ deviceMenuItem.setData(device);
+ deviceMenuItem.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ MenuItem menuItem = (MenuItem)e.widget;
+ if (menuItem.getSelection()) {
+ DevicesList devicesList = devicesManager.getDevicesList();
+ int selectedDeviceIndex = devicesList.getDevices().indexOf(menuItem.getData());
+ if (selectedDeviceIndex < 0) {
+ selectedDeviceIndex = 0;
+ }
+ devicesList.setSelectedDeviceIndex(selectedDeviceIndex);
+ devicesList.notifyObservers();
+ }
+ };
+ });
+
+ currentIndex++;
+ }
+ }
+
+ private Menu createDropDownMenu(Menu menuBar, String name) {
+ MenuItem manuItem = new MenuItem(menuBar, SWT.CASCADE);
+ manuItem.setText(name);
+ Menu dropdown = new Menu(menuBar);
+ manuItem.setMenu(dropdown);
+ return dropdown;
+ }
+
+ public void setDevice(final Device device) {
+ for (MenuItem menuItem : devicesMenu.getItems()) {
+ if (menuItem.getData() instanceof Device) {
+ menuItem.setSelection(menuItem.getData() == device);
+ }
+ }
+
+ browser.setDefaultUserAgent(device.getUserAgent());
+ GridData data = (GridData) browser.getLayoutData();
+ data.widthHint = device.getWidth();
+ data.heightHint = device.getHeight();
+ Point shellSize = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ Rectangle clientArea = display.getClientArea();
+ shellSize.x = Math.min(shellSize.x, clientArea.width);
+ shellSize.y = Math.min(shellSize.y, clientArea.height);
+ shell.setSize(shellSize);
+
+ Rectangle shellBounds = shell.getBounds();
+ int bottomOverlap = shellBounds.y + shellBounds.height - (clientArea.y + clientArea.height);
+ if (bottomOverlap > 0) {
+ if (shellBounds.y > bottomOverlap) {
+ shellBounds.y -= bottomOverlap;
+ } else {
+ shellBounds.y = 0;
+ }
+ }
+
+ int rightOverlap = shellBounds.x + shellBounds.width - (clientArea.x + clientArea.width);
+ if (rightOverlap > 0) {
+ if (shellBounds.x > rightOverlap) {
+ shellBounds.x -= rightOverlap;
+ } else {
+ shellBounds.x = 0;
+ }
+ }
+
+ shell.setBounds(shellBounds);
+ browser.refresh();
+ }
+}
Copied: workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/EditDeviceDialog.java (from rev 36281, workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/EditDeviceDialog.java)
===================================================================
--- workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/EditDeviceDialog.java (rev 0)
+++ workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/EditDeviceDialog.java 2011-11-17 16:27:48 UTC (rev 36409)
@@ -0,0 +1,163 @@
+package org.jboss.tools.browsersim.ui;
+
+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;
+import org.jboss.tools.browsersim.model.Device;
+
+public class EditDeviceDialog extends Dialog {
+ protected Device resultDevice;
+ protected Device initialDevice;
+ protected Shell shell;
+ private Text textName;
+ private Text textWidth;
+ private Text textHeight;
+ private Text textUserAgent;
+
+ /**
+ * Create the dialog.
+ * @param parent
+ * @param style
+ */
+ public EditDeviceDialog(Shell parent, int style, Device initialDevice) {
+ super(parent, style);
+ setText(Messages.EditDeviceDialog_MANAGE_DEVICES);
+ this.initialDevice = initialDevice;
+ }
+
+ /**
+ * Open the dialog.
+ * @return the newDevicesList
+ */
+ public Device 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 resultDevice;
+ }
+
+ /**
+ * 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(Messages.EditDeviceDialog_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(Messages.EditDeviceDialog_NAME);
+
+ textName = new Text(shell, SWT.BORDER);
+ textName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
+ textName.addFocusListener(new FocusGainedTextListener());
+ textName.setText(initialDevice.getName());
+
+ Label labelWidth = new Label(shell, SWT.NONE);
+ labelWidth.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ labelWidth.setText(Messages.EditDeviceDialog_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());
+ textWidth.setText(String.valueOf(initialDevice.getWidth()));
+
+ Label labelHeight = new Label(shell, SWT.NONE);
+ labelHeight.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ labelHeight.setText(Messages.EditDeviceDialog_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());
+ textHeight.setText(String.valueOf(initialDevice.getHeight()));
+
+ Label labelUseragent = new Label(shell, SWT.NONE);
+ labelUseragent.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
+ labelUseragent.setText(Messages.EditDeviceDialog_USER_AGENT);
+
+ textUserAgent = new Text(shell, SWT.BORDER);
+ textUserAgent.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
+ textUserAgent.addFocusListener(new FocusGainedTextListener());
+ textUserAgent.setText(initialDevice.getUserAgent());
+
+ 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(Messages.EditDeviceDialog_OK);
+ buttonOk.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ resultDevice = 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(Messages.EditDeviceDialog_CANCEL);
+ buttonCancel.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ resultDevice = 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"); //$NON-NLS-1$
+ }
+ }
+}
+
+final class FocusGainedTextListener extends FocusAdapter {
+ public void focusGained(FocusEvent e) {
+ Text text = ((Text) e.widget);
+ text.setSelection(0, text.getText().length());
+ }
+}
Copied: workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/ManageDevicesDialog.java (from rev 36281, 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/ui/ManageDevicesDialog.java (rev 0)
+++ workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/ManageDevicesDialog.java 2011-11-17 16:27:48 UTC (rev 36409)
@@ -0,0 +1,226 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.browsersim.ui;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+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.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
+import org.jboss.tools.browsersim.model.Device;
+import org.jboss.tools.browsersim.model.DevicesList;
+import org.jboss.tools.browsersim.model.DevicesManager;
+import org.jboss.tools.browsersim.util.ResourcesUtil;
+
+/**
+ * @author Yahor Radtsevich (yradtsevich)
+ */
+public class ManageDevicesDialog extends Dialog {
+
+ protected DevicesList oldDevicesList;
+ protected List<Device> devices;
+ protected int selectedDeviceIndex;
+ protected Shell shell;
+ private Table table;
+ private DevicesList resultDevicesList;
+
+ /**
+ * Create the dialog.
+ * @param parent
+ * @param style
+ * @param oldDevicesList
+ */
+ public ManageDevicesDialog(Shell parent, int style, DevicesList oldDevicesList) {
+ super(parent, style);
+ setText(Messages.ManageDevicesDialog_DEVICES);
+ this.oldDevicesList = oldDevicesList;
+ this.devices = new ArrayList<Device>(oldDevicesList.getDevices());
+ this.selectedDeviceIndex = oldDevicesList.getSelectedDeviceIndex();
+ }
+
+ /**
+ * Open the dialog.
+ * @return the newDevicesList
+ */
+ public DevicesList open() {
+ createContents();
+ shell.open();
+ shell.layout();
+ Display display = getParent().getDisplay();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ }
+ return resultDevicesList;
+ }
+
+ /**
+ * Create contents of the dialog.
+ */
+ private void createContents() {
+ shell = new Shell(getParent(), getStyle());
+ 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);
+ table.setLinesVisible(true);
+ table.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ selectedDeviceIndex = ((Table)e.widget).getSelectionIndex();
+ }
+ });
+
+ TableColumn tableColumnName = new TableColumn(table, SWT.NONE);
+ tableColumnName.setWidth(100);
+ tableColumnName.setText(Messages.ManageDevicesDialog_NAME);
+
+ TableColumn tableColumnWidth = new TableColumn(table, SWT.NONE);
+ tableColumnWidth.setWidth(100);
+ tableColumnWidth.setText(Messages.ManageDevicesDialog_WIDTH);
+
+ TableColumn tableColumnHeight = new TableColumn(table, SWT.NONE);
+ tableColumnHeight.setWidth(100);
+ tableColumnHeight.setText(Messages.ManageDevicesDialog_HEIGHT);
+
+ TableColumn tableColumnUseragent = new TableColumn(table, SWT.NONE);
+ tableColumnUseragent.setWidth(100);
+ tableColumnUseragent.setText(Messages.ManageDevicesDialog_USER_AGENT);
+
+ Composite compositeControls = new Composite(shell, SWT.NONE);
+ compositeControls.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
+ compositeControls.setLayout(new FillLayout(SWT.VERTICAL));
+
+ Button buttonAdd = new Button(compositeControls, SWT.NONE);
+ buttonAdd.setText(Messages.ManageDevicesDialog_ADD);
+ buttonAdd.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ Device newDevice = new EditDeviceDialog(shell, SWT.APPLICATION_MODAL | SWT.SHELL_TRIM,
+ new Device(Messages.ManageDevicesDialog_NEW_DEVICE, 480, 800, Messages.ManageDevicesDialog_NEW_USER_AGENT)).open();
+ if (newDevice != null) {
+ devices.add(newDevice);
+ selectedDeviceIndex = devices.size() - 1;
+ updateDevices();
+ }
+ }
+ });
+
+ Button buttonEdit = new Button(compositeControls, SWT.NONE);
+ buttonEdit.setText(Messages.ManageDevicesDialog_EDIT);
+ buttonEdit.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ Device newDevice = new EditDeviceDialog(shell, SWT.APPLICATION_MODAL | SWT.SHELL_TRIM,
+ devices.get(selectedDeviceIndex)).open();
+ if (newDevice != null) {
+ devices.remove(selectedDeviceIndex);
+ devices.add(selectedDeviceIndex, newDevice);
+ updateDevices();
+ }
+ }
+ });
+
+ Button buttonRemove = new Button(compositeControls, SWT.NONE);
+ buttonRemove.setText(Messages.ManageDevicesDialog_REMOVE);
+ buttonRemove.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ System.out.println(devices.size());
+ if (devices.size() > 1) {
+ devices.remove(selectedDeviceIndex);
+ if (selectedDeviceIndex >= devices.size()) {
+ selectedDeviceIndex = devices.size() - 1;
+ }
+ updateDevices();
+ }
+ }
+ });
+
+ Button buttonReset = new Button(compositeControls, SWT.NONE);
+ buttonReset.setText(Messages.ManageDevicesDialog_RESET);
+
+ buttonReset.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ devices = new ArrayList<Device>(oldDevicesList.getDevices());
+ selectedDeviceIndex = oldDevicesList.getSelectedDeviceIndex();
+ updateDevices();
+ }
+ });
+
+ new Label(compositeControls, SWT.NONE);
+
+ Button buttonLoadDefaults = new Button(compositeControls, SWT.NONE);
+ buttonLoadDefaults.setText(Messages.ManageDevicesDialog_LOAD_DEFAULTS);
+ buttonLoadDefaults.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ DevicesList defaultDevicesList;
+ try {
+ defaultDevicesList = DevicesManager.loadDevicesList(ResourcesUtil.getResourceAsStream(
+ "/org/jboss/tools/browsersim/resources/config/devices.cfg"));
+ devices = defaultDevicesList.getDevices();
+ selectedDeviceIndex = defaultDevicesList.getSelectedDeviceIndex();
+ updateDevices();
+ } catch (IOException e1) {
+ e1.printStackTrace();
+ }
+ }
+ });
+
+ Composite compositeOkCancel = new Composite(shell, SWT.NONE);
+ compositeOkCancel.setLayout(new FillLayout(SWT.HORIZONTAL));
+ compositeOkCancel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 2, 1));
+
+ Button buttonOk = new Button(compositeOkCancel, SWT.NONE);
+ buttonOk.setText(Messages.ManageDevicesDialog_OK);
+ shell.setDefaultButton(buttonOk);
+ buttonOk.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ resultDevicesList = new DevicesList(devices, selectedDeviceIndex);
+ shell.close();
+ }
+ });
+
+ Button buttonCancel = new Button(compositeOkCancel, SWT.NONE);
+ buttonCancel.setText(Messages.ManageDevicesDialog_CANCEL);
+ buttonCancel.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ resultDevicesList = null;
+ shell.close();
+ }
+ });
+
+
+ updateDevices();
+ }
+
+ public void updateDevices() {
+ table.removeAll();
+ for (Device device : devices) {
+ TableItem tableItem = new TableItem(table, SWT.NONE);
+ tableItem.setText(new String[] {device.getName(), String.valueOf(device.getWidth()), String.valueOf(device.getHeight()), device.getUserAgent()});
+ }
+ table.setSelection(selectedDeviceIndex);
+ }
+}
Copied: workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/Messages.java (from rev 36281, workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/Messages.java)
===================================================================
--- workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/Messages.java (rev 0)
+++ workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/Messages.java 2011-11-17 16:27:48 UTC (rev 36409)
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.browsersim.ui;
+
+import org.jboss.tools.browsersim.util.NLS;
+
+/**
+ * @author Yahor Radtsevich (yradtsevich)
+ */
+public class Messages {
+ private static final String BUNDLE_NAME = Messages.class.getName().toString().toLowerCase();
+ public static String BrowserSim_ADDRESS;
+ public static String BrowserSim_BROWSER_SIM;
+ public static String BrowserSim_COULD_NOT_INSTANTIATE_BROWSER;
+ public static String BrowserSim_DEVICES;
+ public static String BrowserSim_EXIT;
+ public static String BrowserSim_FILE;
+ public static String BrowserSim_MORE;
+ public static String EditDeviceDialog_CANCEL;
+ public static String EditDeviceDialog_EDIT_DEVICE;
+ public static String EditDeviceDialog_HEIGHT;
+ public static String EditDeviceDialog_MANAGE_DEVICES;
+ public static String EditDeviceDialog_NAME;
+ public static String EditDeviceDialog_OK;
+ public static String EditDeviceDialog_USER_AGENT;
+ public static String EditDeviceDialog_WIDTH;
+ public static String ManageDevicesDialog_ADD;
+ public static String ManageDevicesDialog_CANCEL;
+ public static String ManageDevicesDialog_DEVICES;
+ public static String ManageDevicesDialog_EDIT;
+ public static String ManageDevicesDialog_HEIGHT;
+ public static String ManageDevicesDialog_NAME;
+ public static String ManageDevicesDialog_NEW_DEVICE;
+ public static String ManageDevicesDialog_NEW_USER_AGENT;
+ public static String ManageDevicesDialog_OK;
+ public static String ManageDevicesDialog_REMOVE;
+ public static String ManageDevicesDialog_RESET;
+ public static String ManageDevicesDialog_LOAD_DEFAULTS;
+ public static String ManageDevicesDialog_USER_AGENT;
+ public static String ManageDevicesDialog_WIDTH;
+ static {
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
Copied: workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/messages.properties (from rev 36281, workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/messages.properties)
===================================================================
--- workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/messages.properties (rev 0)
+++ workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/ui/messages.properties 2011-11-17 16:27:48 UTC (rev 36409)
@@ -0,0 +1,29 @@
+BrowserSim_ADDRESS=Address
+BrowserSim_BROWSER_SIM=BrowserSim
+BrowserSim_COULD_NOT_INSTANTIATE_BROWSER=Could not instantiate Browser:
+BrowserSim_DEVICES=Devices
+BrowserSim_EXIT=Exit
+BrowserSim_FILE=File
+BrowserSim_MORE=More...
+EditDeviceDialog_CANCEL=Cancel
+EditDeviceDialog_EDIT_DEVICE=Edit Device
+EditDeviceDialog_HEIGHT=Height:
+EditDeviceDialog_MANAGE_DEVICES=Manage Devices
+EditDeviceDialog_NAME=Name:
+EditDeviceDialog_OK=OK
+EditDeviceDialog_USER_AGENT=User-Agent:
+EditDeviceDialog_WIDTH=Width:
+ManageDevicesDialog_ADD=Add
+ManageDevicesDialog_CANCEL=Cancel
+ManageDevicesDialog_DEVICES=Devices
+ManageDevicesDialog_EDIT=Edit
+ManageDevicesDialog_HEIGHT=Height
+ManageDevicesDialog_NAME=Name
+ManageDevicesDialog_NEW_DEVICE=New Device
+ManageDevicesDialog_NEW_USER_AGENT=New User-Agent
+ManageDevicesDialog_OK=OK
+ManageDevicesDialog_REMOVE=Remove
+ManageDevicesDialog_RESET=Reset
+ManageDevicesDialog_LOAD_DEFAULTS=Load Defaults
+ManageDevicesDialog_USER_AGENT=User-Agent
+ManageDevicesDialog_WIDTH=Width
Copied: workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/util/NLS.java (from rev 36281, workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/NLS.java)
===================================================================
--- workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/util/NLS.java (rev 0)
+++ workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/util/NLS.java 2011-11-17 16:27:48 UTC (rev 36409)
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.browsersim.util;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/**
+ * @author Yahor Radtsevich (yradtsevich)
+ */
+public class NLS {
+ private static final int MOD_EXPECTED = Modifier.PUBLIC | Modifier.STATIC;
+
+ private NLS(){};
+
+ public static void initializeMessages(Class<?> clazz) {
+ String bundleName = clazz.getName().toLowerCase();
+ initializeMessages(bundleName, clazz);
+ }
+
+ public static void initializeMessages(String bundleName, Class<?> clazz) {
+ ResourceBundle resourceBundle = ResourceBundle.getBundle(bundleName);
+
+ try {
+ for (Field field : clazz.getDeclaredFields()) {
+ // if it is a public static uninitialized String field
+ if ((field.getModifiers() & MOD_EXPECTED) == MOD_EXPECTED
+ && field.getType() == String.class
+ && field.get(null) == null) {
+ try {
+ field.set(null, resourceBundle.getString(field.getName()));
+ } catch (MissingResourceException e) {
+ field.set(null, '!' + field.getName() + '!');
+ }
+ }
+ }
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ }
+ }
+}
Added: workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/util/ResourcesUtil.java
===================================================================
--- workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/util/ResourcesUtil.java (rev 0)
+++ workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim/src/org/jboss/tools/browsersim/util/ResourcesUtil.java 2011-11-17 16:27:48 UTC (rev 36409)
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.browsersim.util;
+
+import java.io.InputStream;
+
+import org.jboss.tools.browsersim.ui.BrowserSim;
+
+/**
+ * @author Yahor Radtsevich (yradtsevich)
+ */
+public class ResourcesUtil {
+
+ public static InputStream getResourceAsStream(String name) {
+ return BrowserSim.class.getResourceAsStream(name);
+ }
+}
Modified: workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim.eclipse/src/org/jboss/tools/browsersim/eclipse/util/BrowserSimLauncher.java
===================================================================
--- workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim.eclipse/src/org/jboss/tools/browsersim/eclipse/util/BrowserSimLauncher.java 2011-11-17 14:54:19 UTC (rev 36408)
+++ workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim.eclipse/src/org/jboss/tools/browsersim/eclipse/util/BrowserSimLauncher.java 2011-11-17 16:27:48 UTC (rev 36409)
@@ -10,13 +10,13 @@
******************************************************************************/
package org.jboss.tools.browsersim.eclipse.util;
-import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.preferences.ConfigurationScope;
import org.jboss.tools.browsersim.webkit.PlatformUtil;
/**
@@ -43,15 +43,16 @@
commandElements.add("-cp");
commandElements.add(classPath);
- commandElements.add("org.jboss.tools.browsersim.BrowserSim");
+ commandElements.add("org.jboss.tools.browsersim.ui.BrowserSim");
if (initialUrl != null) {
commandElements.add(initialUrl);
}
try {
ProcessBuilder processBuilder = new ProcessBuilder(commandElements);
+ processBuilder.directory(ConfigurationScope.INSTANCE.getLocation().toFile());
Process browserSimProcess = processBuilder.start();
- BufferedInputStream j;
+
final InputStream errorStream = browserSimProcess.getErrorStream();
final InputStream inputStream = browserSimProcess.getInputStream();
new Thread() {
Modified: workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim.webkit/src/org/jboss/tools/browsersim/webkit/WebKitBrowserFactory.java
===================================================================
--- workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim.webkit/src/org/jboss/tools/browsersim/webkit/WebKitBrowserFactory.java 2011-11-17 14:54:19 UTC (rev 36408)
+++ workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim.webkit/src/org/jboss/tools/browsersim/webkit/WebKitBrowserFactory.java 2011-11-17 16:27:48 UTC (rev 36409)
@@ -30,7 +30,7 @@
} else if (PlatformUtil.CURRENT_PLATFORM.equals("win32.win32.x86")) {
return new WebKitBrowser_win32_win32_x86(parent, style);
}
-
+ //TODO: handle null properly in callers
return null;
}
}
Modified: workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim.webkit/src/org/jboss/tools/browsersim/webkit/internal/WebKitBrowser_webkit_cocoa_macos.java
===================================================================
--- workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim.webkit/src/org/jboss/tools/browsersim/webkit/internal/WebKitBrowser_webkit_cocoa_macos.java 2011-11-17 14:54:19 UTC (rev 36408)
+++ workspace/yradtsevich/browsersim/swt-webkit-browsersim/org.jboss.tools.browsersim.webkit/src/org/jboss/tools/browsersim/webkit/internal/WebKitBrowser_webkit_cocoa_macos.java 2011-11-17 16:27:48 UTC (rev 36409)
@@ -40,7 +40,7 @@
Method setCustomUserAgent = webView.getClass().getDeclaredMethod("setCustomUserAgent", NSString);
if (userAgent == null) {
- setCustomUserAgent.invoke(webView, null);
+ setCustomUserAgent.invoke(webView, (Object) null);
} else {
Method NSString_stringWith = NSString.getDeclaredMethod("stringWith", String.class);
//setCustomUserAgent.invoke(webView, org.eclipse.swt.internal.cocoa.NSString.stringWith(userAgent));
14 years, 5 months
JBoss Tools SVN: r36408 - in trunk/as/plugins: org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util and 2 other directories.
by jbosstools-commits@lists.jboss.org
Author: rob.stryker(a)jboss.com
Date: 2011-11-17 09:54:19 -0500 (Thu, 17 Nov 2011)
New Revision: 36408
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7/JBoss7LaunchConfigProperties.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7/LocalJBoss7ServerRuntime.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7/LocalJBoss7StartConfigurator.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/IJBossRuntimeConstants.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/Messages.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/Messages.properties
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/wizards/JBInitialSelectionProvider.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/wizards/JBoss7RuntimeWizardFragment.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/wizards/JBossConfigurationTableViewer.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/wizards/JBossRuntimeWizardFragment.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/wizards/StrippedServerWizardFragment.java
Log:
JBIDE-9336 - config for as7 and some copyrights
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7/JBoss7LaunchConfigProperties.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7/JBoss7LaunchConfigProperties.java 2011-11-17 14:27:50 UTC (rev 36407)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7/JBoss7LaunchConfigProperties.java 2011-11-17 14:54:19 UTC (rev 36408)
@@ -28,6 +28,15 @@
setProgramArguments(progArgs, launchConfig);
}
}
+ public void setConfigurationFile(String file, ILaunchConfigurationWorkingCopy launchConfig)
+ throws CoreException {
+ if (isSet(file)) {
+ String progArgs = getProgramArguments(launchConfig);
+ progArgs = ArgsUtil.setArg(progArgs,
+ null, IJBossRuntimeConstants.JB7_SERVER_CONFIG_ARG, file);
+ setProgramArguments(progArgs, launchConfig);
+ }
+ }
public void setBootLogFile(String blf, ILaunchConfigurationWorkingCopy launchConfig)
throws CoreException {
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7/LocalJBoss7ServerRuntime.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7/LocalJBoss7ServerRuntime.java 2011-11-17 14:27:50 UTC (rev 36407)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7/LocalJBoss7ServerRuntime.java 2011-11-17 14:54:19 UTC (rev 36408)
@@ -18,9 +18,10 @@
import org.jboss.ide.eclipse.as.core.util.IJBossRuntimeResourceConstants;
public class LocalJBoss7ServerRuntime extends LocalJBossServerRuntime implements IJBossRuntimeConstants {
+ public static final String CONFIG_FILE = "org.jboss.ide.eclipse.as.core.server.internal.v7.CONFIG_FILE"; //$NON-NLS-1$
+ public static final String CONFIG_FILE_DEFAULT = "standalone.xml"; //$NON-NLS-1$
-
@Override
public IStatus validate() {
return Status.OK_STATUS;
@@ -63,4 +64,11 @@
IPath loc = getRuntime().getLocation();
return getDefaultRunVMArgs(loc);
}
+
+ public String getConfigurationFile() {
+ return getAttribute(CONFIG_FILE, CONFIG_FILE_DEFAULT);
+ }
+ public void setConfigurationFile(String file) {
+ setAttribute(CONFIG_FILE, file);
+ }
}
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7/LocalJBoss7StartConfigurator.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7/LocalJBoss7StartConfigurator.java 2011-11-17 14:27:50 UTC (rev 36407)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/v7/LocalJBoss7StartConfigurator.java 2011-11-17 14:54:19 UTC (rev 36408)
@@ -61,6 +61,7 @@
getProperties().setUseDefaultClassPath(isUseDefaultClasspath(), launchConfig);
getProperties().setServerId(getServerId(jbossServer), launchConfig);
getProperties().setModulesFolder(getModulesFolder(jbossServer, jbossRuntime), launchConfig);
+ getProperties().setConfigurationFile(getServerConfigFile(jbossServer, jbossRuntime), launchConfig);
getProperties().setBootLogFile(getBootLogPath(jbossRuntime), launchConfig);
getProperties().setLoggingConfigFile(getLoggingConfigPath(jbossRuntime), launchConfig);
}
@@ -80,7 +81,13 @@
protected String getModulesFolder(JBossServer server, IJBossServerRuntime runtime) throws CoreException {
return runtime.getRuntime().getLocation().append(IJBossRuntimeConstants.MODULES).toString();
}
+
+ protected String getServerConfigFile(JBossServer server, IJBossServerRuntime runtime) throws CoreException {
+ LocalJBoss7ServerRuntime rt = (LocalJBoss7ServerRuntime)runtime.getRuntime().loadAdapter(LocalJBoss7ServerRuntime.class, null);
+ return rt.getConfigurationFile();
+ }
+
@Override
protected List<String> getClasspath(JBossServer server, IJBossServerRuntime runtime, List<String> currentClasspath) throws CoreException {
IVMInstall vmInstall = runtime.getVM();
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/IJBossRuntimeConstants.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/IJBossRuntimeConstants.java 2011-11-17 14:27:50 UTC (rev 36407)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/IJBossRuntimeConstants.java 2011-11-17 14:54:19 UTC (rev 36408)
@@ -47,6 +47,9 @@
public static final String PROGRAM_NAME_ARG = "program.name"; //$NON-NLS-1$
public static final String JB7_MP_ARG = "mp"; //$NON-NLS-1$
+ public static final String JB7_SERVER_CONFIG = "server-config"; //$NON-NLS-1$
+ public static final String JB7_SERVER_CONFIG_ARG = "--server-config"; //$NON-NLS-1$
+
public static final String MODULES = "modules"; //$NON-NLS-1$
public static final String JB7_LOGMODULE_ARG = "logmodule"; //$NON-NLS-1$
public static final String JB7_LOGMODULE_DEFAULT = "org.jboss.logmanager"; //$NON-NLS-1$
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/Messages.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/Messages.java 2011-11-17 14:27:50 UTC (rev 36407)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/Messages.java 2011-11-17 14:54:19 UTC (rev 36408)
@@ -65,6 +65,7 @@
public static String rwf_jre6NotFound;
public static String rwf_noValidJRE;
public static String rwf_DefaultJREForExecEnv;
+ public static String rwf7_ConfigFileError;
public static String swf_Title;
public static String swf_RuntimeInformation;
public static String swf_AuthorizationDescription;
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/Messages.properties
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/Messages.properties 2011-11-17 14:27:50 UTC (rev 36407)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/Messages.properties 2011-11-17 14:54:19 UTC (rev 36408)
@@ -23,6 +23,7 @@
rwf_jre6NotFound=No Java 6 runtime environment found
rwf_noValidJRE=No valid JREs found for execution environment "{0}"
rwf_DefaultJREForExecEnv=Default JRE for {0}
+rwf7_ConfigFileError=Configuration file is not found: {0}
J2EEModuleExportOperation_could_not_export_module=Could not export module {1} to {0}.
J2EEModuleExportOperation_ErrorExportingArchive=Error Exporting Archive: {0}
JBAS_version=JBoss Application Server {0}
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/wizards/JBInitialSelectionProvider.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/wizards/JBInitialSelectionProvider.java 2011-11-17 14:27:50 UTC (rev 36407)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/wizards/JBInitialSelectionProvider.java 2011-11-17 14:54:19 UTC (rev 36408)
@@ -1,24 +1,13 @@
-/**
- * JBoss by Red Hat
- * Copyright 2006-2009, Red Hat Middleware, LLC, and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
*
-* This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.jboss.ide.eclipse.as.ui.wizards;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/wizards/JBoss7RuntimeWizardFragment.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/wizards/JBoss7RuntimeWizardFragment.java 2011-11-17 14:27:50 UTC (rev 36407)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/wizards/JBoss7RuntimeWizardFragment.java 2011-11-17 14:54:19 UTC (rev 36408)
@@ -1,3 +1,13 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.jboss.ide.eclipse.as.ui.wizards;
import java.io.File;
@@ -11,14 +21,28 @@
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
import org.eclipse.wst.server.core.IRuntime;
import org.eclipse.wst.server.core.IRuntimeWorkingCopy;
import org.eclipse.wst.server.core.TaskModel;
import org.jboss.ide.eclipse.as.core.server.IJBossServerRuntime;
import org.jboss.ide.eclipse.as.core.server.bean.JBossServerType;
+import org.jboss.ide.eclipse.as.core.server.internal.v7.LocalJBoss7ServerRuntime;
+import org.jboss.ide.eclipse.as.core.util.IJBossRuntimeResourceConstants;
import org.jboss.ide.eclipse.as.ui.JBossServerUIPlugin;
import org.jboss.ide.eclipse.as.ui.Messages;
+import org.jboss.ide.eclipse.as.ui.UIUtil;
public class JBoss7RuntimeWizardFragment extends JBossRuntimeWizardFragment {
@@ -38,8 +62,86 @@
createNameComposite(main);
createHomeComposite(main);
createJREComposite(main);
+ createConfigurationComposite(main);
}
+ protected void createConfigurationComposite(Composite main) {
+ UIUtil u = new UIUtil(); // top bottom left right
+ configComposite = new Composite(main, SWT.NONE);
+ configComposite.setLayoutData(u.createFormData(
+ jreComposite, 10, 100, -5, 0, 5, 100, -5));
+ configComposite.setLayout(new FormLayout());
+
+ configDirLabel = new Label(configComposite, SWT.NONE);
+ configDirLabel.setText("Configuration file: ");
+ configDirText = new Text(configComposite, SWT.BORDER);
+
+ configBrowse = new Button(configComposite, SWT.DEFAULT);
+ configBrowse.setText(Messages.browse);
+
+ // Organize them
+ configDirLabel.setLayoutData(u.createFormData(
+ 0, 7, null, 0, 0, 5, null, 0));
+ configDirText.setLayoutData(u.createFormData(
+ 0, 5, null, 0, configDirLabel, 5, configBrowse, -5));
+ configBrowse.setLayoutData(u.createFormData(
+ 0, 5, null, 0, null, 0, 100, -5));
+
+ configDirText.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ configDirTextVal = configDirText.getText();
+ updatePage();
+ }
+ });
+
+ configBrowse.addSelectionListener(new SelectionListener(){
+ public void widgetSelected(SelectionEvent e) {
+ configBrowsePressed();
+ }
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ });
+
+ }
+
+ protected void configBrowsePressed() {
+ String folder = new Path(configDirText.getText()).isAbsolute() ?
+ configDirText.getText() : new Path(homeDir).append(configDirText.getText()).toString();
+ File file = new File(folder);
+ if (!file.exists()) {
+ file = null;
+ }
+
+ File ffile = getFile(file, homeDirComposite.getShell());
+ if (ffile != null) {
+ if(ffile.getAbsolutePath().startsWith(new Path(homeDir).toString())) {
+ String result = ffile.getAbsolutePath().substring(homeDir.length());
+ configDirText.setText(new Path(result).makeRelative().toString());
+ } else {
+ configDirText.setText(ffile.getAbsolutePath());
+ }
+ }
+ configDirTextVal = configDirText.getText();
+ }
+
+
+ protected static File getFile(File startingDirectory, Shell shell) {
+ FileDialog fileDialog = new FileDialog(shell, SWT.OPEN);
+ if (startingDirectory != null) {
+ fileDialog.setFilterPath(startingDirectory.getPath());
+ }
+
+ String dir = fileDialog.open();
+ if (dir != null) {
+ dir = dir.trim();
+ if (dir.length() > 0) {
+ return new File(dir);
+ }
+ }
+ return null;
+ }
+
+
protected void fillWidgets() {
IRuntime rt = (IRuntime) getTaskModel().getObject(TaskModel.TASK_RUNTIME);
@@ -47,6 +149,7 @@
try {
fillNameWidgets(rt);
fillHomeDir(rt);
+ fillConfigWidgets(rt);
fillJREWidgets(rt);
} catch (Exception e) {
IStatus status = new Status(IStatus.ERROR, JBossServerUIPlugin.PLUGIN_ID, MessageFormat.format(Messages.JBoss7ServerWizardFragment_could_not_create_ui, rt.getName()), e);
@@ -55,6 +158,11 @@
}
}
+ protected void fillConfigWidgets(IRuntime rt) {
+ LocalJBoss7ServerRuntime rt2 = (LocalJBoss7ServerRuntime)rt.loadAdapter(LocalJBoss7ServerRuntime.class, null);
+ configDirText.setText(rt2.getConfigurationFile());
+ }
+
@Override
protected void updatePage() {
int sel = jreCombo.getSelectionIndex();
@@ -63,6 +171,7 @@
selectedVM = installedJREs.get(sel + offset);
else // if sel < 0 or sel == 0 and offset == -1
selectedVM = null;
+ configDirTextVal = configDirText.getText();
updateErrorMessage();
}
@@ -79,7 +188,16 @@
if (name == null || name.equals("")) //$NON-NLS-1$
return Messages.rwf_nameTextBlank;
-
+
+ if( configDirTextVal != null) {
+ IPath p = new Path(configDirTextVal);
+ IPath actualPath = p.isAbsolute() ? p : new Path(homeDir)
+ .append(IJBossRuntimeResourceConstants.AS7_STANDALONE)
+ .append(IJBossRuntimeResourceConstants.CONFIGURATION).append(p);
+ if( !actualPath.toFile().exists()) {
+ return Messages.bind(Messages.rwf7_ConfigFileError, actualPath.toString());
+ }
+ }
return null;
}
@@ -103,6 +221,7 @@
@Override
public void performFinish(IProgressMonitor monitor) throws CoreException {
+ exit();
IRuntime rt = (IRuntime) getTaskModel().getObject(TaskModel.TASK_RUNTIME);
((IRuntimeWorkingCopy) rt).setLocation(new Path(homeDir));
}
@@ -116,9 +235,10 @@
runtimeWC.setName(name);
runtimeWC.setLocation(new Path(homeDir));
- IJBossServerRuntime srt = (IJBossServerRuntime) runtimeWC.loadAdapter(
- IJBossServerRuntime.class, new NullProgressMonitor());
+ LocalJBoss7ServerRuntime srt = (LocalJBoss7ServerRuntime) runtimeWC.loadAdapter(
+ LocalJBoss7ServerRuntime.class, new NullProgressMonitor());
srt.setVM(selectedVM);
+ srt.setConfigurationFile(configDirTextVal);
getTaskModel().putObject(TaskModel.TASK_RUNTIME, runtimeWC);
}
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/wizards/JBossConfigurationTableViewer.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/wizards/JBossConfigurationTableViewer.java 2011-11-17 14:27:50 UTC (rev 36407)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/wizards/JBossConfigurationTableViewer.java 2011-11-17 14:54:19 UTC (rev 36408)
@@ -1,24 +1,13 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
*
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.jboss.ide.eclipse.as.ui.wizards;
import java.io.File;
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/wizards/JBossRuntimeWizardFragment.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/wizards/JBossRuntimeWizardFragment.java 2011-11-17 14:27:50 UTC (rev 36407)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/wizards/JBossRuntimeWizardFragment.java 2011-11-17 14:54:19 UTC (rev 36408)
@@ -1,24 +1,13 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
*
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.jboss.ide.eclipse.as.ui.wizards;
import java.io.File;
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/wizards/StrippedServerWizardFragment.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/wizards/StrippedServerWizardFragment.java 2011-11-17 14:27:50 UTC (rev 36407)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/wizards/StrippedServerWizardFragment.java 2011-11-17 14:54:19 UTC (rev 36408)
@@ -1,24 +1,13 @@
-/**
- * JBoss by Red Hat
- * Copyright 2006-2009, Red Hat Middleware, LLC, and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
*
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.jboss.ide.eclipse.as.ui.wizards;
import java.io.File;
14 years, 5 months
JBoss Tools SVN: r36407 - trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util.
by jbosstools-commits@lists.jboss.org
Author: dmaliarevich
Date: 2011-11-17 09:27:50 -0500 (Thu, 17 Nov 2011)
New Revision: 36407
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java
Log:
https://issues.jboss.org/browse/JBIDE-10178 - [^;] replaced by .
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java 2011-11-17 14:22:43 UTC (rev 36406)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java 2011-11-17 14:27:50 UTC (rev 36407)
@@ -77,7 +77,7 @@
* Java regexp pattern to match css path from the url(..) construction.
* It's implied that the css string has only one URL in it.
*/
- public static final Pattern CSS_URL_PATTERN = Pattern.compile("(?<=\\burl\\b)(?:[\\p{Space}]*\\()[\\p{Space}]*([^;]*)[\\p{Space}]*(?:\\)[\\p{Space}]*)(?=(?>[^\\)]*;|[^\\)]*))"); //$NON-NLS-1$
+ public static final Pattern CSS_URL_PATTERN = Pattern.compile("(?<=\\burl\\b)(?:[\\p{Space}]*\\()[\\p{Space}]*(.*)[\\p{Space}]*(?:\\)[\\p{Space}]*)(?=(?>[^\\)]*;|[^\\)]*))"); //$NON-NLS-1$
public static String ATTR_URL = "url"; //$NON-NLS-1$
public static String OPEN_BRACKET = "("; //$NON-NLS-1$
14 years, 5 months
JBoss Tools SVN: r36406 - trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard.
by jbosstools-commits@lists.jboss.org
Author: adietish
Date: 2011-11-17 09:22:43 -0500 (Thu, 17 Nov 2011)
New Revision: 36406
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationWizardPage.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPage.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPageModel.java
Log:
[JBIDE-9927] creating a jenkins app if there's none so far and user checks "jenkins" cartridge to be embedded into his app.
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationWizardPage.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationWizardPage.java 2011-11-17 13:57:09 UTC (rev 36405)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationWizardPage.java 2011-11-17 14:22:43 UTC (rev 36406)
@@ -283,21 +283,24 @@
"You're up to delete all data within an application. The data may not be recovered. "
+ "Are you sure that you want to delete application {0}?",
model.getSelectedApplication().getName()))) {
- WizardUtils.runInWizard(new Job("Deleting application") {
+ WizardUtils.runInWizard(
+ new Job(NLS.bind("Deleting application \"{0}\"...",
+ model.getSelectedApplication().getName())) {
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- try {
- model.destroyCurrentApplication();
- refreshViewer();
- return Status.OK_STATUS;
- } catch (OpenShiftException e) {
- return new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID, NLS.bind(
- "Could not delete application \"{0}\"",
- model.getSelectedApplication().getName()));
- }
- }
- }, getContainer(), dbc);
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ model.destroyCurrentApplication();
+ refreshViewer();
+ return Status.OK_STATUS;
+ } catch (OpenShiftException e) {
+ return OpenShiftUIActivator.createErrorStatus(
+ NLS.bind("Could not delete application \"{0}\"",
+ model.getSelectedApplication().getName())
+ , e);
+ }
+ }
+ }, getContainer(), dbc);
}
} catch (Exception ex) {
// ignore
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPage.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPage.java 2011-11-17 13:57:09 UTC (rev 36405)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPage.java 2011-11-17 14:22:43 UTC (rev 36406)
@@ -18,6 +18,9 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IInputValidator;
+import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
@@ -36,10 +39,13 @@
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.jboss.tools.common.ui.WizardUtils;
+import org.jboss.tools.openshift.express.client.ICartridge;
import org.jboss.tools.openshift.express.client.IEmbeddableCartridge;
import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
+import org.jboss.tools.openshift.express.internal.ui.common.StringUtils;
/**
* @author André Dietisheim
@@ -103,10 +109,10 @@
layout.setColumnData(column.getColumn(), new ColumnWeightData(weight, true));
}
-
+
private ICheckStateListener onEmbeddableCartridgeChecked() {
return new ICheckStateListener() {
-
+
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
IEmbeddableCartridge cartridge = (IEmbeddableCartridge) event.getElement();
@@ -125,12 +131,39 @@
}
private void addJenkinsCartridge(IEmbeddableCartridge cartridge) {
- model.getSelectedEmbeddableCartridges().add(cartridge);
+ if (model.hasApplication(ICartridge.JENKINS_14)) {
+ model.getSelectedEmbeddableCartridges().add(cartridge);
+ } else {
+ final JenkinsApplicationDialog dialog = new JenkinsApplicationDialog(getShell());
+ if (dialog.open() == Dialog.OK) {
+ try {
+ WizardUtils.runInWizard(new Job("Loading embeddable cartridges...") {
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ model.createJenkinsApplication(dialog.getValue());
+ return Status.OK_STATUS;
+ } catch (Exception e) {
+ clearCartridgesViewer();
+ return new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
+ "Could not load embeddable cartridges", e);
+ }
+ }
+
+ }, getContainer(), getDataBindingContext());
+ model.getSelectedEmbeddableCartridges().add(cartridge);
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+ }
}
private void addPhpMyACartridge(IEmbeddableCartridge cartridge) {
- MessageDialog.openQuestion(getShell(), "Enable MySQL cartridge", "To embed PhpMyAdmin, you'd also have to embed MySql. ");
- model.getSelectedEmbeddableCartridges().add(cartridge);
+ MessageDialog.openQuestion(getShell(), "Enable MySQL cartridge",
+ "To embed PhpMyAdmin, you'd also have to embed MySql. ");
+ model.getSelectedEmbeddableCartridges().add(cartridge);
}
@Override
@@ -154,7 +187,6 @@
} catch (Exception e) {
// ignore
}
-
}
private void clearCartridgesViewer() {
@@ -170,4 +202,33 @@
}
});
}
+
+ private static class JenkinsApplicationDialog extends InputDialog {
+
+ public JenkinsApplicationDialog(Shell shell) {
+ super(shell
+ , "New Jenkins application"
+ , "To embed jenkins into your application you'd first have to create a jenkins application. "
+ + "Please provide it's name"
+ , null
+ , new JenkinsNameValidator());
+ }
+
+ protected int getInputTextStyle() {
+ return SWT.SINGLE | SWT.BORDER | SWT.PASSWORD;
+ }
+
+ private static class JenkinsNameValidator implements IInputValidator {
+
+ @Override
+ public String isValid(String input) {
+ if (StringUtils.isEmpty(input)) {
+ return "You have to provide a name for the jenkins application";
+ }
+ return null;
+ }
+ }
+ }
+
+
}
\ No newline at end of file
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPageModel.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPageModel.java 2011-11-17 13:57:09 UTC (rev 36405)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPageModel.java 2011-11-17 14:22:43 UTC (rev 36406)
@@ -14,6 +14,7 @@
import java.util.List;
import org.jboss.tools.common.ui.databinding.ObservableUIPojo;
+import org.jboss.tools.openshift.express.client.IApplication;
import org.jboss.tools.openshift.express.client.ICartridge;
import org.jboss.tools.openshift.express.client.IEmbeddableCartridge;
import org.jboss.tools.openshift.express.client.OpenShiftException;
@@ -67,4 +68,8 @@
return false;
}
}
+
+ public void createJenkinsApplication(String name) throws OpenShiftException {
+ IApplication application = wizardModel.getUser().createApplication(name, ICartridge.JENKINS_14);
+ }
}
14 years, 5 months
JBoss Tools SVN: r36405 - trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util.
by jbosstools-commits@lists.jboss.org
Author: dmaliarevich
Date: 2011-11-17 08:57:09 -0500 (Thu, 17 Nov 2011)
New Revision: 36405
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java
Log:
https://issues.jboss.org/browse/JBIDE-10178 - Java regexp pattern to match css path from the url(..) construction was updated.
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java 2011-11-17 13:51:29 UTC (rev 36404)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java 2011-11-17 13:57:09 UTC (rev 36405)
@@ -73,7 +73,12 @@
public static final String EMPTY_STRING = ""; //$NON-NLS-1$
public static final String SINGLE_QUOTE_STRING = "\'"; //$NON-NLS-1$
public static final String QUOTE_STRING = "\""; //$NON-NLS-1$
-
+ /*
+ * Java regexp pattern to match css path from the url(..) construction.
+ * It's implied that the css string has only one URL in it.
+ */
+ public static final Pattern CSS_URL_PATTERN = Pattern.compile("(?<=\\burl\\b)(?:[\\p{Space}]*\\()[\\p{Space}]*([^;]*)[\\p{Space}]*(?:\\)[\\p{Space}]*)(?=(?>[^\\)]*;|[^\\)]*))"); //$NON-NLS-1$
+
public static String ATTR_URL = "url"; //$NON-NLS-1$
public static String OPEN_BRACKET = "("; //$NON-NLS-1$
public static String CLOSE_BRACKET = ")"; //$NON-NLS-1$
@@ -493,11 +498,12 @@
* https://issues.jboss.org/browse/JBIDE-10178
* The index of closing bracket was wrong.
* Thus replaced with java regexp.
+ */
+ Matcher m = CSS_URL_PATTERN.matcher(url);
+ String[] res = null;
+ /*
+ * It's implied that the "url" string has only one URL in it.
*/
- String urlRegExp = "(?<=\\burl\\b)\\((.*)\\)(?=(?>[^\\)]*;|[^\\)]*))"; //$NON-NLS-1$
- Pattern p = Pattern.compile(urlRegExp);
- Matcher m = p.matcher(url);
- String[] res = null;
if (m.find()) {
res = new String[3];
/*
14 years, 5 months
JBoss Tools SVN: r36404 - in trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui: buildpath/dialog and 1 other directory.
by jbosstools-commits@lists.jboss.org
Author: fbricon
Date: 2011-11-17 08:51:29 -0500 (Thu, 17 Nov 2011)
New Revision: 36404
Added:
trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/buildpath/dialog/IMaterializeLibraryWarningFactory.java
trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/buildpath/dialog/MaterializeLibraryWarningFactory.java
Modified:
trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/Messages.java
trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/buildpath/dialog/MaterializeLibraryDialog.java
trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/messages.properties
Log:
JBIDE-9878 : Add warnings for when the Maven or JRE libraries are about to be materialized
Modified: trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/Messages.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/Messages.java 2011-11-17 13:03:18 UTC (rev 36403)
+++ trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/Messages.java 2011-11-17 13:51:29 UTC (rev 36404)
@@ -15,13 +15,21 @@
/**
*
* @author Fred Bricon
- *
+ *
*/
public class Messages extends NLS {
private static final String BUNDLE_NAME = "org.jboss.tools.common.jdt.ui.messages"; //$NON-NLS-1$
-
+
public static String Materialize_Library;
-
+
+ public static String Maven_Configuration_Warning;
+
+ public static String Maven_Configuration_Dialog_Warning;
+
+ public static String Jre_Warning;
+
+ public static String Jre_Dialog_Warning;
+
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
Added: trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/buildpath/dialog/IMaterializeLibraryWarningFactory.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/buildpath/dialog/IMaterializeLibraryWarningFactory.java (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/buildpath/dialog/IMaterializeLibraryWarningFactory.java 2011-11-17 13:51:29 UTC (rev 36404)
@@ -0,0 +1,36 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2011 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.common.jdt.ui.buildpath.dialog;
+
+import org.eclipse.jdt.core.IClasspathContainer;
+
+/**
+ * Warning message factory for classpath libraries to be materialized.
+ *
+ * @author Fred Bricon
+ *
+ */
+public interface IMaterializeLibraryWarningFactory {
+
+ /**
+ * Returns a simple warning message associated with the materialization of a classpath library.
+ * @return a warning message or <code>null</code> if it doesn't apply.
+ */
+ String getWarning(IClasspathContainer classpathLibrary);
+
+ /**
+ * Returns a warning message associated with the materialization of a classpath library.
+ * This message is destined to be displayed in a dialog window.
+ * @return a warning message associated with the materialization of a classpath library,
+ * or <code>null</code> if it doesn't apply.
+ */
+ String getDialogWarning(IClasspathContainer classpathLibrary);
+}
Modified: trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/buildpath/dialog/MaterializeLibraryDialog.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/buildpath/dialog/MaterializeLibraryDialog.java 2011-11-17 13:03:18 UTC (rev 36403)
+++ trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/buildpath/dialog/MaterializeLibraryDialog.java 2011-11-17 13:51:29 UTC (rev 36404)
@@ -26,7 +26,12 @@
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IClasspathContainer;
import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.CheckStateChangedEvent;
@@ -37,12 +42,14 @@
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.TextCellEditor;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
@@ -82,7 +89,13 @@
private Button keepSourceBtn;
private boolean keepSources;
+
+ private IMaterializeLibraryWarningFactory warningfactory;
+ private Label warningImg;
+
+ private Label warningLabel;
+
public MaterializeLibraryDialog(Shell shell, IProject project, IClasspathContainer containerToMaterialize, String defaultLib) {
super(shell);
setShellStyle(super.getShellStyle() | SWT.RESIZE | SWT.MODELESS);
@@ -90,6 +103,7 @@
IPath folderPath = project.getFullPath().append(defaultLib);
libFolder = ResourcesPlugin.getWorkspace().getRoot().getFolder(folderPath);
this.containerToMaterialize = containerToMaterialize;
+ warningfactory = new MaterializeLibraryWarningFactory();
initClasspathEntryPaths();
}
@@ -132,10 +146,14 @@
layout.marginLeft = 12;
container.setLayout(layout);
container.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ String message = NLS.bind("Copy selected jars from {0} to the destination folder.",libName);
+ String warning = warningfactory.getWarning(containerToMaterialize);
+ if (warning != null) {
+ displayWarning(container, warning);
+ }
+ setMessage(message);
- setMessage("Copy selected jars from " + libName
- + " to the destination folder.");
-
Label libFolderLabel = new Label(container, SWT.NONE);
libFolderLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,
false, 1, 1));
@@ -159,6 +177,21 @@
return area;
}
+
+ private void displayWarning(Composite container, String warning) {
+ Composite composite = new Composite(container, SWT.NONE);
+ GridDataFactory.fillDefaults().align(SWT.LEFT,SWT.CENTER).span(3,1).applyTo(composite);
+ GridLayoutFactory.fillDefaults().numColumns(2).applyTo(composite);
+ warningImg = new Label(composite, SWT.CENTER);
+ warningImg.setImage(JFaceResources.getImage(DLG_IMG_MESSAGE_WARNING));
+ GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(warningImg);
+ warningLabel = new Label(composite, SWT.NONE);
+ warningLabel.setText(warning);
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(warningLabel);
+ }
+
+
+
private void addSelectFolderButton(Composite container) {
Button button = new Button(container, SWT.NONE);
@@ -201,7 +234,7 @@
gd.widthHint = 550;
classpathEntriesViewer = CheckboxTableViewer.newCheckList(container,
- SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
+ SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION );
Table table = classpathEntriesViewer.getTable();
table.setFocus();
table.setLayoutData(gd);
@@ -285,6 +318,18 @@
if (!validate()) {
return;
}
+
+ String dialogWarning = warningfactory.getDialogWarning(containerToMaterialize);
+ if (dialogWarning != null) {
+ String[] buttonLabels = new String[] { IDialogConstants.OK_LABEL,
+ IDialogConstants.CANCEL_LABEL };
+
+ MessageDialog dialog = new MessageDialog(getShell(), getShell().getText(), null, dialogWarning,
+ MessageDialog.WARNING, buttonLabels, 0);
+ if (dialog.open() == CANCEL) {
+ return;
+ }
+ }
libFolder = getLibFolderFromText(libfolderText.getText());
keepSources = keepSourceBtn.getSelection();
super.okPressed();
Added: trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/buildpath/dialog/MaterializeLibraryWarningFactory.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/buildpath/dialog/MaterializeLibraryWarningFactory.java (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/buildpath/dialog/MaterializeLibraryWarningFactory.java 2011-11-17 13:51:29 UTC (rev 36404)
@@ -0,0 +1,53 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2011 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+package org.jboss.tools.common.jdt.ui.buildpath.dialog;
+
+import org.eclipse.jdt.core.IClasspathContainer;
+import org.eclipse.osgi.util.NLS;
+import org.jboss.tools.common.jdt.ui.Messages;
+
+public class MaterializeLibraryWarningFactory implements IMaterializeLibraryWarningFactory {
+
+ @Override
+ public String getWarning(IClasspathContainer classpathLibrary) {
+ if (isMavenLibrary(classpathLibrary)) {
+ return Messages.Maven_Configuration_Warning;
+ } else if (isJreLibrary(classpathLibrary)) {
+ return NLS.bind(Messages.Jre_Warning, classpathLibrary.getDescription());
+ }
+ return null;
+ }
+
+ @Override
+ public String getDialogWarning(IClasspathContainer classpathLibrary) {
+ if (isMavenLibrary(classpathLibrary)) {
+ return Messages.Maven_Configuration_Dialog_Warning;
+ } else if (isJreLibrary(classpathLibrary)) {
+ return NLS.bind(Messages.Jre_Dialog_Warning, classpathLibrary.getDescription());
+ }
+ return null;
+ }
+
+ private boolean isJreLibrary(IClasspathContainer classpathLibrary) {
+ return applies(classpathLibrary, "org.eclipse.jdt.launching.JRE_CONTAINER");
+ }
+
+ private boolean isMavenLibrary(IClasspathContainer classpathLibrary) {
+ return applies(classpathLibrary, "org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER");
+ }
+
+ private boolean applies(IClasspathContainer classpathLibrary, String libPrefix) {
+ return classpathLibrary != null
+ && classpathLibrary.getPath() != null
+ && classpathLibrary.getPath().toPortableString().startsWith(libPrefix);
+ }
+
+}
Modified: trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/messages.properties
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/messages.properties 2011-11-17 13:03:18 UTC (rev 36403)
+++ trunk/common/plugins/org.jboss.tools.common.jdt.ui/src/org/jboss/tools/common/jdt/ui/messages.properties 2011-11-17 13:51:29 UTC (rev 36404)
@@ -1,3 +1,7 @@
Materialize_Library=Materialize Library
+
+Maven_Configuration_Warning =This will also remove the Maven configuration from this project.
+Maven_Configuration_Dialog_Warning = This will also remove the Maven configuration from this project.\nThis operation cannot be undone, are you sure ?
+Jre_Warning = Materializing {0} might have unexpected consequences and is not recommended.
+Jre_Dialog_Warning = Materializing {0} might have unexpected consequences and is not recommended. Are you sure?
-
14 years, 5 months
JBoss Tools SVN: r36403 - trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard.
by jbosstools-commits@lists.jboss.org
Author: adietish
Date: 2011-11-17 08:03:18 -0500 (Thu, 17 Nov 2011)
New Revision: 36403
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationWizardModel.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizard.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizard.java
Removed:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationDialog.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardModel.java
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationWizardPage.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPage.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPageModel.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardPage.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardPageModel.java
Log:
[JBIDE-9927] added "embed" button and wizard to applications page
Added: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationWizardModel.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationWizardModel.java (rev 0)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationWizardModel.java 2011-11-17 13:03:18 UTC (rev 36403)
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.openshift.express.internal.ui.wizard;
+
+import org.jboss.tools.common.ui.databinding.ObservableUIPojo;
+import org.jboss.tools.openshift.express.client.IApplication;
+import org.jboss.tools.openshift.express.client.ICartridge;
+import org.jboss.tools.openshift.express.client.IUser;
+import org.jboss.tools.openshift.express.client.OpenShiftException;
+
+/**
+ * @author André Dietisheim
+ */
+public class ApplicationWizardModel extends ObservableUIPojo {
+
+ public static final String PROPERTY_APPLICATION = "application";
+
+ private IUser user;
+ private IApplication application;
+ private String name;
+ private ICartridge cartridge;
+
+ public ApplicationWizardModel(IUser user) {
+ this.user = user;
+ }
+
+ public IUser getUser() {
+ return user;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String setName(String name) {
+ return this.name = name;
+ }
+
+ public void setCartridge(ICartridge cartridge) {
+ this.cartridge = cartridge;
+ }
+
+ public void createApplication() throws OpenShiftException {
+ createApplication(name, cartridge);
+ }
+
+
+ public void setApplication(IApplication application) {
+ firePropertyChange(PROPERTY_APPLICATION, this.application, this.application = application);
+ }
+
+ public IApplication getApplication() {
+ return application;
+ }
+
+ public void createApplication(String name, ICartridge cartridge) throws OpenShiftException {
+ IApplication application = getUser().createApplication(name, cartridge);
+ setApplication(application);
+ }
+
+}
Property changes on: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationWizardModel.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationWizardPage.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationWizardPage.java 2011-11-17 12:05:44 UTC (rev 36402)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationWizardPage.java 2011-11-17 13:03:18 UTC (rev 36403)
@@ -90,7 +90,7 @@
domainGroup.setText("Domain");
GridDataFactory.fillDefaults()
.grab(true, false).align(SWT.FILL, SWT.TOP).span(3, 1).applyTo(domainGroup);
- GridLayoutFactory.fillDefaults().margins(6, 6).numColumns(3).applyTo(domainGroup);
+ GridLayoutFactory.fillDefaults().margins(6, 6).numColumns(4).applyTo(domainGroup);
Label namespaceLabel = new Label(domainGroup, SWT.NONE);
namespaceLabel.setText("&Domain name");
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(namespaceLabel);
@@ -123,11 +123,11 @@
applicationGroup.setText("Available Applications");
GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).hint(400, 260).span(3, 1)
.applyTo(applicationGroup);
- GridLayoutFactory.fillDefaults().numColumns(3).margins(6, 6).applyTo(applicationGroup);
+ GridLayoutFactory.fillDefaults().numColumns(4).margins(6, 6).applyTo(applicationGroup);
Composite tableContainer = new Composite(applicationGroup, SWT.NONE);
this.viewer = createTable(tableContainer);
- GridDataFactory.fillDefaults().span(3, 1).align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(tableContainer);
+ GridDataFactory.fillDefaults().span(4, 1).align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(tableContainer);
viewer.addDoubleClickListener(onApplicationDoubleClick());
Binding selectedApplicationBinding = dbc.bindValue(
ViewerProperties.singleSelection().observe(viewer),
@@ -140,7 +140,8 @@
return ValidationStatus.ok();
}
else {
- return ValidationStatus.info("Please select an application to start with, or create a new one");
+ return ValidationStatus
+ .info("Please select an application to start with, or create a new one");
}
}
}),
@@ -157,6 +158,12 @@
DataBindingUtils.bindEnablementToValidationStatus(deleteButton, IStatus.OK, dbc, selectedApplicationBinding);
deleteButton.addSelectionListener(onDelete(dbc));
+ Button embedButton = new Button(applicationGroup, SWT.PUSH);
+ embedButton.setText("E&mbed");
+ GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).hint(80, SWT.DEFAULT).applyTo(embedButton);
+ DataBindingUtils.bindEnablementToValidationStatus(embedButton, IStatus.OK, dbc, selectedApplicationBinding);
+ embedButton.addSelectionListener(onEmbed(dbc));
+
Button detailsButton = new Button(applicationGroup, SWT.PUSH);
detailsButton.setText("De&tails");
GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).grab(true, false).hint(80, SWT.DEFAULT)
@@ -305,7 +312,7 @@
@Override
public void widgetSelected(SelectionEvent e) {
Shell shell = getContainer().getShell();
- NewApplicationDialog applicationDialog = new NewApplicationDialog(model.getUser());
+ NewApplicationWizard applicationDialog = new NewApplicationWizard(model.getUser());
if (WizardUtils.openWizardDialog(applicationDialog, shell) == Dialog.OK) {
viewer.refresh();
model.setSelectedApplication(applicationDialog.getApplication());
@@ -314,6 +321,16 @@
};
}
+ private SelectionAdapter onEmbed(final DataBindingContext dbc) {
+ return new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ WizardUtils.openWizardDialog(new EmbedCartridgeWizard(model.getUser()), getShell());
+ }
+ };
+ }
+
private SelectionAdapter onDetails(DataBindingContext dbc) {
return new SelectionAdapter() {
Added: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizard.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizard.java (rev 0)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizard.java 2011-11-17 13:03:18 UTC (rev 36403)
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.openshift.express.internal.ui.wizard;
+
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.osgi.util.NLS;
+import org.jboss.tools.common.ui.WizardUtils;
+import org.jboss.tools.openshift.express.client.IApplication;
+import org.jboss.tools.openshift.express.client.IUser;
+import org.jboss.tools.openshift.express.client.OpenShiftException;
+import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
+
+/**
+ * @author André Dietisheim
+ */
+public class EmbedCartridgeWizard extends Wizard {
+
+ private ApplicationWizardModel wizardModel;
+
+ public EmbedCartridgeWizard(IUser user) {
+ this.wizardModel = new ApplicationWizardModel(user);
+ setNeedsProgressMonitor(true);
+ }
+
+ @Override
+ public boolean performFinish() {
+ final ArrayBlockingQueue<Boolean> queue = new ArrayBlockingQueue<Boolean>(1);
+ try {
+ WizardUtils.runInWizard(new Job(NLS.bind("Creating application \"{0}\"...", wizardModel.getName())) {
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ wizardModel.createApplication();
+ queue.offer(true);
+ } catch (OpenShiftException e) {
+ queue.offer(false);
+ return new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
+ NLS.bind("Could not create application \"{0}\"", wizardModel.getName()), e);
+ }
+ return Status.OK_STATUS;
+ }
+ }, getContainer());
+ return queue.poll(10, TimeUnit.SECONDS);
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ @Override
+ public void addPages() {
+ addPage(new EmbedCartridgeWizardPage(wizardModel, this));
+ }
+
+ public IApplication getApplication() {
+ return wizardModel.getApplication();
+ }
+}
Property changes on: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizard.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPage.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPage.java 2011-11-17 12:05:44 UTC (rev 36402)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPage.java 2011-11-17 13:03:18 UTC (rev 36403)
@@ -49,7 +49,7 @@
private EmbedCartridgeWizardPageModel model;
private CheckboxTableViewer viewer;
- public EmbedCartridgeWizardPage(NewApplicationWizardModel wizardModel, IWizard wizard) {
+ public EmbedCartridgeWizardPage(ApplicationWizardModel wizardModel, IWizard wizard) {
super("Embed Cartridges", "Please select the cartridges to embed into your application",
"EmbedCartridgePage", wizard);
this.model = new EmbedCartridgeWizardPageModel(wizardModel);
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPageModel.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPageModel.java 2011-11-17 12:05:44 UTC (rev 36402)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPageModel.java 2011-11-17 13:03:18 UTC (rev 36403)
@@ -30,12 +30,12 @@
public static final String PROPERTY_EMBEDDABLE_CARTRIDGES = "embeddableCartridges";
public static final String PROPERTY_SELECTED_CARTRIDGE = "selectedCartridge";
- private NewApplicationWizardModel wizardModel;
+ private ApplicationWizardModel wizardModel;
private List<IEmbeddableCartridge> embeddableCartridges = new ArrayList<IEmbeddableCartridge>();
private List<IEmbeddableCartridge> selectedEmbeddableCartridges = new ArrayList<IEmbeddableCartridge>();
- public EmbedCartridgeWizardPageModel(NewApplicationWizardModel wizardModel) {
+ public EmbedCartridgeWizardPageModel(ApplicationWizardModel wizardModel) {
this.wizardModel = wizardModel;
}
Deleted: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationDialog.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationDialog.java 2011-11-17 12:05:44 UTC (rev 36402)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationDialog.java 2011-11-17 13:03:18 UTC (rev 36403)
@@ -1,74 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.openshift.express.internal.ui.wizard;
-
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.TimeUnit;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.jface.wizard.Wizard;
-import org.eclipse.osgi.util.NLS;
-import org.jboss.tools.common.ui.WizardUtils;
-import org.jboss.tools.openshift.express.client.IApplication;
-import org.jboss.tools.openshift.express.client.IUser;
-import org.jboss.tools.openshift.express.client.OpenShiftException;
-import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
-
-/**
- * @author André Dietisheim
- */
-public class NewApplicationDialog extends Wizard {
-
- private NewApplicationWizardModel newApplicationWizardModel;
-
- public NewApplicationDialog(IUser user) {
- this.newApplicationWizardModel = new NewApplicationWizardModel(user);
- setNeedsProgressMonitor(true);
- }
-
- @Override
- public boolean performFinish() {
- final ArrayBlockingQueue<Boolean> queue = new ArrayBlockingQueue<Boolean>(1);
- try {
- WizardUtils.runInWizard(new Job("Creating application...") {
-
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- try {
- newApplicationWizardModel.createApplication();
- queue.offer(true);
- } catch (OpenShiftException e) {
- queue.offer(false);
- return new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
- NLS.bind("Could not create application \"{0}\"", newApplicationWizardModel.getName()), e);
- }
- return Status.OK_STATUS;
- }
- }, getContainer());
- return queue.poll(10, TimeUnit.SECONDS);
- } catch (Exception e) {
- return false;
- }
- }
-
- @Override
- public void addPages() {
- addPage(new NewApplicationWizardPage(newApplicationWizardModel, this));
- addPage(new EmbedCartridgeWizardPage(newApplicationWizardModel, this));
- }
-
- public IApplication getApplication() {
- return newApplicationWizardModel.getApplication();
- }
-}
Copied: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizard.java (from rev 36402, trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationDialog.java)
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizard.java (rev 0)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizard.java 2011-11-17 13:03:18 UTC (rev 36403)
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.openshift.express.internal.ui.wizard;
+
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.osgi.util.NLS;
+import org.jboss.tools.common.ui.WizardUtils;
+import org.jboss.tools.openshift.express.client.IApplication;
+import org.jboss.tools.openshift.express.client.IUser;
+import org.jboss.tools.openshift.express.client.OpenShiftException;
+import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
+
+/**
+ * @author André Dietisheim
+ */
+public class NewApplicationWizard extends Wizard {
+
+ private ApplicationWizardModel wizardModel;
+
+ public NewApplicationWizard(IUser user) {
+ this.wizardModel = new ApplicationWizardModel(user);
+ setNeedsProgressMonitor(true);
+ }
+
+ @Override
+ public boolean performFinish() {
+ final ArrayBlockingQueue<Boolean> queue = new ArrayBlockingQueue<Boolean>(1);
+ try {
+ WizardUtils.runInWizard(new Job(NLS.bind("Creating application \"{0}\"...", wizardModel.getName())) {
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ wizardModel.createApplication();
+ queue.offer(true);
+ } catch (OpenShiftException e) {
+ queue.offer(false);
+ return new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
+ NLS.bind("Could not create application \"{0}\"", wizardModel.getName()), e);
+ }
+ return Status.OK_STATUS;
+ }
+ }, getContainer());
+ return queue.poll(10, TimeUnit.SECONDS);
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ @Override
+ public void addPages() {
+ addPage(new NewApplicationWizardPage(wizardModel, this));
+ addPage(new EmbedCartridgeWizardPage(wizardModel, this));
+ }
+
+ public IApplication getApplication() {
+ return wizardModel.getApplication();
+ }
+}
Deleted: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardModel.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardModel.java 2011-11-17 12:05:44 UTC (rev 36402)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardModel.java 2011-11-17 13:03:18 UTC (rev 36403)
@@ -1,78 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.openshift.express.internal.ui.wizard;
-
-import org.jboss.tools.common.ui.databinding.ObservableUIPojo;
-import org.jboss.tools.openshift.express.client.IApplication;
-import org.jboss.tools.openshift.express.client.ICartridge;
-import org.jboss.tools.openshift.express.client.IUser;
-import org.jboss.tools.openshift.express.client.OpenShiftException;
-import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
-
-/**
- * @author André Dietisheim
- */
-public class NewApplicationWizardModel extends ObservableUIPojo {
-
- private IUser user;
-
- private String name;
- private ICartridge cartridge;
-
- private IApplication application;
-
- public NewApplicationWizardModel(IUser user) {
- this.user = user;
- }
-
- public IUser getUser() {
- return user;
- }
-
- public String getName() {
- return name;
- }
-
- public String setName(String name) {
- return this.name = name;
- }
-
- public ICartridge getCartridge() {
- return cartridge;
- }
-
- public void setCartridge(ICartridge cartridge) {
- this.cartridge = cartridge;
- }
-
- public void setApplication(IApplication application) {
- this.application = application;
- }
-
- public void createApplication() throws OpenShiftException {
- IApplication application = user.createApplication(name, cartridge);
- setApplication(application);
- }
-
- public IApplication getApplication() {
- return application;
- }
-
- public boolean hasApplication(String name) {
- try {
- return user.getApplicationByName(name) != null;
- } catch (OpenShiftException e) {
- OpenShiftUIActivator.log(
- OpenShiftUIActivator.createErrorStatus("Could not get application by name", e));
- return false;
- }
- }
-}
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardPage.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardPage.java 2011-11-17 12:05:44 UTC (rev 36402)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardPage.java 2011-11-17 13:03:18 UTC (rev 36403)
@@ -46,9 +46,9 @@
public class NewApplicationWizardPage extends AbstractOpenShiftWizardPage {
private NewApplicationWizardPageModel model;
- private NewApplicationWizardModel wizardModel;
+ private ApplicationWizardModel wizardModel;
- public NewApplicationWizardPage(NewApplicationWizardModel wizardModel, IWizard wizard) {
+ public NewApplicationWizardPage(ApplicationWizardModel wizardModel, IWizard wizard) {
super("Create new OpenShift Express application", "Create new OpenShift Express application",
"Create new OpenShift Express application", wizard);
this.wizardModel = wizardModel;
@@ -154,9 +154,8 @@
@Override
protected void onPageWillGetDeactivated(Direction progress, final PageChangingEvent event, DataBindingContext dbc) {
- final String name = wizardModel.getName();
try {
- WizardUtils.runInWizard(new Job(NLS.bind("Creating application \"{0}\"...", name)) {
+ WizardUtils.runInWizard(new Job(NLS.bind("Creating application \"{0}\"...", wizardModel.getName())) {
@Override
protected IStatus run(IProgressMonitor monitor) {
@@ -164,7 +163,7 @@
wizardModel.createApplication();
} catch (OpenShiftException e) {
event.doit = false;
- return OpenShiftUIActivator.createErrorStatus("Could not create application \"{0}\"", e, name);
+ return OpenShiftUIActivator.createErrorStatus("Could not create application \"{0}\"", e, wizardModel.getName());
}
return Status.OK_STATUS;
}
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardPageModel.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardPageModel.java 2011-11-17 12:05:44 UTC (rev 36402)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardPageModel.java 2011-11-17 13:03:18 UTC (rev 36403)
@@ -29,13 +29,13 @@
public static final String PROPERTY_CARTRIDGES = "cartridges";
public static final String PROPERTY_SELECTED_CARTRIDGE = "selectedCartridge";
- private NewApplicationWizardModel wizardModel;
+ private ApplicationWizardModel wizardModel;
private List<ICartridge> cartridges = new ArrayList<ICartridge>();
private ICartridge selectedCartridge;
private StringPreferenceValue selectedCartridgePreference;
- public NewApplicationWizardPageModel(NewApplicationWizardModel wizardModel) {
+ public NewApplicationWizardPageModel(ApplicationWizardModel wizardModel) {
this.wizardModel = wizardModel;
this.selectedCartridgePreference = new StringPreferenceValue(
"org.jboss.tools.openshift.express.internal.ui.wizard.NewApplicationWizard.selectedCartridge",
14 years, 5 months
JBoss Tools SVN: r36402 - in trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui: wizard and 1 other directory.
by jbosstools-commits@lists.jboss.org
Author: adietish
Date: 2011-11-17 07:05:44 -0500 (Thu, 17 Nov 2011)
New Revision: 36402
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPage.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPageModel.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardModel.java
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/OpenShiftUIActivator.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationDialog.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardPage.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardPageModel.java
Log:
[JBIDE-9927] implementing "embed cartridge"
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/OpenShiftUIActivator.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/OpenShiftUIActivator.java 2011-11-17 12:05:12 UTC (rev 36401)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/OpenShiftUIActivator.java 2011-11-17 12:05:44 UTC (rev 36402)
@@ -2,6 +2,7 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
@@ -15,7 +16,7 @@
// The shared instance
private static OpenShiftUIActivator plugin;
-
+
/**
* The constructor
*/
@@ -24,7 +25,10 @@
/*
* (non-Javadoc)
- * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ *
+ * @see
+ * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
+ * )
*/
public void start(BundleContext context) throws Exception {
super.start(context);
@@ -33,7 +37,10 @@
/*
* (non-Javadoc)
- * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ *
+ * @see
+ * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
+ * )
*/
public void stop(BundleContext context) throws Exception {
plugin = null;
@@ -42,13 +49,13 @@
/**
* Returns the shared instance
- *
+ *
* @return the shared instance
*/
public static OpenShiftUIActivator getDefault() {
return plugin;
}
-
+
public static void log(IStatus status) {
plugin.getLog().log(status);
}
@@ -58,8 +65,10 @@
}
public static IStatus createErrorStatus(String message, Throwable throwable) {
- return new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
- message, throwable);
+ return new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID, message, throwable);
}
-
+
+ public static IStatus createErrorStatus(String message, Throwable throwable, Object... arguments) {
+ return createErrorStatus(NLS.bind(message, arguments), throwable);
+ }
}
Added: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPage.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPage.java (rev 0)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPage.java 2011-11-17 12:05:44 UTC (rev 36402)
@@ -0,0 +1,173 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.openshift.express.internal.ui.wizard;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.eclipse.core.databinding.DataBindingContext;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.layout.TableColumnLayout;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.CellLabelProvider;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.ViewerCell;
+import org.eclipse.jface.wizard.IWizard;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Table;
+import org.jboss.tools.common.ui.WizardUtils;
+import org.jboss.tools.openshift.express.client.IEmbeddableCartridge;
+import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
+
+/**
+ * @author André Dietisheim
+ */
+public class EmbedCartridgeWizardPage extends AbstractOpenShiftWizardPage {
+
+ private EmbedCartridgeWizardPageModel model;
+ private CheckboxTableViewer viewer;
+
+ public EmbedCartridgeWizardPage(NewApplicationWizardModel wizardModel, IWizard wizard) {
+ super("Embed Cartridges", "Please select the cartridges to embed into your application",
+ "EmbedCartridgePage", wizard);
+ this.model = new EmbedCartridgeWizardPageModel(wizardModel);
+ }
+
+ @Override
+ protected void doCreateControls(Composite parent, DataBindingContext dbc) {
+ GridLayoutFactory.fillDefaults().numColumns(2).margins(10, 10).applyTo(parent);
+
+ Group embedGroup = new Group(parent, SWT.NONE);
+ embedGroup.setText("Embeddable Cartridges");
+ GridDataFactory.fillDefaults()
+ .hint(300, 150).align(SWT.FILL, SWT.FILL).span(2, 1).grab(true, true)
+ .applyTo(embedGroup);
+ FillLayout fillLayout = new FillLayout();
+ fillLayout.marginHeight = 6;
+ fillLayout.marginWidth = 6;
+ embedGroup.setLayout(fillLayout);
+
+ Composite tableContainer = new Composite(embedGroup, SWT.NONE);
+ this.viewer = createTable(tableContainer);
+ viewer.addCheckStateListener(onEmbeddableCartridgeChecked());
+
+ }
+
+ protected CheckboxTableViewer createTable(Composite tableContainer) {
+ Table table =
+ new Table(tableContainer, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL | SWT.CHECK);
+ table.setLinesVisible(true);
+ TableColumnLayout tableLayout = new TableColumnLayout();
+ tableContainer.setLayout(tableLayout);
+ CheckboxTableViewer viewer = new CheckboxTableViewer(table);
+ viewer.setContentProvider(new ArrayContentProvider());
+
+ createTableColumn("Embeddable Cartridge", 1, new CellLabelProvider() {
+
+ @Override
+ public void update(ViewerCell cell) {
+ IEmbeddableCartridge cartridge = (IEmbeddableCartridge) cell.getElement();
+ cell.setText(cartridge.getName());
+ }
+ }, viewer, tableLayout);
+ return viewer;
+ }
+
+ private void createTableColumn(String name, int weight, CellLabelProvider cellLabelProvider, TableViewer viewer,
+ TableColumnLayout layout) {
+ TableViewerColumn column = new TableViewerColumn(viewer, SWT.LEFT);
+ column.getColumn().setText(name);
+ column.setLabelProvider(cellLabelProvider);
+
+ layout.setColumnData(column.getColumn(), new ColumnWeightData(weight, true));
+ }
+
+ private ICheckStateListener onEmbeddableCartridgeChecked() {
+ return new ICheckStateListener() {
+
+ @Override
+ public void checkStateChanged(CheckStateChangedEvent event) {
+ IEmbeddableCartridge cartridge = (IEmbeddableCartridge) event.getElement();
+ if (event.getChecked()) {
+ if (IEmbeddableCartridge.PHPMYADMIN_34.equals(cartridge)) {
+ addPhpMyACartridge(cartridge);
+ }
+ else if (IEmbeddableCartridge.JENKINS_14.equals(cartridge)) {
+ addJenkinsCartridge(cartridge);
+ }
+ } else {
+ model.getSelectedEmbeddableCartridges().remove(cartridge);
+ }
+ }
+ };
+ }
+
+ private void addJenkinsCartridge(IEmbeddableCartridge cartridge) {
+ model.getSelectedEmbeddableCartridges().add(cartridge);
+ }
+
+ private void addPhpMyACartridge(IEmbeddableCartridge cartridge) {
+ MessageDialog.openQuestion(getShell(), "Enable MySQL cartridge", "To embed PhpMyAdmin, you'd also have to embed MySql. ");
+ model.getSelectedEmbeddableCartridges().add(cartridge);
+ }
+
+ @Override
+ protected void onPageActivated(DataBindingContext dbc) {
+ try {
+ WizardUtils.runInWizard(new Job("Loading embeddable cartridges...") {
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ setCartridgesViewerInput(model.loadEmbeddableCartridges());
+ return Status.OK_STATUS;
+ } catch (Exception e) {
+ clearCartridgesViewer();
+ return new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
+ "Could not load embeddable cartridges", e);
+ }
+ }
+
+ }, getContainer(), getDataBindingContext());
+ } catch (Exception e) {
+ // ignore
+ }
+
+ }
+
+ private void clearCartridgesViewer() {
+ setCartridgesViewerInput(new ArrayList<IEmbeddableCartridge>());
+ }
+
+ private void setCartridgesViewerInput(final Collection<IEmbeddableCartridge> cartridges) {
+ getShell().getDisplay().syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ viewer.setInput(cartridges);
+ }
+ });
+ }
+}
\ No newline at end of file
Property changes on: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPage.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPageModel.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPageModel.java (rev 0)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPageModel.java 2011-11-17 12:05:44 UTC (rev 36402)
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.openshift.express.internal.ui.wizard;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.tools.common.ui.databinding.ObservableUIPojo;
+import org.jboss.tools.openshift.express.client.ICartridge;
+import org.jboss.tools.openshift.express.client.IEmbeddableCartridge;
+import org.jboss.tools.openshift.express.client.OpenShiftException;
+import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
+
+/**
+ * @author André Dietisheim
+ */
+public class EmbedCartridgeWizardPageModel extends ObservableUIPojo {
+
+ public static final String PROPERTY_APPLICATION = "application";
+ public static final String PROPERTY_NAME = "name";
+ public static final String PROPERTY_CARTRIDGES = "cartridges";
+ public static final String PROPERTY_EMBEDDABLE_CARTRIDGES = "embeddableCartridges";
+ public static final String PROPERTY_SELECTED_CARTRIDGE = "selectedCartridge";
+
+ private NewApplicationWizardModel wizardModel;
+
+ private List<IEmbeddableCartridge> embeddableCartridges = new ArrayList<IEmbeddableCartridge>();
+ private List<IEmbeddableCartridge> selectedEmbeddableCartridges = new ArrayList<IEmbeddableCartridge>();
+
+ public EmbedCartridgeWizardPageModel(NewApplicationWizardModel wizardModel) {
+ this.wizardModel = wizardModel;
+ }
+
+ public List<IEmbeddableCartridge> loadEmbeddableCartridges() throws OpenShiftException {
+ List<IEmbeddableCartridge> cartridges = wizardModel.getUser().getEmbeddableCartridges();
+ setEmbeddableCartridges(cartridges);
+ return cartridges;
+ }
+
+ public void setEmbeddableCartridges(List<IEmbeddableCartridge> cartridges) {
+ firePropertyChange(
+ PROPERTY_EMBEDDABLE_CARTRIDGES, this.embeddableCartridges, this.embeddableCartridges = cartridges);
+ }
+
+ public List<IEmbeddableCartridge> getEmbeddableCartridges() {
+ return embeddableCartridges;
+ }
+
+ public List<IEmbeddableCartridge> getSelectedEmbeddableCartridges() {
+ return selectedEmbeddableCartridges;
+ }
+
+ public boolean hasApplication(ICartridge cartridge) {
+ try {
+ return wizardModel.getUser().hasApplication(cartridge);
+ } catch (OpenShiftException e) {
+ OpenShiftUIActivator.log(
+ OpenShiftUIActivator.createErrorStatus("Could not get application by cartridge", e));
+ return false;
+ }
+ }
+}
Property changes on: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/EmbedCartridgeWizardPageModel.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationDialog.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationDialog.java 2011-11-17 12:05:12 UTC (rev 36401)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationDialog.java 2011-11-17 12:05:44 UTC (rev 36402)
@@ -30,10 +30,10 @@
*/
public class NewApplicationDialog extends Wizard {
- private NewApplicationWizardPageModel newApplicationModel;
+ private NewApplicationWizardModel newApplicationWizardModel;
public NewApplicationDialog(IUser user) {
- this.newApplicationModel = new NewApplicationWizardPageModel(user);
+ this.newApplicationWizardModel = new NewApplicationWizardModel(user);
setNeedsProgressMonitor(true);
}
@@ -46,12 +46,12 @@
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
- newApplicationModel.createApplication();
+ newApplicationWizardModel.createApplication();
queue.offer(true);
} catch (OpenShiftException e) {
queue.offer(false);
return new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
- NLS.bind("Could not create application \"{0}\"", newApplicationModel.getName()), e);
+ NLS.bind("Could not create application \"{0}\"", newApplicationWizardModel.getName()), e);
}
return Status.OK_STATUS;
}
@@ -64,10 +64,11 @@
@Override
public void addPages() {
- addPage(new NewApplicationWizardPage(newApplicationModel, this));
+ addPage(new NewApplicationWizardPage(newApplicationWizardModel, this));
+ addPage(new EmbedCartridgeWizardPage(newApplicationWizardModel, this));
}
public IApplication getApplication() {
- return newApplicationModel.getApplication();
+ return newApplicationWizardModel.getApplication();
}
}
Added: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardModel.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardModel.java (rev 0)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardModel.java 2011-11-17 12:05:44 UTC (rev 36402)
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.openshift.express.internal.ui.wizard;
+
+import org.jboss.tools.common.ui.databinding.ObservableUIPojo;
+import org.jboss.tools.openshift.express.client.IApplication;
+import org.jboss.tools.openshift.express.client.ICartridge;
+import org.jboss.tools.openshift.express.client.IUser;
+import org.jboss.tools.openshift.express.client.OpenShiftException;
+import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
+
+/**
+ * @author André Dietisheim
+ */
+public class NewApplicationWizardModel extends ObservableUIPojo {
+
+ private IUser user;
+
+ private String name;
+ private ICartridge cartridge;
+
+ private IApplication application;
+
+ public NewApplicationWizardModel(IUser user) {
+ this.user = user;
+ }
+
+ public IUser getUser() {
+ return user;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String setName(String name) {
+ return this.name = name;
+ }
+
+ public ICartridge getCartridge() {
+ return cartridge;
+ }
+
+ public void setCartridge(ICartridge cartridge) {
+ this.cartridge = cartridge;
+ }
+
+ public void setApplication(IApplication application) {
+ this.application = application;
+ }
+
+ public void createApplication() throws OpenShiftException {
+ IApplication application = user.createApplication(name, cartridge);
+ setApplication(application);
+ }
+
+ public IApplication getApplication() {
+ return application;
+ }
+
+ public boolean hasApplication(String name) {
+ try {
+ return user.getApplicationByName(name) != null;
+ } catch (OpenShiftException e) {
+ OpenShiftUIActivator.log(
+ OpenShiftUIActivator.createErrorStatus("Could not get application by name", e));
+ return false;
+ }
+ }
+}
Property changes on: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardModel.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardPage.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardPage.java 2011-11-17 12:05:12 UTC (rev 36401)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardPage.java 2011-11-17 12:05:44 UTC (rev 36402)
@@ -10,9 +10,6 @@
******************************************************************************/
package org.jboss.tools.openshift.express.internal.ui.wizard;
-import java.util.ArrayList;
-import java.util.Collection;
-
import org.eclipse.core.databinding.Binding;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.UpdateListStrategy;
@@ -27,32 +24,19 @@
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.databinding.fieldassist.ControlDecorationSupport;
import org.eclipse.jface.databinding.swt.WidgetProperties;
+import org.eclipse.jface.dialogs.PageChangingEvent;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
-import org.eclipse.jface.layout.TableColumnLayout;
-import org.eclipse.jface.viewers.ArrayContentProvider;
-import org.eclipse.jface.viewers.CellLabelProvider;
-import org.eclipse.jface.viewers.CheckStateChangedEvent;
-import org.eclipse.jface.viewers.CheckboxTableViewer;
-import org.eclipse.jface.viewers.ColumnWeightData;
-import org.eclipse.jface.viewers.ICheckStateListener;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.TableViewerColumn;
-import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.jface.wizard.IWizard;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
import org.jboss.tools.common.ui.WizardUtils;
import org.jboss.tools.openshift.express.client.Cartridge;
import org.jboss.tools.openshift.express.client.ICartridge;
-import org.jboss.tools.openshift.express.client.IEmbeddableCartridge;
import org.jboss.tools.openshift.express.client.OpenShiftException;
import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
@@ -62,12 +46,13 @@
public class NewApplicationWizardPage extends AbstractOpenShiftWizardPage {
private NewApplicationWizardPageModel model;
- private CheckboxTableViewer viewer;
+ private NewApplicationWizardModel wizardModel;
- public NewApplicationWizardPage(NewApplicationWizardPageModel model, IWizard wizard) {
+ public NewApplicationWizardPage(NewApplicationWizardModel wizardModel, IWizard wizard) {
super("Create new OpenShift Express application", "Create new OpenShift Express application",
"Create new OpenShift Express application", wizard);
- this.model = model;
+ this.wizardModel = wizardModel;
+ this.model = new NewApplicationWizardPageModel(wizardModel);
}
@Override
@@ -144,70 +129,8 @@
}
}));
ControlDecorationSupport.create(comboSelectionBinding, SWT.LEFT | SWT.TOP);
-
- createEmbedGroup(parent);
}
- private void createEmbedGroup(Composite parent) {
- Group embedGroup = new Group(parent, SWT.NONE);
- embedGroup.setText("Embeddable Cartridges");
- GridDataFactory.fillDefaults()
- .hint(300, 150).align(SWT.FILL, SWT.FILL).span(2, 1).grab(true, true)
- .applyTo(embedGroup);
- FillLayout fillLayout = new FillLayout();
- fillLayout.marginHeight = 6;
- fillLayout.marginWidth = 6;
- embedGroup.setLayout(fillLayout);
-
- Composite tableContainer = new Composite(embedGroup, SWT.NONE);
- this.viewer = createTable(tableContainer);
- viewer.addCheckStateListener(onEmbeddableCartridgeSelected());
- }
-
- private ICheckStateListener onEmbeddableCartridgeSelected() {
- return new ICheckStateListener() {
-
- @Override
- public void checkStateChanged(CheckStateChangedEvent event) {
- IEmbeddableCartridge cartridge = (IEmbeddableCartridge) event.getElement();
- if (event.getChecked()) {
- model.getSeleEmbeddableCartridges().add(cartridge);
- } else {
- model.getSeleEmbeddableCartridges().remove(cartridge);
- }
- }
- };
- }
-
- protected CheckboxTableViewer createTable(Composite tableContainer) {
- Table table =
- new Table(tableContainer, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL | SWT.CHECK);
- table.setLinesVisible(true);
- TableColumnLayout tableLayout = new TableColumnLayout();
- tableContainer.setLayout(tableLayout);
- CheckboxTableViewer viewer = new CheckboxTableViewer(table);
- viewer.setContentProvider(new ArrayContentProvider());
-
- createTableColumn("Embeddable Cartridge", 1, new CellLabelProvider() {
-
- @Override
- public void update(ViewerCell cell) {
- IEmbeddableCartridge cartridge = (IEmbeddableCartridge) cell.getElement();
- cell.setText(cartridge.getName());
- }
- }, viewer, tableLayout);
- return viewer;
- }
-
- private void createTableColumn(String name, int weight, CellLabelProvider cellLabelProvider, TableViewer viewer,
- TableColumnLayout layout) {
- TableViewerColumn column = new TableViewerColumn(viewer, SWT.LEFT);
- column.getColumn().setText(name);
- column.setLabelProvider(cellLabelProvider);
-
- layout.setColumnData(column.getColumn(), new ColumnWeightData(weight, true));
- }
-
@Override
protected void onPageActivated(DataBindingContext dbc) {
try {
@@ -226,43 +149,31 @@
} catch (Exception e) {
// ignore
}
+ }
+
+ @Override
+ protected void onPageWillGetDeactivated(Direction progress, final PageChangingEvent event, DataBindingContext dbc) {
+ final String name = wizardModel.getName();
try {
- WizardUtils.runInWizard(new Job("Loading embeddable cartridges...") {
+ WizardUtils.runInWizard(new Job(NLS.bind("Creating application \"{0}\"...", name)) {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
- setCartridgesViewerInput(model.loadEmbeddableCartridges());
- return Status.OK_STATUS;
- } catch (Exception e) {
- clearCartridgesViewer();
- return new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
- "Could not load embeddable cartridges", e);
+ wizardModel.createApplication();
+ } catch (OpenShiftException e) {
+ event.doit = false;
+ return OpenShiftUIActivator.createErrorStatus("Could not create application \"{0}\"", e, name);
}
+ return Status.OK_STATUS;
}
-
- }, getContainer(), getDataBindingContext());
+ }, getContainer());
} catch (Exception e) {
// ignore
}
-
}
- private void clearCartridgesViewer() {
- setCartridgesViewerInput(new ArrayList<IEmbeddableCartridge>());
- }
-
- private void setCartridgesViewerInput(final Collection<IEmbeddableCartridge> cartridges) {
- getShell().getDisplay().syncExec(new Runnable() {
-
- @Override
- public void run() {
- viewer.setInput(cartridges);
- }
- });
- }
-
private class ApplicationNameValidator implements IValidator {
@Override
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardPageModel.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardPageModel.java 2011-11-17 12:05:12 UTC (rev 36401)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/NewApplicationWizardPageModel.java 2011-11-17 12:05:44 UTC (rev 36402)
@@ -15,10 +15,7 @@
import org.jboss.tools.common.ui.databinding.ObservableUIPojo;
import org.jboss.tools.common.ui.preferencevalue.StringPreferenceValue;
-import org.jboss.tools.openshift.express.client.IApplication;
import org.jboss.tools.openshift.express.client.ICartridge;
-import org.jboss.tools.openshift.express.client.IEmbeddableCartridge;
-import org.jboss.tools.openshift.express.client.IUser;
import org.jboss.tools.openshift.express.client.OpenShiftException;
import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
@@ -30,22 +27,16 @@
public static final String PROPERTY_APPLICATION = "application";
public static final String PROPERTY_NAME = "name";
public static final String PROPERTY_CARTRIDGES = "cartridges";
- public static final String PROPERTY_EMBEDDABLE_CARTRIDGES = "embeddableCartridges";
public static final String PROPERTY_SELECTED_CARTRIDGE = "selectedCartridge";
- private IUser user;
- private String name;
- private IApplication application;
+ private NewApplicationWizardModel wizardModel;
private List<ICartridge> cartridges = new ArrayList<ICartridge>();
private ICartridge selectedCartridge;
private StringPreferenceValue selectedCartridgePreference;
- private List<IEmbeddableCartridge> embeddableCartridges = new ArrayList<IEmbeddableCartridge>();
- private List<IEmbeddableCartridge> selectedEmbeddableCartridges = new ArrayList<IEmbeddableCartridge>();
-
- public NewApplicationWizardPageModel(IUser user) {
- this.user = user;
+ public NewApplicationWizardPageModel(NewApplicationWizardModel wizardModel) {
+ this.wizardModel = wizardModel;
this.selectedCartridgePreference = new StringPreferenceValue(
"org.jboss.tools.openshift.express.internal.ui.wizard.NewApplicationWizard.selectedCartridge",
OpenShiftUIActivator.PLUGIN_ID);
@@ -69,15 +60,16 @@
}
public String getName() {
- return name;
+ return wizardModel.getName();
}
public void setName(String name) {
- firePropertyChange(PROPERTY_NAME, this.name, this.name = name);
+ wizardModel.setName(name);
+ firePropertyChange(PROPERTY_NAME, wizardModel.getName(), wizardModel.setName(name));
}
public void loadCartridges() throws OpenShiftException {
- setCartridges(user.getCartridges());
+ setCartridges(wizardModel.getUser().getCartridges());
}
public void setCartridges(List<ICartridge> cartridges) {
@@ -94,6 +86,7 @@
}
public void setSelectedCartridge(ICartridge cartridge) {
+ wizardModel.setCartridge(cartridge);
if (cartridge != null) {
selectedCartridgePreference.store(cartridge.getName());
}
@@ -111,41 +104,9 @@
return matchingCartridge;
}
- public List<IEmbeddableCartridge> loadEmbeddableCartridges() throws OpenShiftException {
- List<IEmbeddableCartridge> cartridges = user.getEmbeddableCartridges();
- setEmbeddableCartridges(cartridges);
- return cartridges;
- }
-
- public void setEmbeddableCartridges(List<IEmbeddableCartridge> cartridges) {
- firePropertyChange(
- PROPERTY_EMBEDDABLE_CARTRIDGES, this.embeddableCartridges, this.embeddableCartridges = cartridges);
- }
-
- public List<IEmbeddableCartridge> getEmbeddableCartridges() {
- return embeddableCartridges;
- }
-
- public List<IEmbeddableCartridge> getSeleEmbeddableCartridges() {
- return selectedEmbeddableCartridges;
- }
-
- public void createApplication() throws OpenShiftException {
- IApplication application = user.createApplication(name, selectedCartridge);
- setApplication(application);
- }
-
- public void setApplication(IApplication application) {
- firePropertyChange(PROPERTY_APPLICATION, this.application, this.application = application);
- }
-
- public IApplication getApplication() {
- return application;
- }
-
public boolean hasApplication(String name) {
try {
- return user.getApplicationByName(name) != null;
+ return wizardModel.getUser().getApplicationByName(name) != null;
} catch (OpenShiftException e) {
OpenShiftUIActivator.log(
OpenShiftUIActivator.createErrorStatus("Could not get application by name", e));
14 years, 5 months
JBoss Tools SVN: r36401 - trunk/openshift/plugins/org.jboss.tools.openshift.express.client.
by jbosstools-commits@lists.jboss.org
Author: adietish
Date: 2011-11-17 07:05:12 -0500 (Thu, 17 Nov 2011)
New Revision: 36401
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.client/org.jboss.tools.openshift.express.client-2.3.0-SNAPSHOT.jar
Log:
[JBIDE-9927] switched to latest client jar
Modified: trunk/openshift/plugins/org.jboss.tools.openshift.express.client/org.jboss.tools.openshift.express.client-2.3.0-SNAPSHOT.jar
===================================================================
(Binary files differ)
14 years, 5 months