private void openMoreInformaionInBrowser() { String moreInformationUrl = studyParameters.getMoreInformationUrl(); try { if (WebBrowserPreference.getBrowserChoice() == WebBrowserPreference.EXTERNAL) { try { IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport(); support.getExternalBrowser().openURL(new URL(moreInformationUrl)); } catch (Exception e) { StatusHandler.fail( new Status( IStatus.ERROR, UiUsageMonitorPlugin.ID_PLUGIN, "Could not open url", e)); //$NON-NLS-1$ } } else { IWebBrowser browser = null; int flags = 0; 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(); // $NON-NLS-1$ browser = WorkbenchBrowserSupport.getInstance().createBrowser(flags, generatedId, null, null); browser.openURL(new URL(moreInformationUrl)); } } catch (PartInitException e) { MessageDialog.openError( Display.getDefault().getActiveShell(), "Browser init error", //$NON-NLS-1$ "Browser could not be initiated"); //$NON-NLS-1$ } catch (MalformedURLException e) { MessageDialog.openError( Display.getDefault().getActiveShell(), Messages.UsageDataPreferencePage_Url_Not_Found, NLS.bind(Messages.UsageDataPreferencePage_Unable_To_Open_X, moreInformationUrl)); } }
protected void openBrowser(ISonarResource sonarResource) { IWorkbenchBrowserSupport browserSupport = SonarUiPlugin.getDefault().getWorkbench().getBrowserSupport(); ProjectProperties properties = ProjectProperties.getInstance(sonarResource.getProject()); try { String url = new SonarUrls().resourceUrl(sonarResource); URL consoleURL = new URL(url); if (browserSupport.isInternalWebBrowserAvailable()) { browserSupport.createBrowser("id" + properties.getUrl().hashCode()).openURL(consoleURL); } else { browserSupport.getExternalBrowser().openURL(consoleURL); } } catch (Exception e) { LoggerFactory.getLogger(getClass()).error(e.getMessage(), e); } }
@Override public void linkActivated(HyperlinkEvent event) { try { String target = (String) event.getHref(); if ("action:open".equals(target)) // $NON-NLS-1$ { IHandlerService handlerService = (IHandlerService) getIntroSite().getService(IHandlerService.class); Object result = handlerService.executeCommand( "name.abuchen.portfolio.ui.commands.openFileCommand", null); // $NON-NLS-1$ if (result != null) PlatformUI.getWorkbench().getIntroManager().closeIntro(this); } else if ("action:new".equals(target)) // $NON-NLS-1$ { IHandlerService handlerService = (IHandlerService) getIntroSite().getService(IHandlerService.class); handlerService.executeCommand( "name.abuchen.portfolio.ui.commands.newFileCommand", null); // $NON-NLS-1$ PlatformUI.getWorkbench().getIntroManager().closeIntro(this); } else if ("action:sample".equals(target)) // $NON-NLS-1$ { openSample("kommer.xml"); // $NON-NLS-1$ } else if ("action:daxsample".equals(target)) // $NON-NLS-1$ { openSample("dax.xml"); // $NON-NLS-1$ } else if (target.startsWith("http://")) // $NON-NLS-1$ { IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport(); IWebBrowser browser = support.getExternalBrowser(); browser.openURL(new URL(target)); } } catch (CommandException e) { PortfolioPlugin.log(e); MessageDialog.openError(getIntroSite().getShell(), Messages.LabelError, e.getMessage()); } catch (PartInitException e) { PortfolioPlugin.log(e); MessageDialog.openError(getIntroSite().getShell(), Messages.LabelError, e.getMessage()); } catch (MalformedURLException e) { PortfolioPlugin.log(e); MessageDialog.openError(getIntroSite().getShell(), Messages.LabelError, e.getMessage()); } }
public static void openUrl(String location) { 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) { GroovyCore.logException("Could not open browser", e); } } else { IWebBrowser browser = null; int flags = 0; 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 id = "org.eclipse.contribution.weaving.jdt"; browser = WorkbenchBrowserSupport.getInstance().createBrowser(flags, id, null, null); browser.openURL(url); } } catch (PartInitException e) { MessageDialog.openError( Display.getDefault().getActiveShell(), "Browser initialization error", "Browser could not be initiated"); } catch (MalformedURLException e) { MessageDialog.openInformation( Display.getDefault().getActiveShell(), "Malformed URL", location); } }
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.grails.ide.eclipse.ui-" + 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) { } }
/** * Open a URL in a browser. * * @param url * @param internal In case true, the system will try to open the internal browser if it's * available. * @param style the Browser's style, in case an internal browser is requested. * @return A boolean value indicating a successful operations or not. */ public static boolean openInBroswer(URL url, boolean internal, int style) { IWorkbench workbench = PlatformUI.getWorkbench(); if (workbench != null) { IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport(); try { if (internal && support.isInternalWebBrowserAvailable()) { support.createBrowser(style, INTERNAL_HELP_BROWSER_ID, null, null).openURL(url); } else { support.getExternalBrowser().openURL(url); } } catch (PartInitException e) { IdeLog.logError(UIPlugin.getDefault(), "Error opening the help", e); // $NON-NLS-1$ return false; } return true; } return false; }
@Override protected Object run(final Presentation context) { final DiagramNodePart part = (DiagramNodePart) context.part(); final Location location = (Location) part.getModelElement(); final String locationName = location.getName().text(); if (locationName != null) { try { final IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport(); final IWebBrowser browser = support.getExternalBrowser(); final URL url = new URL("http://en.wikipedia.org/wiki/" + locationName); browser.openURL(url); } catch (MalformedURLException e) { Sapphire.service(LoggingService.class).log(e); } catch (PartInitException e) { Sapphire.service(LoggingService.class).log(e); } } return null; }