Search in sources :

Example 66 with DefaultMutableTreeNode

use of javax.swing.tree.DefaultMutableTreeNode in project intellij-community by JetBrains.

the class CopyValueAction method actionPerformed.

public void actionPerformed(AnActionEvent e) {
    final DefaultMutableTreeNode node = e.getData(SELECTED_NODE);
    if (node instanceof GeneratedStructureModel.StructureNode) {
        final GeneratedStructureModel.StructureNode structureNode = (GeneratedStructureModel.StructureNode) node;
        final OutputEventQueue.NodeEvent event = structureNode.getUserObject();
        setClipboardData(event.getValue());
    }
}
Also used : GeneratedStructureModel(org.intellij.plugins.xsltDebugger.ui.GeneratedStructureModel) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) OutputEventQueue(org.intellij.plugins.xsltDebugger.rt.engine.OutputEventQueue)

Example 67 with DefaultMutableTreeNode

use of javax.swing.tree.DefaultMutableTreeNode in project voltdb by VoltDB.

the class DatabaseManagerSwing method directRefreshTree.

/**
     * Clear all existing nodes from the tree model and rebuild from scratch.
     *
     * This method executes in current thread
     */
protected void directRefreshTree() {
    int[] rowCounts;
    DefaultMutableTreeNode propertiesNode;
    // Added: (weconsultants@users) Moved tableNode here for visibiity nd new DECFM
    DefaultMutableTreeNode tableNode;
    DecimalFormat DECFMT = new DecimalFormat(" ( ####,###,####,##0 )");
    // 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();
    ResultSet result = null;
    // 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
        result = dMeta.getTables(null, null, null, (showSys ? usertables : nonSystables));
        Vector tables = new Vector();
        Vector schemas = new Vector();
        // sqlbob@users Added remarks.
        Vector remarks = new Vector();
        String schema;
        while (result.next()) {
            schema = result.getString(2);
            if ((!showSys) && isOracle && oracleSysUsers.contains(schema)) {
                continue;
            }
            if (schemaFilter == null || schema.equals(schemaFilter)) {
                schemas.addElement(schema);
                tables.addElement(result.getString(3));
                remarks.addElement(result.getString(5));
                continue;
            }
        }
        result.close();
        result = null;
        // Added: (weconsultants@users)
        // Sort not to go into production. Have to sync with 'remarks Vector' for DBMS that has it
        //   Collections.sort(tables);
        // Added: (weconsultants@users) - Add rowCounts if needed.
        rowCounts = new int[tables.size()];
        try {
            rowCounts = getRowCounts(tables, schemas);
        } catch (Exception e) {
            //  Added: (weconsultants@users)
            CommonSwing.errorMessage(e);
        }
        ResultSet col;
        // For each table, build a tree node with interesting info
        for (int i = 0; i < tables.size(); i++) {
            col = null;
            String name;
            try {
                name = (String) tables.elementAt(i);
                if (isOracle && name.startsWith("BIN$")) {
                    continue;
                // Oracle Recyle Bin tables.
                // Contains metacharacters which screw up metadata
                // queries below.
                }
                schema = (String) schemas.elementAt(i);
                String schemaname = "";
                if (schema != null && showSchemas) {
                    schemaname = schema + '.';
                }
                String rowcount = displayRowCounts ? (" " + DECFMT.format(rowCounts[i])) : "";
                String displayedName = schemaname + name + rowcount;
                // weconsul@ptd.net Add rowCounts if needed.
                tableNode = makeNode(displayedName, rootNode);
                col = dMeta.getColumns(null, schema, name, null);
                if ((schema != null) && !schema.trim().equals("")) {
                    makeNode(schema, tableNode);
                }
                // 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);
                }
            } finally {
                if (col != null) {
                    try {
                        col.close();
                    } catch (SQLException se) {
                    }
                }
            }
            DefaultMutableTreeNode indexesNode = makeNode("Indices", tableNode);
            if (showIndexDetails) {
                ResultSet ind = null;
                try {
                    ind = dMeta.getIndexInfo(null, schema, name, false, false);
                    String oldiname = null;
                    DefaultMutableTreeNode indexNode = null;
                    // A child node to contain each index - and its attributes
                    while (ind.next()) {
                        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);
                    }
                } catch (SQLException se) {
                    // Workaround for Oracle
                    if (se.getMessage() == null || ((!se.getMessage().startsWith("ORA-25191:")) && (!se.getMessage().startsWith("ORA-01702:")) && !se.getMessage().startsWith("ORA-01031:"))) {
                        throw se;
                    }
                } finally {
                    if (ind != null) {
                        ind.close();
                        ind = null;
                    }
                }
            }
        }
        // Finally - a little additional metadata on this connection
        propertiesNode = makeNode("Properties", rootNode);
        makeNode("User: " + dMeta.getUserName(), propertiesNode);
        makeNode("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);
        CommonSwing.errorMessage(se);
    } finally {
        if (result != null) {
            try {
                result.close();
            } catch (SQLException se) {
            }
        }
    }
    treeModel.nodeStructureChanged(rootNode);
    treeModel.reload();
    tScrollPane.repaint();
    // We want the Schema List to always be in sync with the displayed tree
    updateSchemaList();
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) SQLException(java.sql.SQLException) DecimalFormat(java.text.DecimalFormat) ResultSet(java.sql.ResultSet) Vector(java.util.Vector) InvocationTargetException(java.lang.reflect.InvocationTargetException) AccessControlException(java.security.AccessControlException) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Example 68 with DefaultMutableTreeNode

