Author: adietish
Date: 2011-09-30 04:39:11 -0400 (Fri, 30 Sep 2011)
New Revision: 35198
Added:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/browser/
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/browser/BrowserUtil.java
Modified:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/CommonUIMessages.java
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/messages.properties
Log:
[JBIDE-9805] copied BrowserUtil to commons.ui
Modified:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/CommonUIMessages.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/CommonUIMessages.java 2011-09-30
08:32:29 UTC (rev 35197)
+++
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/CommonUIMessages.java 2011-09-30
08:39:11 UTC (rev 35198)
@@ -66,6 +66,10 @@
public static String BUTTON_REMOVE;
+ public static String BROWSER_COULD_NOT_OPEN_BROWSER;
+
+ public static String BROWSER_COULD_NOT_DISPLAY_MALFORMED_URL;
+
static {
NLS.initializeMessages(BUNDLE_NAME, CommonUIMessages.class);
}
Added:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/browser/BrowserUtil.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/browser/BrowserUtil.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/browser/BrowserUtil.java 2011-09-30
08:39:11 UTC (rev 35198)
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * 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.common.ui.browser;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.text.MessageFormat;
+
+import org.eclipse.core.runtime.ILog;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.browser.IWebBrowser;
+import org.jboss.tools.common.ui.CommonUIMessages;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class BrowserUtil {
+
+ /**
+ * Opens a browser for the given url with the given id. If an error occurs
+ * it will be reported to the given log provider with the given plugin id.
+ *
+ * @param url
+ * the url to open a browser for.
+ * @param browserId
+ * the id for the new browser.
+ * @param pluginId
+ * the plugin id to log for.
+ * @param log
+ * the log provider to log against if an error occurred.
+ */
+ public static void checkedCreateInternalBrowser(String url, String browserId, String
pluginId, ILog log) {
+ try {
+ openUrl(url, PlatformUI.getWorkbench().getBrowserSupport().createBrowser(browserId),
pluginId, log);
+ } catch (PartInitException e) {
+ IStatus errorStatus = createErrorStatus(pluginId,
CommonUIMessages.BROWSER_COULD_NOT_OPEN_BROWSER, e, url);
+ log.log(errorStatus);
+ }
+ }
+
+ private static IStatus createErrorStatus(String pluginId, String message, Throwable e,
+ Object... messageArguments) {
+ String formattedMessage = null;
+ if (message != null) {
+ formattedMessage = MessageFormat.format(message, messageArguments);
+ }
+ return new Status(Status.ERROR, pluginId, Status.ERROR, formattedMessage, e);
+ }
+
+ public static void checkedCreateExternalBrowser(String url, String pluginId, ILog log)
{
+ try {
+ openUrl(url, PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser(),
pluginId, log);
+ } catch (PartInitException e) {
+ IStatus errorStatus = createErrorStatus(pluginId,
CommonUIMessages.BROWSER_COULD_NOT_OPEN_BROWSER, e, url);
+ log.log(errorStatus);
+ }
+ }
+
+ public static void openUrl(String url, IWebBrowser browser, String pluginId, ILog log)
{
+ try {
+ browser.openURL(new URL(url));
+ } catch (PartInitException e) {
+ IStatus errorStatus = createErrorStatus(pluginId,
CommonUIMessages.BROWSER_COULD_NOT_OPEN_BROWSER, e, url);
+ log.log(errorStatus);
+ } catch (MalformedURLException e) {
+ IStatus errorStatus = createErrorStatus(pluginId,
CommonUIMessages.BROWSER_COULD_NOT_DISPLAY_MALFORMED_URL, e,
+ url);
+ log.log(errorStatus);
+ }
+ }
+}
Property changes on:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/browser/BrowserUtil.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/messages.properties
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/messages.properties 2011-09-30
08:32:29 UTC (rev 35197)
+++
trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/messages.properties 2011-09-30
08:39:11 UTC (rev 35198)
@@ -25,4 +25,7 @@
TEXT_FIELD_EDITOR_EDITOR_SUPPORTS_ONLY_GRID_LAYOUT=Editor supports only grid layout
BUTTON_ADD=Add
-BUTTON_REMOVE=Remove
\ No newline at end of file
+BUTTON_REMOVE=Remove
+
+BROWSER_COULD_NOT_OPEN_BROWSER=Could not open browser for url \"{0}\".
+BROWSER_COULD_NOT_DISPLAY_MALFORMED_URL=Could not display malformed url
\"{0}\".
\ No newline at end of file