private void removeNodeFromParent(DefaultMutableTreeNode node) {
    TreeNode parent = node.getParent();
    int idx = parent.getIndex(node);
    node.removeFromParent();

    (getModel()).nodesWereRemoved(parent, new int[] {idx}, new TreeNode[] {node});
  }
  public int createTreeFromMenuBar(
      javax.swing.MenuElement subElements[],
      javax.swing.tree.DefaultMutableTreeNode treeNodes,
      javax.swing.tree.DefaultMutableTreeNode topReports,
      java.lang.String reportNodeTitle,
      java.lang.String utilitiesNodeTitle) {

    for (int i = 0; i < subElements.length; i++) {

      if (subElements[i].getClass().getName() != "javax.swing.JPopupMenu") {

        javax.swing.JMenuItem abstractButton = (javax.swing.JMenuItem) subElements[i];

        if (abstractButton.isEnabled()) {

          siblingNode = new javax.swing.tree.DefaultMutableTreeNode(abstractButton.getText());

          treeNodes.add(siblingNode);

          if (treeNodes.getUserObject() == "Reports") {

            treeNodes.setUserObject(reportNodeTitle);

            topReports.add(treeNodes);
          }

          if (treeNodes.getUserObject() == "Utility") {

            treeNodes.setUserObject(utilitiesNodeTitle);

            topReports.add(treeNodes);
          }
        }
      }

      if (subElements[i].getSubElements().length > 0) {

        createTreeFromMenuBar(
            subElements[i].getSubElements(),
            siblingNode,
            topReports,
            reportNodeTitle,
            utilitiesNodeTitle);

        if (treeNodes.isLeaf()) {

          javax.swing.tree.DefaultMutableTreeNode parentNode =
              (javax.swing.tree.DefaultMutableTreeNode) siblingNode.getParent();

          siblingNode.removeFromParent();
        }
      }

      treeCount++;
    }

    return treeCount;
  }
Exemplo n.º 3
0
  public void viderNoeud(DefaultMutableTreeNode selectednode) {
    int nbchildren = selectednode.getChildCount();

    for (int i = 0; i < nbchildren; i++) {
      if (selectednode.getChildAt(0).isLeaf()) {
        ((DefaultMutableTreeNode) selectednode.getChildAt(0)).removeFromParent();
      } else {
        viderNoeud((DefaultMutableTreeNode) selectednode.getChildAt(0));
      }
    }
    if (!selectednode.isRoot()) {
      selectednode.removeFromParent();
    }
  }
