Search in sources :

Example 1 with NodeModelTable

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

the class AddTables 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 database to update
    DefaultMutableTreeNode databaseNode = null;
    // Loop into the list of tables
    for (Table table : this.tables) {
        // Create a node model with the table element
        AbstractNodeModel newTreeNodeModel = new NodeModelTable(table);
        // Create the node
        DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(newTreeNodeModel);
        // Save the node
        MediatorGui.frame().getTreeNodeModels().put(table, newNode);
        // Get the parent database
        databaseNode = MediatorGui.frame().getTreeNodeModels().get(table.getParent());
        // Report NullPointerException #1670
        if (databaseNode != null) {
            // Add the table to the database
            treeModel.insertNodeInto(newNode, databaseNode, databaseNode.getChildCount());
        } else {
            LOGGER.warn("Missing database for table " + table.toString() + ".");
        }
    }
    if (databaseNode != null) {
        // Open the database node
        MediatorGui.treeDatabase().expandPath(new TreePath(databaseNode.getPath()));
        // The database has just been search (avoid double check)
        ((AbstractNodeModel) databaseNode.getUserObject()).setLoaded(true);
    }
}
Also used : NodeModelTable(com.jsql.view.swing.tree.model.NodeModelTable) Table(com.jsql.model.bean.database.Table) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath) AbstractNodeModel(com.jsql.view.swing.tree.model.AbstractNodeModel) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) NodeModelTable(com.jsql.view.swing.tree.model.NodeModelTable)

Aggregations

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