JList - Displaying Linked Records/Tables
Hello List! I have a Panel that displays the Records/Tables added by the user.
Here is my simple addTable method:
privatevoid addTables(String schema)throws SQLException{
APTListModel listModel = (APTListModel)list.getModel();
Vector usedTables =null;
int type = -1;
if(schema.equals("elementdata")){
type = APTListModel.DATA_TABLE;
usedTables = aptElement.getTableNames(schema, main.getConnection());
}
elseif(schema.equals("region")){
type = APTListModel.REGION_TABLE;
usedTables = aptElement.getTableNames(schema,
main.getConnection());
}
elseif(schema.equals("projectdata")){
Project project = main.getProject();
type = APTListModel.PROJECT_TABLE;
usedTables = project.getTableNames(main.getConnection());
}
//add tables and capitialize first letter
ListIterator li = usedTables.listIterator();
while(li.hasNext()){
String nextTable = (String)li.next();
nextTable = nextTable.substring(0,1).toUpperCase() + nextTable.substring(1);
listModel.addElement(nextTable, type);
}
}
And here is my APTListModel class:
publicclass APTListModelextends DefaultListModel{
publicstaticfinalint REGION_TABLE = 0;
publicstaticfinalint DATA_TABLE = 1;
publicstaticfinalint PDF_TABLE = 2;
publicstaticfinalint PROJECT_TABLE = 3;
public Hashtable type;
protected TreeNode root;
public APTListModel(){
super();
type =new Hashtable();
}
publicvoid addElement(Object obj,int type){
this.type.put(obj,new Integer(type));
super.addElement(obj);
}
publicint getElementType(Object obj){
Object o = type.get(obj);
return ((Integer)(o)).intValue();
}
}
Currently, only the attached record is being displayed - if there are any linked records to the attached record, they are not visible to the user.
What I'd like to do now is: If the Record/Table in the listModel has a linked Record/Table associated with it, to display that as well as under (as a chld node? - haven't used these before, but think this may be what I want to do) and any linked tables to that table under it...
Can anyone provide me with any changes that I may have to make to my code to accomplish this? Or what Objects/Methods I may need to add to get this accomplished?
I've experimented a bit with roots and nodes to no avail - I modified my addTables method to the following and nothing shows up on my Panel that displays the attached Records/Tables at all:
privatevoid addTables(String schema)throws SQLException{
APTListModel listModel = (APTListModel)list.getModel();
Vector usedTables =null;
int type = -1;
if(schema.equals("elementdata")){
type = APTListModel.DATA_TABLE;
usedTables = aptElement.getTableNames(schema, main.getConnection());
}
elseif(schema.equals("region")){
type = APTListModel.REGION_TABLE;
usedTables = aptElement.getTableNames(schema,
main.getConnection());
}
elseif(schema.equals("projectdata")){
Project project = main.getProject();
type = APTListModel.PROJECT_TABLE;
usedTables = project.getTableNames(main.getConnection());
}
//add tables and capitialize first letter
ListIterator li = usedTables.listIterator();
while(li.hasNext()){
String nextTable = (String)li.next();
nextTable = nextTable.substring(0,1).toUpperCase() + nextTable.substring(1);
}
APTTreeNode root = (APTTreeNode)listModel.getRoot();
APTTreeNode node =new APTTreeNode(nextTable,true);
listModel.addElement(nextTable, type);
int i = 0;
if (root.getChildCount() == 0){
listModel.insertNodeInto(node, root, 0);
return;
}
for (i = 0; i < root.getChildCount(); i++){
APTTreeNode nextNode = (APTTreeNode)root.getChildAt(i);
APTElement nxtTable = (APTElement)nextNode.getUserObject();
String nextTableName = nextTable.toString().toLowerCase();
if (nextTableName.compareTo(nextTable) > 0){
break;
}
}
listModel.insertNodeInto(node, root, i);
}
}
Any changes/direction that anyone can provide would be greatly appreciated!! Thanks in advance for your time and assistance!
-Jeanna

