blob: 514ba44882cadca8696cb7bda6c43c0a0c2e197b [file] [log] [blame]
/*********************************************************************
* Copyright (c) 2009, 2012 SpringSource, a division of VMware, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
package org.eclipse.virgo.ide.runtime.internal.ui.editor;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Calendar;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.browser.IWebBrowser;
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
import org.eclipse.ui.internal.browser.WebBrowserPreference;
import org.eclipse.ui.internal.browser.WorkbenchBrowserSupport;
/**
* @author Christian Dupuis
* @since 1.0.0
*/
@SuppressWarnings("restriction")
public class WebUiUtils {
public static void openUrl(String location) {
openUrl(location, 0);
}
private static void openUrl(String location, int customFlags) {
try {
URL url = null;
if (location != null) {
url = new URL(location);
}
if (WebBrowserPreference.getBrowserChoice() == WebBrowserPreference.EXTERNAL) {
try {
IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport();
support.getExternalBrowser().openURL(url);
} catch (Exception e) {
}
} else {
IWebBrowser browser = null;
int flags = customFlags;
if (WorkbenchBrowserSupport.getInstance().isInternalWebBrowserAvailable()) {
flags |= IWorkbenchBrowserSupport.AS_EDITOR | IWorkbenchBrowserSupport.LOCATION_BAR | IWorkbenchBrowserSupport.NAVIGATION_BAR;
} else {
flags |= IWorkbenchBrowserSupport.AS_EXTERNAL | IWorkbenchBrowserSupport.LOCATION_BAR | IWorkbenchBrowserSupport.NAVIGATION_BAR;
}
String generatedId = "org.eclipse.mylyn.web.browser-" + Calendar.getInstance().getTimeInMillis();
browser = WorkbenchBrowserSupport.getInstance().createBrowser(flags, generatedId, null, null);
browser.openURL(url);
}
} catch (PartInitException e) {
MessageDialog.openError(Display.getDefault().getActiveShell(), "Browser init error", "Browser could not be initiated");
} catch (MalformedURLException e) {
}
}
}