protected IWebBrowser doCreateBrowser(int style, String browserId, String name, String tooltip)
      throws PartInitException {

    // external browser is not required by called or user
    if (((style & AS_EXTERNAL) == 0)
        && (WebBrowserPreference.getBrowserChoice() == WebBrowserPreference.INTERNAL)) {
      return new InternalWebBrowser(this, browserId);
    }

    IWebBrowser webBrowser = null;

    // AS_EXTERNAL will force the external browser regardless of the user
    // preference
    // The help editor will open in an editor regardless of the user
    // preferences
    boolean isHelpEditor = ((style & AS_EDITOR) != 0) && HELP_BROWSER_ID.equals(browserId);
    if ((style & AS_EXTERNAL) != 0
        || (WebBrowserPreference.getBrowserChoice() != WebBrowserPreference.INTERNAL
            && !isHelpEditor)
        || !WebBrowserUtil.canUseInternalWebBrowser()) {
      IBrowserDescriptor ewb = BrowserManager.getInstance().getCurrentWebBrowser();
      if (ewb == null) throw new PartInitException("Error No Browser detected");

      if (ewb instanceof SystemBrowserDescriptor) webBrowser = new SystemBrowserInstance(browserId);
      else {
        IBrowserExt ext = null;
        if (ewb != null) ext = WebBrowserUIPlugin.findBrowsers(getLocation(ewb));
        if (ext != null)
          webBrowser = ext.createBrowser(browserId, getLocation(ewb), ewb.getParameters());
        if (webBrowser == null) webBrowser = new ExternalBrowserInstance(browserId, ewb);
      }
    } else {
      if ((style & IWorkbenchBrowserSupport.AS_VIEW) != 0)
        webBrowser = new InternalBrowserViewInstance(browserId, style, name, tooltip);
      else webBrowser = new InternalBrowserEditorInstance(browserId, style, name, tooltip);
    }

    return webBrowser;
  }
  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);
    }
  }
Beispiel #4
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) {
    }
  }