Esempio n. 1
0
  public LibraryData(HorizontalPanel lp, DrakeGeneticsServiceAsync drakeGeneticsService) {
    this.libraryPanel = lp;

    final DrakeGeneticsServiceAsync dgs = drakeGeneticsService;
    drakeGeneticsService.getLibrary(
        new AsyncCallback<LibraryNode>() {
          public void onSuccess(LibraryNode results) {
            getTreeModelSucceeded(results, dgs);
          }

          public void onFailure(Throwable caught) {
            getTreeModelFailed(caught);
          }
        });

    treePanel.setHeaderVisible(true);
    treePanel.setLayout(new FitLayout());
    treePanel.setHeading("Publications");

    tree.setDisplayProperty("name");
    tree.setWidth(200);
    // tree.setHeight(450);
    tree.setHeight(670);
    tree.addListener(
        Events.OnClick,
        new Listener<TreePanelEvent<ModelData>>() {

          public void handleEvent(TreePanelEvent<ModelData> be) {
            ModelData item = be.getItem();
            String url = (String) item.get("url");
            if (url != null && !url.equals("")) {
              if (url.startsWith("/")) {
                url = url.substring(1);
              }
              libraryDocumentPanel.setUrl(GWT.getHostPageBaseURL() + url);
            }
          }
        });

    treePanel.add(tree);

    libraryPanel.add(treePanel);

    libraryDocumentPanel.setHeaderVisible(false);
    libraryDocumentPanel.setWidth(494);
    // libraryDocumentPanel.setHeight(451);
    libraryDocumentPanel.setHeight(671);
    libraryDocumentPanel.setUrl(GWT.getHostPageBaseURL() + "Library/index.html");
    libraryPanel.add(libraryDocumentPanel);
  }
Esempio n. 2
0
  /**
   * Method used to transfer the nodes of a LibrayNode based tree to a BaseTreeModel based tree of
   * Folder and Document objects for use in a GXT display
   *
   * @param node A LibraryNode object that was returned from the server
   * @return The equivalent BaseTreeModel node (Folder or Document) for display in a GXT Widget.
   */
  private BaseTreeModel parseLibraryNode(
      LibraryNode node, TreeModel parent, DrakeGeneticsServiceAsync drakeGeneticsService) {
    BaseTreeModel displayNode = null;

    if (node.isDocument()) {

      GWT.log(node.getDisplayName() + "--" + node.getFileName());
      final Document document = new Document(node.getDisplayName(), node.getFileName());
      if (parent != null) {
        document.setParent(parent);
      }

      // Add code here to actually fetch the document and add it to
      // the Document object
      List<String> path = new ArrayList<String>();
      path.add(document.getDocument());
      Folder fParent = (Folder) parent;
      if (!fParent.getName().equals("/Library/")) {
        path.add(fParent.getName());
        Folder curParent = (Folder) parent.getParent();
        while (curParent != null) {
          if (!curParent.getName().equals("/Library/")) path.add(curParent.getName());
          curParent = (Folder) curParent.getParent();
        }
      }
      Collections.reverse(path);
      GWT.log(path.toString());

      drakeGeneticsService.getPublication(
          path,
          new AsyncCallback<String>() {
            public void onSuccess(String documentUrl) {
              GWT.log(document.getName());
              GWT.log(" Node URL = " + documentUrl);
              document.setUrl(documentUrl);
              tree.repaint();
            }

            public void onFailure(Throwable caught) {
              getTreeModelFailed(caught);
            }
          });
      displayNode = document;

    } else if (node.isLeaf()) {
      displayNode = new Folder(node.getData());
      if (parent != null) {
        displayNode.setParent(parent);
      }

    } else {
      displayNode = new Folder(node.getData());
      if (parent != null) {
        displayNode.setParent(parent);
      }
      for (int i = 0; i < node.getChildCount(); i++) {
        displayNode.add(
            parseLibraryNode((LibraryNode) node.getChild(i), displayNode, drakeGeneticsService));
      }
    }

    return displayNode;
  }