Search in sources :

Example 1 with NodeModelDatabase

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

the class AddDatabases 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();
    // First node in tree
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) treeModel.getRoot();
    // Loop into the list of databases
    for (Database database : this.databases) {
        // Create a node model with the database element
        AbstractNodeModel newTreeNodeModel = new NodeModelDatabase(database);
        // Create the node
        DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(newTreeNodeModel);
        // Save the node
        MediatorGui.frame().getTreeNodeModels().put(database, newNode);
        // Add the node to the tree
        root.add(newNode);
    }
    // Refresh the tree
    treeModel.reload(root);
    // Open the root node
    MediatorGui.treeDatabase().expandPath(new TreePath(root.getPath()));
    MediatorGui.treeDatabase().setRootVisible(false);
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath) Database(com.jsql.model.bean.database.Database) NodeModelDatabase(com.jsql.view.swing.tree.model.NodeModelDatabase) AbstractNodeModel(com.jsql.view.swing.tree.model.AbstractNodeModel) NodeModelDatabase(com.jsql.view.swing.tree.model.NodeModelDatabase) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Aggregations

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