public void open() {
      // Create the browser
      IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport();
      IWebBrowser browser;
      try {
        browser = support.createBrowser(null);
      } catch (PartInitException e) {
        SadlActivatorExt.getInstance()
            .getLog()
            .log(
                new Status(
                    IStatus.ERROR,
                    SadlActivatorExt.getInstance().getBundle().getSymbolicName(),
                    "Could not create Web browser for URLHyperlink",
                    e)); //$NON-NLS-1$
        super.open();
        return;
      }

      try {
        browser.openURL(new URL(getURLString()));
      } catch (PartInitException e) {
        super.open();
      } catch (MalformedURLException e) {
        super.open();
      }
    }
  @Override
  public void widgetSelected(SelectionEvent e) {

    String formType = "/Model_Type/";
    String args = "?";
    int i = 1;

    if (modelType.getName() != null) args = args + "name=" + modelType.getName();
    if (modelType.getSupertype() != null)
      args = args + "&supertype=" + modelType.getSupertype().getName();

    if (modelType instanceof ModelRel) {
      formType = "/Relationship_Type/";

      ModelRel modelRelType = (ModelRel) modelType;

      if (!modelRelType.getModelEndpoints().isEmpty()) args = args + "&arguments=";

      for (ModelEndpoint modelEndpoint : modelRelType.getModelEndpoints()) {
        if (i != 1) args = args + ", ";
        args = args + modelEndpoint.getName() + ";" + modelEndpoint.getTarget().getName();
        i++;
      }
    }

    IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport();
    String url = WIKI_WWW + formType + modelType.getName() + args;
    try {
      IWebBrowser browser = support.createBrowser("MMINT Wiki");
      browser.openURL(new URL(url));
    } catch (Exception ex) {
      MMINTException.print(IStatus.ERROR, "Error opening wiki page " + url, ex);
    }
  }
 private static void openURL(String strURL) {
   if (Program.launch(strURL)) {
     return;
   }
   URL openURL = null;
   try {
     openURL = new URL(strURL);
     PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(openURL);
   } catch (PartInitException e) {
     // if no default browser (like on linux), try to open directly with firefox.
     try {
       Runtime.getRuntime().exec("firefox " + openURL.toString()); // $NON-NLS-1$
     } catch (IOException e2) {
       if (PlatformUI.getWorkbench().getBrowserSupport().isInternalWebBrowserAvailable()) {
         IWebBrowser browser;
         try {
           browser =
               PlatformUI.getWorkbench()
                   .getBrowserSupport()
                   .createBrowser("registrationId"); // $NON-NLS-1$
           browser.openURL(openURL);
         } catch (PartInitException e1) {
           ExceptionHandler.process(e);
         }
       } else {
         ExceptionHandler.process(e);
       }
     }
   } catch (MalformedURLException e) {
     ExceptionHandler.process(e);
   }
 }
 /**
  * Opens an internal browser with the URL that is given in the attributes.
  *
  * @param attributes We expect for an array that contains a single string URL.
  * @return {@link IBrowserNotificationConstants#JSON_OK} or a {@link
  *     IBrowserNotificationConstants#JSON_ERROR}
  */
 @ControllerAction
 public Object internalOpen(Object attributes) {
   URL url = getURL(attributes);
   if (url == null) {
     return IBrowserNotificationConstants.JSON_ERROR;
   }
   try {
     IWebBrowser browser =
         PortalUIPlugin.getDefault()
             .getWorkbench()
             .getBrowserSupport()
             .createBrowser(
                 IWorkbenchBrowserSupport.AS_EDITOR
                     | IWorkbenchBrowserSupport.LOCATION_BAR
                     | IWorkbenchBrowserSupport.STATUS
                     | IWorkbenchBrowserSupport.NAVIGATION_BAR,
                 url.toString(),
                 null,
                 null);
     browser.openURL(url);
   } catch (PartInitException e) {
     PortalUIPlugin.logError(e);
     return IBrowserNotificationConstants.JSON_ERROR;
   }
   return IBrowserNotificationConstants.JSON_OK;
 }
  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));
    }
  }
 @Override
 protected void configure() {
   // We usually just cancel the launch.
   setSelectedLauncher(null);
   IWebBrowser externalBrowser;
   try {
     externalBrowser = PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser();
     externalBrowser.openURL(new URL("http://developer.apple.com/devcenter/ios"));
   } catch (Exception e) {
     Policy.getStatusHandler()
         .show(
             new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Could not open browser", e),
             "Could not open browser");
   }
 }
  /**
   * 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();
    }
  }
  void registerBrowser(IWebBrowser browser) {
    // don't track non-internal browsers, because we have no way of tracking
    // when they're closed
    if (!(browser instanceof InternalWebBrowser)) {
      return;
    }

    browsers.put(browser.getId(), browser);
  }
Esempio n. 9
0
  @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);
    }
  }
Esempio n. 11
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) {
    }
  }
  @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;
  }
 void unregisterBrowser(IWebBrowser browser) {
   browsers.remove(browser.getId());
   fireBrowserClosed(browser);
 }
Esempio n. 14
0
  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection =
        HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
    if (selection != null & selection instanceof IStructuredSelection) {
      IStructuredSelection strucSelection = (IStructuredSelection) selection;

      for (Object obj : strucSelection.toArray()) {
        System.out.println("Object =" + obj.toString());
        if (obj instanceof ui_TaxonomyTreeItem) {
          if ((((ui_TaxonomyTreeItem) obj).getOfficeElement()
              instanceof RequestedFederationScenario)) {
            // http://nam.ece.upatras.gr/fstoolkit/utils/resourcesmap.php?x[0]=38.288291,21.788884
            String req = "";
            RequestedFederationScenario scenario =
                (RequestedFederationScenario) ((ui_TaxonomyTreeItem) obj).getOfficeElement();

            ArrayList<myMarker> sitelist = new ArrayList<myMarker>();
            for (ResourceRequest resReq :
                scenario.getInfrastructureRequest().getReqOfferedResources()) {
              if (resReq.getRefOfferedResource() != null) {
                System.out.println(
                    "resReq.getRefOfferedResource() = " + resReq.getRefOfferedResource().getName());

                Site site = (Site) resReq.getRefOfferedResource().eContainer();

                if ((site != null) && (!sitelist.contains(site))) {
                  myMarker mymarker = null;
                  for (myMarker m : sitelist) {
                    if (m.site.equals(site)) mymarker = m;
                  }
                  if (mymarker == null) {
                    mymarker = new myMarker();
                    mymarker.site = site;
                    mymarker.descriptions = "";
                    sitelist.add(mymarker);
                  }
                  mymarker.descriptions +=
                      resReq.getName()
                          + " : <i>"
                          + resReq.getRefOfferedResource().getName()
                          + "</i></br>";
                }
              }
            }
            int i = 0;
            for (myMarker mymarker : sitelist) {
              if (mymarker.site.getLocatedAt() != null) {
                ResourcesProvider r = (ResourcesProvider) mymarker.site.eContainer();
                req = req + "x[" + i + "]=" + mymarker.site.getLocatedAt().getGeocoords() + "&";
                req =
                    req
                        + "c["
                        + i
                        + "]=<b>"
                        + r.getName()
                        + "</b><br>"
                        + "<small>"
                        + mymarker.descriptions
                        + "</small>"
                        + "&";
              }
              i++;
            }

            req = req.substring(0, req.length() - 1);
            req = "http://nam.ece.upatras.gr/fstoolkit/utils/resourcesmap.php?" + req;
            System.out.println("req = " + req);

            IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport();
            IWebBrowser browser;
            try {

              browser =
                  support.createBrowser(
                      IWorkbenchBrowserSupport.AS_VIEW,
                      ((ui_TaxonomyTreeItem) obj).getOfficeElement().getName()
                          + ".webbrowser.fstoolkit",
                      "Map for " + ((ui_TaxonomyTreeItem) obj).getOfficeElement().getName(),
                      "A world map for "
                          + ((ui_TaxonomyTreeItem) obj).getOfficeElement().getName());

              browser.openURL(new URL(req));

            } catch (PartInitException e) {
              e.printStackTrace();
            } catch (MalformedURLException e) {
              e.printStackTrace();
            }
          }
        }
      }
    }
    return null;
  }
Esempio n. 15
0
  @SuppressWarnings("unchecked")
  public void doubleClick(final DoubleClickEvent event) {
    TreeSelection selection = (TreeSelection) event.getSelection();
    Object o = selection.getFirstElement();
    if (o == null || o instanceof NoDatabaseRoot) {
      return;
    }

    // Try to find element to show
    HoogleResult result = null;
    if (o instanceof HoogleResult) {
      result = (HoogleResult) o;
    } else {
      Map.Entry<String, Object> entry = (Map.Entry<String, Object>) o;
      if (entry.getValue() instanceof HoogleResult) {
        result = (HoogleResult) entry.getValue();
      } else {
        // Show the first one (better than nothing)
        result = ((ArrayList<HoogleResult>) entry.getValue()).get(0);
      }
    }

    String url = null;
    switch (result.getType()) {
      case PACKAGE:
        HoogleResultPackage pkg = (HoogleResultPackage) result;
        url = HtmlUtil.generatePackageUrl(pkg.getPackage().getIdentifier());
        break;
      case MODULE:
        HoogleResultModule mod = (HoogleResultModule) result;
        url = HtmlUtil.generateModuleUrl(mod.getPackageIdentifiers().get(0), mod.getName());
        break;
      case CONSTRUCTOR:
        HoogleResultConstructor con = (HoogleResultConstructor) result;
        url =
            HtmlUtil.generateElementUrl(
                con.getPackageIdentifiers().get(0), con.getModule(), true, con.getName());
        break;
      case DECLARATION:
        HoogleResultDeclaration decl = (HoogleResultDeclaration) result;
        url =
            HtmlUtil.generateElementUrl(
                decl.getPackageIdentifiers().get(0),
                decl.getModule(),
                decl.getDeclaration().getType() == DeclarationType.FUNCTION,
                decl.getName());
        break;
    }

    // Open browser
    if (url != null) {
      try {
        IWorkbenchBrowserSupport browserSupport =
            this.getSite().getWorkbenchWindow().getWorkbench().getBrowserSupport();
        URL webUrl = new URL(url);
        IWebBrowser browser =
            browserSupport.createBrowser(
                IWorkbenchBrowserSupport.AS_EDITOR | IWorkbenchBrowserSupport.LOCATION_BAR,
                null,
                "Haskell Browser",
                "Haskell Browser");
        browser.openURL(webUrl);
      } catch (Throwable ex) {
        // Do nothing
      }
    }
  }