Example #1
0
  @Override
  @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);
      }
    }
    IWorkbenchPage page = getSite().getPage();

    switch (result.getType()) {
      case KEYWORD:
        OpenDefinitionHandler.openExternalDefinition(
            page, null, null, null, result.getName(), null);
        break;
      case PACKAGE:
        HoogleResultPackage pkg = (HoogleResultPackage) result;
        OpenDefinitionHandler.openExternalDefinition(
            page, null, pkg.getPackage().getIdentifier().toString(), null, null, null);
        break;
      case MODULE:
        HoogleResultModule mod = (HoogleResultModule) result;
        OpenDefinitionHandler.openExternalDefinition(
            page, null, mod.getPackageIdentifiers().get(0).toString(), mod.getName(), null, null);
        break;
      case CONSTRUCTOR:
        HoogleResultConstructor con = (HoogleResultConstructor) result;
        OpenDefinitionHandler.openExternalDefinition(
            page,
            null,
            con.getPackageIdentifiers().get(0).toString(),
            con.getModule(),
            con.getName(),
            "v");
        break;
      case DECLARATION:
        HoogleResultDeclaration decl = (HoogleResultDeclaration) result;
        OpenDefinitionHandler.openExternalDefinition(
            page,
            null,
            decl.getPackageIdentifiers().get(0).toString(),
            decl.getModule(),
            decl.getName(),
            decl.getDeclaration().getType() == DeclarationType.FUNCTION ? "v" : "t");
        break;
      case WARNING: // not in tree
        break;
    }
  }
Example #2
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
      }
    }
  }