示例#1
0
  @Override
  @SuppressWarnings("unchecked")
  public void selectionChanged(final SelectionChangedEvent event) {
    TreeSelection selection = (TreeSelection) event.getSelection();

    Object o = selection.getFirstElement();
    if (o == null || o instanceof NoDatabaseRoot) {
      doc.setText("");
      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();
      }
    }

    if (result != null) {
      String text = "";
      switch (result.getType()) {
        case KEYWORD:
          text = HtmlUtil.generateDocument("keyword " + result.getName(), "");
          break;
        case PACKAGE:
          HaskellPackage pkg = ((HoogleResultPackage) result).getPackage();
          text =
              HtmlUtil.generateDocument("package " + pkg.getIdentifier().toString(), pkg.getDoc());
          break;
        case MODULE:
          HoogleResultModule mod = (HoogleResultModule) result;
          text =
              HtmlUtil.generateDocument(
                  "module " + mod.getName(),
                  mod.getPackageIdentifiers(),
                  null,
                  false,
                  mod.getModule().getDoc());
          break;
        case DECLARATION:
          HoogleResultDeclaration decl = (HoogleResultDeclaration) result;
          text =
              HtmlUtil.generateDocument(
                  decl.getDeclaration().getCompleteDefinition(),
                  decl.getPackageIdentifiers(),
                  decl.getModule(),
                  false,
                  decl.getDeclaration().getDoc());
          break;
        case CONSTRUCTOR:
          HoogleResultConstructor con = (HoogleResultConstructor) result;
          text =
              HtmlUtil.generateDocument(
                  con.getConstructor().getCompleteDefinition(),
                  con.getPackageIdentifiers(),
                  con.getModule(),
                  false,
                  con.getDeclaration().getDoc());
          break;
        case WARNING: // not in tree
          break;
      }

      doc.setText(text);
    } else {
      doc.setText(HtmlUtil.generateText(UITexts.browser_definedInSeveralLocations));
    }
  }