use of javax.swing.tree.DefaultMutableTreeNode in project ACS by ACS-Community.

the class LogLvlTreeModel method containerLoggedOut.

/**
	 * @see LogLevelListener
	 */
public void containerLoggedOut(int conthandle) {
    DefaultMutableTreeNode contNode = findNode(containersNode, null, conthandle);
    if (contNode != null) {
        System.out.println("Found a container node with handle " + conthandle);
        Object[] children = new Object[] { contNode };
        int idx = containersNode.getIndex(contNode);
        int[] indexes = new int[] { idx };
        containersNode.remove(contNode);
        fireTreeNodesRemoved(containersNode, containersNode.getPath(), indexes, children);
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode)

Example 69 with DefaultMutableTreeNode

use of javax.swing.tree.DefaultMutableTreeNode in project ACS by ACS-Community.

the class LogLvlTreeModel method removeFromComponentSubtree.

/**
	 * Remove a node from the subtree of components
	 * 
	 * @param compHandle The handle of the component to remove
	 */
private void removeFromComponentSubtree(int compHandle) {
    DefaultMutableTreeNode child = findNode(componentsNode, null, compHandle);
    if (child == null) {
        // The component is not in the list
        return;
    }
    int pos = componentsNode.getIndex(child);
    componentsNode.remove(pos);
    int[] indexes = new int[] { pos };
    Object[] children = new Object[] { child };
    fireTreeNodesRemoved(componentsNode, componentsNode.getPath(), indexes, children);
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode)

Example 70 with DefaultMutableTreeNode

use of javax.swing.tree.DefaultMutableTreeNode in project ACS by ACS-Community.

the class LogLvlTreeModel method refreshTree.

/**
	 * Build the tree.
	 * It read the clients, components and containers and add them
	 * to the tree.
	 *
	 */
public void refreshTree() {
    if (admin == null) {
        setRoot(null);
        if (rootNode != null) {
            rootNode.removeAllChildren();
        }
        rootNode = null;
    }
    rootNode = new DefaultMutableTreeNode("root");
    managersNode.removeAllChildren();
    clientsNode.removeAllChildren();
    componentsNode.removeAllChildren();
    containersNode.removeAllChildren();
    servicesNode.removeAllChildren();
    rootNode.add(managersNode);
    // rootNode.add(clientsNode);  // yatagai:hide for now. 
    rootNode.add(containersNode);
    // rootNode.add(componentsNode);  // yatagai: not used any more
    rootNode.add(servicesNode);
    Object[] children = new Object[] { managersNode, clientsNode, containersNode, componentsNode, servicesNode };
    int[] indexes = new int[] { rootNode.getIndex(managersNode), rootNode.getIndex(clientsNode), rootNode.getIndex(containersNode), rootNode.getIndex(componentsNode), rootNode.getIndex(servicesNode) };
    fireTreeNodesInserted(rootNode, rootNode.getPath(), indexes, children);
    setRoot(rootNode);
    buildManagersNode();
    buildClientsNode();
    buildContainersNode();
    buildComponentsNode();
    buildServicesNode();
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode)

Aggregations

DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)692 TreePath (javax.swing.tree.TreePath)185 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)98 ArrayList (java.util.ArrayList)51 Nullable (org.jetbrains.annotations.Nullable)50 TreeNode (javax.swing.tree.TreeNode)42 Test (org.junit.Test)39 JTree (javax.swing.JTree)38 NotNull (org.jetbrains.annotations.NotNull)32 VirtualFile (com.intellij.openapi.vfs.VirtualFile)28 JScrollPane (javax.swing.JScrollPane)25 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)23 TreeSelectionListener (javax.swing.event.TreeSelectionListener)23 Module (com.intellij.openapi.module.Module)20 File (java.io.File)20 Tree (com.intellij.ui.treeStructure.Tree)19 Enumeration (java.util.Enumeration)19 MouseEvent (java.awt.event.MouseEvent)18 IOException (java.io.IOException)17 MProduct (org.compiere.model.MProduct)17