Exemplo n.º 4
0
  /**
   * The abstract function that descendant classes must be overridden to provide customsized
   * handling.
   *
   * @param e
   * @return true if the action is finished successfully; otherwise, return false.
   */
  protected boolean doAction(ActionEvent e) throws Exception {

    // System.out.println("Delete node clicked.......");
    if (treeNode == null) {
      // System.out.println("Tree node null returning.......");
      return false;
    }

    DefaultEdge[] linkEdge = null;
    DefaultEdge linkEdgeTemp = null;
    DefaultPort[] srcPort = null;
    DefaultPort srcPortTemp = null;
    DefaultPort[] tgtPort = null;
    DefaultPort tgtPortTemp = null;
    for (Object child : MainFrame.getMappingMainPanel().getMiddlePanel().getGraph().getRoots()) {
      if (child instanceof DefaultEdge) {
        linkEdge = new DefaultEdge[2];
        srcPort = new DefaultPort[1];
        tgtPort = new DefaultPort[1];
        linkEdgeTemp = (DefaultEdge) child;
        // linkEdge[0] = linkEdgeTemp;
        srcPortTemp = (DefaultPort) linkEdgeTemp.getSource();
        srcPort[0] = srcPortTemp;
        tgtPortTemp = (DefaultPort) linkEdgeTemp.getTarget();
        tgtPort[0] = tgtPortTemp;
        Iterator edges = srcPortTemp.getEdges().iterator();
        int i = 0;
        while (edges.hasNext()) {
          linkEdge[i] = (DefaultEdge) edges.next();
          i++;
        }

        Object sourceNode = srcPortTemp.getUserObject();
        if (sourceNode instanceof DefaultMutableTreeNode) {
          DefaultMutableTreeNode srcTreeNode = (DefaultMutableTreeNode) sourceNode;
          if (srcTreeNode.getParent().equals(treeNode)) {

            MainFrame.getMappingMainPanel()
                .getMiddlePanel()
                .getGraphController()
                .removeCells(linkEdge, true);
            // MainFrame.getMappingMainPanel().getMiddlePanel().getGraphController().removeCells(tgtPort,true);
            MainFrame.getMappingMainPanel().getTargetScrollPane().repaint();
          }
        }
      }
    }
    // System.out.println("Before Tree node removal.......");
    if (treeNode.getParent() != null) {
      treeNode.removeFromParent();
    } else {
      tree.removeAll();
    }
    // remove the resource from the list
    MainFrame.getMappingMainPanel().getPOJOClassList().remove(treeNode.toString());
    // System.out.println("TREENODE STR..."+treeNode.toString());
    //
    tree.updateUI();
    //
    if (MainFrame.getMappingMainPanel().getMappingTargetFile() != null) {
      Mapping mappingData =
          MainFrame.getMappingMainPanel()
              .getMiddlePanel()
              .getGraphController()
              .retrieveMappingData(true, "Temp");
      if (mappingData != null) {
        MainFrame.getMappingMainPanel()
            .getMiddlePanel()
            .getGraphController()
            .setMappingData(mappingData, true);
        MainFrame.getMappingMainPanel().getMiddlePanel().setMappingNamesforLinkInGraph(mappingData);
      }
    }
    return true;
  }
  /* Clear all existing nodes from the tree model and rebuild from scratch.
   */
  protected void refreshTree() {

    DefaultMutableTreeNode propertiesNode;
    DefaultMutableTreeNode leaf;

    // First clear the existing tree by simply enumerating
    // over the root node's children and removing them one by one.
    while (treeModel.getChildCount(rootNode) > 0) {
      DefaultMutableTreeNode child = (DefaultMutableTreeNode) treeModel.getChild(rootNode, 0);

      treeModel.removeNodeFromParent(child);
      child.removeAllChildren();
      child.removeFromParent();
    }

    treeModel.nodeStructureChanged(rootNode);
    treeModel.reload();
    tScrollPane.repaint();

    // Now rebuild the tree below its root
    try {

      // Start by naming the root node from its URL:
      rootNode.setUserObject(dMeta.getURL());

      // get metadata about user tables by building a vector of table names
      String usertables[] = {"TABLE", "GLOBAL TEMPORARY", "VIEW"};
      ResultSet result = dMeta.getTables(null, null, null, usertables);
      Vector tables = new Vector();

      // sqlbob@users Added remarks.
      Vector remarks = new Vector();

      while (result.next()) {
        tables.addElement(result.getString(3));
        remarks.addElement(result.getString(5));
      }

      result.close();

      // For each table, build a tree node with interesting info
      for (int i = 0; i < tables.size(); i++) {
        String name = (String) tables.elementAt(i);
        DefaultMutableTreeNode tableNode = makeNode(name, rootNode);
        ResultSet col = dMeta.getColumns(null, null, name, null);

        // sqlbob@users Added remarks.
        String remark = (String) remarks.elementAt(i);

        if ((remark != null) && !remark.trim().equals("")) {
          makeNode(remark, tableNode);
        }

        // With a child for each column containing pertinent attributes
        while (col.next()) {
          String c = col.getString(4);
          DefaultMutableTreeNode columnNode = makeNode(c, tableNode);
          String type = col.getString(6);

          makeNode("Type: " + type, columnNode);

          boolean nullable = col.getInt(11) != DatabaseMetaData.columnNoNulls;

          makeNode("Nullable: " + nullable, columnNode);
        }

        col.close();

        DefaultMutableTreeNode indexesNode = makeNode("Indices", tableNode);
        ResultSet ind = dMeta.getIndexInfo(null, null, name, false, false);
        String oldiname = null;

        // A child node to contain each index - and its attributes
        while (ind.next()) {
          DefaultMutableTreeNode indexNode = null;
          boolean nonunique = ind.getBoolean(4);
          String iname = ind.getString(6);

          if ((oldiname == null || !oldiname.equals(iname))) {
            indexNode = makeNode(iname, indexesNode);

            makeNode("Unique: " + !nonunique, indexNode);

            oldiname = iname;
          }

          // And the ordered column list for index components
          makeNode(ind.getString(9), indexNode);
        }

        ind.close();
      }

      // Finally - a little additional metadata on this connection
      propertiesNode = makeNode("Properties", rootNode);

      makeNode("User: "******"ReadOnly: " + cConn.isReadOnly(), propertiesNode);
      makeNode("AutoCommit: " + cConn.getAutoCommit(), propertiesNode);
      makeNode("Driver: " + dMeta.getDriverName(), propertiesNode);
      makeNode("Product: " + dMeta.getDatabaseProductName(), propertiesNode);
      makeNode("Version: " + dMeta.getDatabaseProductVersion(), propertiesNode);
    } catch (SQLException se) {
      propertiesNode = makeNode("Error getting metadata:", rootNode);

      makeNode(se.getMessage(), propertiesNode);
      makeNode(se.getSQLState(), propertiesNode);
    }

    treeModel.nodeStructureChanged(rootNode);
    treeModel.reload();
    tScrollPane.repaint();
  }