Search in sources :

Example 1 with NodeModelColumn

use of com.jsql.view.swing.tree.model.NodeModelColumn in project jsql-injection by ron190.

the class AddColumns method execute.

@Override
public void execute() {
    if (MediatorGui.treeDatabase() == null) {
        LOGGER.error("Unexpected unregistered MediatorGui.treeDatabase() in " + this.getClass());
    }
    // Tree model, update the tree (refresh, add node, etc)
    DefaultTreeModel treeModel = (DefaultTreeModel) MediatorGui.treeDatabase().getModel();
    // The table to update
    DefaultMutableTreeNode tableNode = null;
    // Loop into the list of columns
    for (Column column : this.columns) {
        // Create a node model with the column element
        AbstractNodeModel newTreeNodeModel = new NodeModelColumn(column);
        // Create the node
        DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(newTreeNodeModel);
        // Get the parent table
        tableNode = MediatorGui.frame().getTreeNodeModels().get(column.getParent());
        // Fix #1805 : NullPointerException on tableNode.getChildCount()
        if (tableNode != null) {
            // Add the column to the table
            treeModel.insertNodeInto(newNode, tableNode, tableNode.getChildCount());
        }
    }
    if (tableNode != null) {
        // Open the table node
        MediatorGui.treeDatabase().expandPath(new TreePath(tableNode.getPath()));
        // The table has just been search (avoid double check)
        ((AbstractNodeModel) tableNode.getUserObject()).setLoaded(true);
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath) Column(com.jsql.model.bean.database.Column) NodeModelColumn(com.jsql.view.swing.tree.model.NodeModelColumn) AbstractNodeModel(com.jsql.view.swing.tree.model.AbstractNodeModel) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) NodeModelColumn(com.jsql.view.swing.tree.model.NodeModelColumn)

Aggregations

Column (com.jsql.model.bean.database.Column)1 AbstractNodeModel (com.jsql.view.swing.tree.model.AbstractNodeModel)1 NodeModelColumn (com.jsql.view.swing.tree.model.NodeModelColumn)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)1 TreePath (javax.swing.tree.TreePath)1