Author: yradtsevich
Date: 2010-11-18 10:12:25 -0500 (Thu, 18 Nov 2010)
New Revision: 26713
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/browser/XulRunnerBrowser.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties
Log:
https://jira.jboss.org/browse/JBIDE-7308 : VPE Part should not show exceptions but
readable explanation why it cannot be loaded.
- the issue fixing
- code refactoring
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java 2010-11-18
15:09:43 UTC (rev 26712)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/mozilla/MozillaEditor.java 2010-11-18
15:12:25 UTC (rev 26713)
@@ -80,6 +80,7 @@
import org.jboss.tools.vpe.messages.VpeUIMessages;
import org.jboss.tools.vpe.resref.core.VpeResourcesDialog;
import org.jboss.tools.vpe.xulrunner.XulRunnerException;
+import org.jboss.tools.vpe.xulrunner.browser.XulRunnerBrowser;
import org.jboss.tools.vpe.xulrunner.editor.XulRunnerEditor;
import org.jboss.tools.vpe.xulrunner.util.XPCOM;
import org.mozilla.interfaces.nsIDOMDocument;
@@ -701,7 +702,7 @@
*/
protected void showXulRunnerError(Composite parent,
Throwable originalThrowable) {
- Throwable throwable = wrapIfItIsXulRunnerError(originalThrowable);
+ Throwable throwable = wrapXulRunnerError(originalThrowable);
String errorMessage = MessageFormat.format(
VpeUIMessages.MOZILLA_LOADING_ERROR, throwable.getMessage());
VpePlugin.getPluginLog().logError(errorMessage, throwable);
@@ -756,28 +757,43 @@
}
/**
- * This is a workaround method for JBIDE-7601 (Show XULRunner exception only once).
- * <P>
+ * Wraps instances of {@code SWTError} generated by XULRunner
+ * into a {@code XulRunnerException}. All other throwables are
+ * returned as is. In certain cases, error's messages may be
+ * substituted by messages that are more clear to the user.
+ */
+ /* There is a workaround for JBIDE-7601 (Show XULRunner exception only once).
+ *
* The problem is that the method {@code VpePlugin.getPluginLog().logError(...)}
* shows pop-ups for instances of {@code SWTError} because it considers
* them as {@code fatal}. To workaround of it, these errors are wrapped
- * to an {@code Exception}.
+ * to an {@code XulRunnerException}.
*
* @see org.eclipse.ui.internal.ide.IDEWorkbenchErrorHandler#isFatal(StatusAdapter)
* @see org.eclipse.swt.browser.Mozilla
*/
- private Throwable wrapIfItIsXulRunnerError(Throwable originalThrowable) {
+ private Throwable wrapXulRunnerError(Throwable originalThrowable) {
Throwable throwable = originalThrowable;
if (throwable instanceof SWTError && throwable.getMessage() != null) {
String message = throwable.getMessage();
if(message.contains("XPCOM error ") //$NON-NLS-1$
|| message.contains(" [Failed to use detected XULRunner: ") //$NON-NLS-1$
- || message.contains(" [Could not detect registered XULRunner to use]")
//$NON-NLS-1$
|| message.contains(" [Unknown Mozilla path (MOZILLA_FIVE_HOME not set)]")
//$NON-NLS-1$
|| message.contains(" [Mozilla GTK2 required (GTK1.2 detected)]")
//$NON-NLS-1$
|| message.contains(" [MOZILLA_FIVE_HOME='") //$NON-NLS-1$
|| message.contains(" [MOZILLA_FIVE_HOME may not point at an embeddable GRE]
[NS_InitEmbedding ")) { //$NON-NLS-1$
throwable = new XulRunnerException(originalThrowable);
+ } else if (message.contains(" [Could not detect registered XULRunner to
use]")) {//$NON-NLS-1$
+ if (System.getProperty(XulRunnerBrowser.XULRUNNER_PATH) == null
+ && !XulRunnerBrowser.isCurrentPlatformOfficiallySupported()) {
+ throwable = new XulRunnerException(
+ MessageFormat.format(
+ VpeUIMessages.CURRENT_PLATFORM_IS_NOT_SUPPORTED,
+ XulRunnerBrowser.CURRENT_PLATFORM_ID),
+ originalThrowable);
+ } else {
+ throwable = new XulRunnerException(originalThrowable);
+ }
}
}
return throwable;
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java 2010-11-18
15:09:43 UTC (rev 26712)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java 2010-11-18
15:12:25 UTC (rev 26713)
@@ -163,5 +163,6 @@
public static String LIST_IS_EMPTY;
public static String COULD_NOT_OPEN_VPE_RESOURCES_DIALOG;
+ public static String CURRENT_PLATFORM_IS_NOT_SUPPORTED;
public static String VPE_PREFERENCES_MENU_LABEL;
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties 2010-11-18
15:09:43 UTC (rev 26712)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties 2010-11-18
15:12:25 UTC (rev 26713)
@@ -6,7 +6,8 @@
PREFERENCES=Preferences
REFRESH=Refresh
PAGE_DESIGN_OPTIONS=Page Design Options
-MOZILLA_LOADING_ERROR=Could not open the Visual Page Editor: {0}
+MOZILLA_LOADING_ERROR=Could not open the Visual Page Editor:\n{0}
+CURRENT_PLATFORM_IS_NOT_SUPPORTED=Current platform ''{0}'' is not
supported.
MOZILLA_LOADING_ERROR_LINK_TEXT=See JBoss Tools Visual Editor FAQ
# START NON-TRANSLATABLE
MOZILLA_LOADING_ERROR_LINK=http://www.jboss.org/community/docs/DOC-10862
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/browser/XulRunnerBrowser.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/browser/XulRunnerBrowser.java 2010-11-18
15:09:43 UTC (rev 26712)
+++
trunk/vpe/plugins/org.jboss.tools.vpe.xulrunner/src/org/jboss/tools/vpe/xulrunner/browser/XulRunnerBrowser.java 2010-11-18
15:12:25 UTC (rev 26713)
@@ -15,6 +15,9 @@
import java.io.IOException;
import java.net.URL;
import java.text.MessageFormat;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Platform;
@@ -36,7 +39,6 @@
import org.mozilla.interfaces.nsIURI;
import org.mozilla.interfaces.nsIWebBrowser;
import org.mozilla.interfaces.nsIWebBrowserChrome;
-import org.mozilla.interfaces.nsIWebBrowserSetup;
import org.mozilla.interfaces.nsIWebNavigation;
import org.mozilla.interfaces.nsIWebProgress;
import org.mozilla.interfaces.nsIWebProgressListener;
@@ -57,31 +59,42 @@
private static final String XULRUNNER_HIGHER_VERSION = "1.9.2.9";
//$NON-NLS-1$
// TODO Sergey Vasilyev Think. May be XULRUNNER_BUNDLE shouldn't be final?
private static final String XULRUNNER_BUNDLE;
- private static final String XULRUNNER_ENTRY = "/xulrunner"; //$NON-NLS-1$
// TEMPORARY CODE (@see org.eclipse.swt.browser.Mozilla)
static final String XULRUNNER_INITIALIZED =
"org.eclipse.swt.browser.XULRunnerInitialized"; //$NON-NLS-1$
- static final String XULRUNNER_PATH = "org.eclipse.swt.browser.XULRunnerPath";
//$NON-NLS-1$
+ public static final String XULRUNNER_PATH =
"org.eclipse.swt.browser.XULRunnerPath"; //$NON-NLS-1$
private static final String ROOT_BRANCH_NAME = ""; //$NON-NLS-1$
private static final String PREFERENCE_DISABLEOPENDURINGLOAD =
"dom.disable_open_during_load"; //$NON-NLS-1$
private static final String PREFERENCE_DISABLEWINDOWSTATUSCHANGE =
"dom.disable_window_status_change"; //$NON-NLS-1$
-
- private static final Mozilla mozilla;
+
private Browser browser = null;
private nsIWebBrowser webBrowser = null;
private long chrome_flags = nsIWebBrowserChrome.CHROME_ALL;
public static final long NS_ERROR_FAILURE = 0x80004005L;
-
+ private static final String XULRUNNER_ENTRY = "/xulrunner"; //$NON-NLS-1$
+
+ public static final Set<String> OFFICIALLY_SUPPORTED_PLATFORM_IDS = new
HashSet<String>();
static {
- StringBuffer buff = new StringBuffer("org.mozilla.xulrunner");
- buff.append(".").append(Platform.getWS()) //$NON-NLS-1$
- .append(".").append(Platform.getOS()); //$NON-NLS-1$
+ Collections.addAll(OFFICIALLY_SUPPORTED_PLATFORM_IDS,
+ "carbon.macosx", //$NON-NLS-1$
+ "cocoa.macosx", //$NON-NLS-1$
+ "gtk.linux.x86", //$NON-NLS-1$
+ "gtk.linux.x86_64", //$NON-NLS-1$
+ "win32.win32.x86"); //$NON-NLS-1$
+ }
+ public static final String CURRENT_PLATFORM_ID;
+ private static final Mozilla mozilla;
+ static {
+ StringBuffer buff = new StringBuffer();
+ buff.append(Platform.getWS())
+ .append('.').append(Platform.getOS());
if(! Platform.OS_MACOSX.equals(Platform.getOS())) {
- buff.append(".").append(Platform.getOSArch());
+ buff.append('.').append(Platform.getOSArch());
}
- XULRUNNER_BUNDLE = buff.toString();
+ CURRENT_PLATFORM_ID = buff.toString();
+ XULRUNNER_BUNDLE = "org.mozilla.xulrunner." + CURRENT_PLATFORM_ID;
//$NON-NLS-1$
mozilla = Mozilla.getInstance();
}
@@ -460,4 +473,16 @@
}
}
+ /**
+ * Return {@code true} if and only if the current
+ * platform is officially supported in JBoss Tools.
+ * But {@code false} does not necessary mean that XULRunner
+ * cannot be run on the system.
+ *
+ * @see #CURRENT_PLATFORM_ID
+ * @see #OFFICIALLY_SUPPORTED_PLATFORM_IDS
+ */
+ public static boolean isCurrentPlatformOfficiallySupported() {
+ return OFFICIALLY_SUPPORTED_PLATFORM_IDS.contains(CURRENT_PLATFORM_ID);
+ }
}