Search in sources :

Example 1 with AbstractNodeModel

use of com.jsql.view.swing.tree.model.AbstractNodeModel 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)

Example 2 with AbstractNodeModel

use of com.jsql.view.swing.tree.model.AbstractNodeModel 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)

Example 3 with AbstractNodeModel

use of com.jsql.view.swing.tree.model.AbstractNodeModel 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)

Example 4 with AbstractNodeModel

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

the class CellEditorNode method showPopup.

/**
 * Fix compatibility issue with right click on Linux.
 * @param e Mouse event
 */
private void showPopup(MouseEvent e) {
    if (e.isPopupTrigger()) {
        JTree tree = (JTree) e.getSource();
        TreePath path = tree.getPathForLocation(e.getX(), e.getY());
        if (path == null) {
            return;
        }
        DefaultMutableTreeNode currentTableNode = (DefaultMutableTreeNode) path.getLastPathComponent();
        if (currentTableNode.getUserObject() instanceof AbstractNodeModel) {
            AbstractNodeModel currentTableModel = (AbstractNodeModel) currentTableNode.getUserObject();
            if (currentTableModel.isPopupDisplayable()) {
                currentTableModel.showPopup(currentTableNode, path, e);
            }
        }
    }
}
Also used : JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) AbstractNodeModel(com.jsql.view.swing.tree.model.AbstractNodeModel)

Example 5 with AbstractNodeModel

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

the class StartProgress 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();
    DefaultMutableTreeNode node = MediatorGui.frame().getTreeNodeModels().get(this.dataElementDatabase);
    // Get the node
    AbstractNodeModel progressingTreeNodeModel = (AbstractNodeModel) node.getUserObject();
    // Mark the node model as 'display progress bar'
    progressingTreeNodeModel.setLoading(true);
    // Update the node
    treeModel.nodeChanged(node);
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) AbstractNodeModel(com.jsql.view.swing.tree.model.AbstractNodeModel) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Aggregations

AbstractNodeModel (com.jsql.view.swing.tree.model.AbstractNodeModel)13 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)13 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)10 TreePath (javax.swing.tree.TreePath)4 Column (com.jsql.model.bean.database.Column)2 Database (com.jsql.model.bean.database.Database)1 Table (com.jsql.model.bean.database.Table)1 TabHeader (com.jsql.view.swing.tab.TabHeader)1 PanelTable (com.jsql.view.swing.table.PanelTable)1 NodeModelColumn (com.jsql.view.swing.tree.model.NodeModelColumn)1 NodeModelDatabase (com.jsql.view.swing.tree.model.NodeModelDatabase)1 NodeModelTable (com.jsql.view.swing.tree.model.NodeModelTable)1 ArrayList (java.util.ArrayList)1 JCheckBox (javax.swing.JCheckBox)1 JTree (javax.swing.JTree)1