Search in sources :

Example 1 with TreeTableModel

use of pcgen.gui2.util.treetable.TreeTableModel in project pcgen by PCGen.

the class CompanionInfoTab method selectCompanion.

private void selectCompanion(CompanionFacade compFacade) {
    TreeTableModel treeTableModel = companionsTable.getTreeTableModel();
    treeTableModel.getRoot();
    TreePath path = null;
    JTree tree = companionsTable.getTree();
    String companionType = compFacade.getCompanionType();
    for (int i = 0; i < tree.getRowCount(); i++) {
        TreePath pathForRow = tree.getPathForRow(i);
        Object lastPathComponent = pathForRow.getLastPathComponent();
        if (lastPathComponent.toString().startsWith(companionType)) {
            tree.expandRow(i);
        } else if (lastPathComponent instanceof pcgen.gui2.tabs.CompanionInfoTab.CompanionsModel.CompanionNode) {
            CompanionFacade rowComp = (CompanionFacade) ((pcgen.gui2.tabs.CompanionInfoTab.CompanionsModel.CompanionNode) lastPathComponent).getValueAt(0);
            if (rowComp != null && rowComp.getFileRef().get() == compFacade.getFileRef().get() && rowComp.getNameRef().get() == compFacade.getNameRef().get() && rowComp.getRaceRef().get() == compFacade.getRaceRef().get()) {
                path = pathForRow;
            }
        }
    }
    if (path != null) {
        companionsTable.getTree().setSelectionPath(path);
        companionsTable.getTree().scrollPathToVisible(path);
    }
}
Also used : AbstractTreeTableModel(pcgen.gui2.util.treetable.AbstractTreeTableModel) TreeTableModel(pcgen.gui2.util.treetable.TreeTableModel) CompanionFacade(pcgen.facade.core.CompanionFacade) JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath)

Aggregations

JTree (javax.swing.JTree)1 TreePath (javax.swing.tree.TreePath)1 CompanionFacade (pcgen.facade.core.CompanionFacade)1 AbstractTreeTableModel (pcgen.gui2.util.treetable.AbstractTreeTableModel)1 TreeTableModel (pcgen.gui2.util.treetable.TreeTableModel)1