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));
    }
  }
  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);
    }
  }
예제 #3
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.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) {
    }
  }
  /**
   * The action has been activated. The argument of the method represents the 'real' action sitting
   * in the workbench UI.
   *
   * @see IWorkbenchWindowActionDelegate#run
   */
  public void run(IAction action) {

    //
    //	<http://stackoverflow.com/questions/18151203/eclipse-plugin-how-to-open-standard-view-like-internalwebbrowser-with-java>
    //
    //			To open the `Internal Browser` you need this code:
    //
    //			    int style = IWorkbenchBrowserSupport.AS_EDITOR | IWorkbenchBrowserSupport.LOCATION_BAR
    // | IWorkbenchBrowserSupport.STATUS;
    //			    IWebBrowser browser = WorkbenchBrowserSupport.getInstance().createBrowser(style,
    // "MyBrowserID", "MyBrowserName", "MyBrowser Tooltip");
    //			    browser.openURL(new URL("http://www.google.de"));
    //
    //			Alternative:
    //
    //			    final IWebBrowser browser =
    // PlatformUI.getWorkbench().getBrowserSupport().createBrowser("abc");
    //			    browser.openURL(new URL("http://www.google.de"));

    int style =
        IWorkbenchBrowserSupport.AS_EDITOR
            | IWorkbenchBrowserSupport.LOCATION_BAR
            | IWorkbenchBrowserSupport.NAVIGATION_BAR
            | IWorkbenchBrowserSupport.STATUS;
    IWebBrowser browser;
    try {
      browser =
          WorkbenchBrowserSupport.getInstance()
              .createBrowser(
                  style,
                  Constants.LIST_BROWSER_ID,
                  Constants.LIST_BROWSER_NAME,
                  Constants.LIST_BROWSER_TOOLTIP);
    } catch (PartInitException e) {
      e.printStackTrace();
      MessageDialog.openError(
          window.getShell(),
          Constants.ERROR1_MESSAGE,
          Constants.ERROR1_MESSAGE + " to show " + Constants.LIST_BROWSER_NAME);
      return;
    }
    try {
      browser.openURL(Constants.listUrl);
    } catch (PartInitException e) {
      e.printStackTrace();
    }
  }