Author: yradtsevich
Date: 2012-04-27 08:01:02 -0400 (Fri, 27 Apr 2012)
New Revision: 40564
Added:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/ExceptionNotifier.java
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim.browser/src/org/jboss/tools/vpe/browsersim/browser/PlatformUtil.java
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/BrowserSim.java
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/Messages.java
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/messages.properties
Log:
https://issues.jboss.org/browse/JBIDE-11498 : Show more informative messages when
BrowserSim cannot be run
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/BrowserSim.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/BrowserSim.java 2012-04-27
11:39:03 UTC (rev 40563)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/BrowserSim.java 2012-04-27
12:01:02 UTC (rev 40564)
@@ -46,7 +46,6 @@
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
-import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Monitor;
import org.eclipse.swt.widgets.Shell;
import org.jboss.tools.vpe.browsersim.browser.BrowserSimBrowser;
@@ -154,7 +153,8 @@
try {
skin.createControls(display);
} catch (SWTError e) {
- showErrorMessage(new Shell(display),
Messages.BrowserSim_COULD_NOT_INSTANTIATE_WEBKIT_BROWSER + e.getMessage());
+ e.printStackTrace();
+ ExceptionNotifier.showWebKitLoadError(new Shell(display), e);
display.dispose();
return;
}
@@ -398,7 +398,8 @@
url = new URL(skin.getBrowser().getUrl());// validate URL (to do not open
'about:blank' and similar)
Program.launch(url.toString());
} catch (MalformedURLException e1) {
- showErrorMessage(skin.getShell(),
Messages.BrowserSim_COULD_NOT_OPEN_DEFAULT_BROWSER + e1.getMessage());
+ e1.printStackTrace();
+ ExceptionNotifier.showErrorMessage(skin.getShell(),
Messages.BrowserSim_COULD_NOT_OPEN_DEFAULT_BROWSER + e1.getMessage());
}
}
});
@@ -427,15 +428,6 @@
}
});
}
-
- private void showErrorMessage(Shell shell, String message) {
- System.err.println(message);
-
- MessageBox messageBox = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
- messageBox.setText(Messages.BrowserSim_ERROR);
- messageBox.setMessage(message);
- messageBox.open();
- }
private void addDevicesListForMenu(final DevicesList devicesList, Menu devicesMenu) {
List<Device> devices = devicesList.getDevices();
Added:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/ExceptionNotifier.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/ExceptionNotifier.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/ExceptionNotifier.java 2012-04-27
12:01:02 UTC (rev 40564)
@@ -0,0 +1,166 @@
+/*******************************************************************************
+ * 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.vpe.browsersim.ui;
+
+import java.text.MessageFormat;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.SWTError;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.program.Program;
+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.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Link;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.swt.widgets.Shell;
+import org.jboss.tools.vpe.browsersim.browser.PlatformUtil;
+
+/**
+ * @author Yahor Radtsevich (yradtsevich)
+ */
+public class ExceptionNotifier {
+
+ /**
+ * Should be used to notify user about WebKit-loading errors
+ */
+ public static void showWebKitLoadError(Shell parentShell, SWTError error) {
+ String os = PlatformUtil.getOs();
+ String arch = PlatformUtil.getArch();
+ String message;
+ if (PlatformUtil.OS_WIN32.equals(os) && !PlatformUtil.ARCH_X86.equals(arch))
{// Eclipse 64-bit on Windows
+ message = Messages.ExceptionNotifier_ONLY_32_BIT_ECLIPSE_IS_SUPPORTED_ON_WINDOWS;
+ } else if (PlatformUtil.OS_WIN32.equals(os) &&
PlatformUtil.ARCH_X86.equals(arch) // Eclipse 32-bit on Windows and
+ && error.getMessage() != null // Apple Application Support is not
installed
+ && error.getMessage().contains("Safari must be installed to use a
SWT.WEBKIT-style Browser")) {
+ message = Messages.ExceptionNotifier_APPLE_APPLICATION_SUPPORT_IS_NOT_FOUND;
+ } else if (PlatformUtil.OS_LINUX.equals(os) && error.getMessage() != null
// WebKitGTK is not installed
+ && error.getMessage().contains("WebKitGTK")) {
+ message = Messages.ExceptionNotifier_WEBKIT_GTK_IS_NOT_FOUND;
+ } else { // everything else
+ message =
MessageFormat.format(Messages.ExceptionNotifier_COULD_NOT_INSTANTIATE_WEBKIT_BROWSER,
error.getMessage());
+ }
+ showErrorMessageWithLinks(parentShell, message);
+ }
+
+ public static void showErrorMessage(Shell shell, String message) {
+ System.err.println(message);
+
+ MessageBox messageBox = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
+ messageBox.setText(Messages.BrowserSim_ERROR);
+ messageBox.setMessage(message);
+ messageBox.open();
+ }
+
+ public static void showErrorMessageWithLinks(Shell shell, String message) {
+ System.err.println(message);
+
+ ErrorMessageBoxWithLinks messageBox = new ErrorMessageBoxWithLinks(shell);
+ messageBox.setText(Messages.BrowserSim_ERROR);
+ messageBox.setMessage(message);
+ messageBox.open();
+ }
+}
+
+/**
+ * Behaves like MessageBox with styles SWT.OK and SWT.ICON_ERROR, but allows HTML links
is messages.
+ * @author Yahor Radtsevich (yradtsevich)
+ *
+ */
+class ErrorMessageBoxWithLinks extends Dialog {
+ private Shell shell;
+ private String message;
+
+ public ErrorMessageBoxWithLinks(Shell parent) {
+ super(parent, SWT.NONE);
+ message = "";
+ }
+
+ public void open() {
+ shell = new Shell(getParent(), SWT.DIALOG_TRIM);
+ GridLayout shellLayout = new GridLayout(1, true);
+ shellLayout.marginHeight = 0;
+ shellLayout.marginWidth = 0;
+ shellLayout.verticalSpacing = 0;
+ shell.setLayout(shellLayout);
+ shell.setText(getText());
+
+ Color whiteColor = getParent().getDisplay().getSystemColor(SWT.COLOR_WHITE);
+ Composite messageComposite = new Composite(shell, SWT.NONE);
+ GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
+ messageComposite.setLayoutData(gridData);
+ RowLayout messageCompositeLayout = new RowLayout(SWT.HORIZONTAL);
+ messageCompositeLayout.marginHeight = 22;
+ messageCompositeLayout.marginWidth = 22;
+ messageCompositeLayout.spacing = 10;
+ messageCompositeLayout.center = true;
+ messageComposite.setLayout(messageCompositeLayout);
+ messageComposite.setBackground(whiteColor);
+
+ Image errorImage = shell.getDisplay().getSystemImage(SWT.ICON_ERROR);
+ Label imageLabel = new Label(messageComposite, SWT.NONE);
+ imageLabel.setImage(errorImage);
+ imageLabel.setBackground(whiteColor);
+ Link link = new Link(messageComposite, SWT.WRAP);
+ link.setText(message);
+ link.setBackground(whiteColor);
+ link.addListener (SWT.Selection, new Listener () {
+ public void handleEvent(Event event) {
+ Program.launch(event.text);
+ }
+ });
+
+ Composite okComposite = new Composite(shell, SWT.NONE);
+ gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
+ okComposite.setLayoutData(gridData);
+ GridLayout okCompositeLayout = new GridLayout(1, false);
+ okCompositeLayout.marginHeight = 10;
+ okCompositeLayout.marginWidth = 10;
+ okComposite.setLayout(okCompositeLayout);
+
+ Button ok = new Button(okComposite, SWT.PUSH);
+ ok.setText("OK");
+ ok.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ shell.close();
+ }
+ });
+ GridData okLayoutData = new GridData(SWT.END, SWT.CENTER, true, true);
+ okLayoutData.widthHint = 88;
+ ok.setLayoutData(okLayoutData);
+ shell.setDefaultButton(ok);
+
+
+ shell.pack();
+ shell.open();
+ Display display = getParent().getDisplay();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ }
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/Messages.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/Messages.java 2012-04-27
11:39:03 UTC (rev 40563)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/Messages.java 2012-04-27
12:01:02 UTC (rev 40564)
@@ -19,7 +19,6 @@
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_WEBKIT_BROWSER;
public static String BrowserSim_COULD_NOT_OPEN_DEFAULT_BROWSER;
public static String BrowserSim_DEVICES;
public static String BrowserSim_ERROR;
@@ -40,6 +39,10 @@
public static String EditDeviceDialog_SKIN;
public static String EditDeviceDialog_USER_AGENT;
public static String EditDeviceDialog_WIDTH;
+ public static String ExceptionNotifier_APPLE_APPLICATION_SUPPORT_IS_NOT_FOUND;
+ public static String ExceptionNotifier_COULD_NOT_INSTANTIATE_WEBKIT_BROWSER;
+ public static String ExceptionNotifier_ONLY_32_BIT_ECLIPSE_IS_SUPPORTED_ON_WINDOWS;
+ public static String ExceptionNotifier_WEBKIT_GTK_IS_NOT_FOUND;
public static String ManageDevicesDialog_ADD;
public static String ManageDevicesDialog_CANCEL;
public static String ManageDevicesDialog_DEFAULT;
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/messages.properties
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/messages.properties 2012-04-27
11:39:03 UTC (rev 40563)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim/src/org/jboss/tools/vpe/browsersim/ui/messages.properties 2012-04-27
12:01:02 UTC (rev 40564)
@@ -1,6 +1,5 @@
BrowserSim_ADDRESS=Address
BrowserSim_BROWSER_SIM=BrowserSim
-BrowserSim_COULD_NOT_INSTANTIATE_WEBKIT_BROWSER=Could not instantiate WebKit Browser:
BrowserSim_COULD_NOT_OPEN_DEFAULT_BROWSER=Could not open default browser:
BrowserSim_DEVICES=Devices
BrowserSim_ERROR=Error
@@ -21,6 +20,17 @@
EditDeviceDialog_SKIN=Skin:
EditDeviceDialog_USER_AGENT=User-Agent:
EditDeviceDialog_WIDTH=Width:
+ExceptionNotifier_APPLE_APPLICATION_SUPPORT_IS_NOT_FOUND=Apple Application Support is not
found.\
+\nPlease install <a
href=\"http://www.apple.com/quicktime/download/\">Apple QuickTime</a>
or <a
href=\"http://www.apple.com/itunes/download/\">Apple
iTunes</a> to run BrowserSim.\
+\nAlso see <a
href=\"https://community.jboss.org/docs/DOC-18100\">BrowserSim FAQ</a>.
+ExceptionNotifier_COULD_NOT_INSTANTIATE_WEBKIT_BROWSER=Could not instantiate WebKit
Browser:\n{1}\
+\nAlso see <a
href=\"https://community.jboss.org/docs/DOC-18100\">BrowserSim
FAQ</a>.
+ExceptionNotifier_ONLY_32_BIT_ECLIPSE_IS_SUPPORTED_ON_WINDOWS=64-bit Eclipse/JBDS is not
supported on Windows.\
+\nPlease install 32-bit Eclipse/JBDS to run BrowserSim.\
+\nAlso see <a
href=\"https://community.jboss.org/docs/DOC-18100\">BrowserSim
FAQ</a>.
+ExceptionNotifier_WEBKIT_GTK_IS_NOT_FOUND=WebKitGTK 1.2.0 or newer is not found in the
library load path.\
+\nPlease use your package manager to install libwebkitgtk.\
+\nAlso see <a
href=\"https://community.jboss.org/docs/DOC-18100\">BrowserSim
FAQ</a>.
ManageDevicesDialog_ADD=Add
ManageDevicesDialog_CANCEL=Cancel
ManageDevicesDialog_DEFAULT=DEFAULT
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim.browser/src/org/jboss/tools/vpe/browsersim/browser/PlatformUtil.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim.browser/src/org/jboss/tools/vpe/browsersim/browser/PlatformUtil.java 2012-04-27
11:39:03 UTC (rev 40563)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.browsersim.browser/src/org/jboss/tools/vpe/browsersim/browser/PlatformUtil.java 2012-04-27
12:01:02 UTC (rev 40564)
@@ -17,6 +17,9 @@
*/
public class PlatformUtil {
+ public static final String ARCH_X86 = "x86";
+ public static final String OS_WIN32 = "win32";
+ public static final String OS_LINUX = "linux";
public static final String OS_MACOSX = "macosx";
public static final String CURRENT_PLATFORM;
static {
@@ -24,7 +27,7 @@
String ws = getWs();
String arch = getArch();
- if (OS_MACOSX.equals(os) && "x86".equals(arch)) {
+ if (OS_MACOSX.equals(os) && ARCH_X86.equals(arch)) {
CURRENT_PLATFORM = ws + '.' + os; // special case for MacOSX x86 (its SWT
bundle has name org.eclipse.swt.cocoa.macosx)
} else {
CURRENT_PLATFORM = ws + '.' + os + '.' + arch;
@@ -34,9 +37,9 @@
/*
* Copy of org.eclipse.swt.internal.Library.arch()
*/
- private static String getArch() {
+ public static String getArch() {
String osArch = System.getProperty("os.arch"); //$NON-NLS-1$
- if (osArch.equals ("i386") || osArch.equals ("i686")) return
"x86"; //$NON-NLS-1$ $NON-NLS-2$ $NON-NLS-3$
+ if (osArch.equals ("i386") || osArch.equals ("i686")) return
ARCH_X86; //$NON-NLS-1$ $NON-NLS-2$ $NON-NLS-3$
if (osArch.equals ("amd64")) return "x86_64"; //$NON-NLS-1$
$NON-NLS-2$
if (osArch.equals ("IA64N")) return "ia64_32"; //$NON-NLS-1$
$NON-NLS-2$
if (osArch.equals ("IA64W")) return "ia64"; //$NON-NLS-1$
$NON-NLS-2$
@@ -48,12 +51,12 @@
*/
public static String getOs() {
String osName = System.getProperty("os.name"); //$NON-NLS-1$
- if (osName.equals ("Linux")) return "linux"; //$NON-NLS-1$
$NON-NLS-2$
+ if (osName.equals ("Linux")) return OS_LINUX; //$NON-NLS-1$ $NON-NLS-2$
if (osName.equals ("AIX")) return "aix"; //$NON-NLS-1$ $NON-NLS-2$
if (osName.equals ("Solaris") || osName.equals ("SunOS")) return
"solaris"; //$NON-NLS-1$ $NON-NLS-2$ $NON-NLS-3$
if (osName.equals ("HP-UX")) return "hpux"; //$NON-NLS-1$
$NON-NLS-2$
if (osName.equals ("Mac OS X")) return OS_MACOSX; //$NON-NLS-1$ $NON-NLS-2$
- if (osName.startsWith ("Win")) return "win32"; //$NON-NLS-1$
$NON-NLS-2$
+ if (osName.startsWith ("Win")) return OS_WIN32; //$NON-NLS-1$ $NON-NLS-2$
return osName;
}