Ejemplo n.º 1
0
  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().getReference() == compFacade.getFileRef().getReference()
            && rowComp.getNameRef().getReference() == compFacade.getNameRef().getReference()
            && rowComp.getRaceRef().getReference() == compFacade.getRaceRef().getReference()) {
          path = pathForRow;
        }
      }
    }
    if (path != null) {
      companionsTable.getTree().setSelectionPath(path);
      companionsTable.getTree().scrollPathToVisible(path);
    }
  }
Ejemplo n.º 2
0
 private void saveExpansionState() {
   Object root = companionsTable.getTreeTableModel().getRoot();
   Enumeration<TreePath> paths = tree.getExpandedDescendants(new TreePath(root));
   expandedPaths = Collections.list(paths);
 }
Ejemplo n.º 3
0
 public void uninstall() {
   tree.removeTreeExpansionListener(this);
 }
Ejemplo n.º 4
0
 public void install() {
   for (TreePath path : expandedPaths) {
     tree.expandPath(path);
   }
   tree.addTreeExpansionListener(this);
 }