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); } }
void showCompanion(boolean switchTabs) { CompanionFacade companion = getSelectedCompanion(); if (companion == null) { if (!switchTabs) { infoPane.setText(""); // $NON-NLS-1$ } return; } if (isCompanionOpen(companion)) { CharacterFacade character = CharacterManager.getCharacterMatching(companion); if (character != null) { if (switchTabs) { frame.setSelectedCharacter(character); return; } else { sheetSupport.setCharacter(character); sheetSupport.refresh(); } } // the companion was not found // TODO: show error, complain? } else if (switchTabs) { frame.loadCharacterFromFile(companion.getFileRef().getReference()); } else { // Display a message telling the user to open the companion. infoPane.setText( LanguageBundle.getString("in_companionLoadCompanionMessage")); // $NON-NLS-1$ } }
private boolean isCompanionOpen(CompanionFacade companion) { File compFile = companion.getFileRef().getReference(); if (compFile == null) { return true; } for (CharacterFacade character : CharacterManager.getCharacters()) { File charFile = character.getFileRef().getReference(); if (compFile.equals(charFile)) { return true; } } return false; }