@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);
    }
  }
    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();
      }
    }
Ejemplo n.º 3
0
 @Override
 public Object execute(ExecutionEvent event) throws ExecutionException {
   try {
     IWorkbenchBrowserSupport browserSupport = PlatformUI.getWorkbench().getBrowserSupport();
     browserSupport
         .createBrowser(IWorkbenchBrowserSupport.AS_EDITOR, "prob", "prob2", "prob3")
         .openURL(new URL("http://localhost:" + WebConsole.getPort() + "/"));
   } catch (PartInitException e) {
     e.printStackTrace();
   } catch (MalformedURLException e) {
     e.printStackTrace();
   }
   return null;
 }
  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));
    }
  }
Ejemplo n.º 5
0
  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);
    }
  }
Ejemplo n.º 6
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);
    }
  }
Ejemplo n.º 8
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) {
    }
  }
Ejemplo n.º 9
0
  /**
   * 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;
  }
Ejemplo n.º 11
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;
  }
Ejemplo n.º 12
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
      }
    }
  }