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

[7586 byte] By [JGeiera] at [2007-11-26 18:34:56]
# 1
Not sure I understand the question but I'm thinking a [url http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html]JTree[/url] is what you are looking for.
camickra at 2007-7-9 6:09:00 > top of Java-index,Desktop,Core GUI APIs...
# 2

Thank you for replying to my post. Sorry if I didn't explain it clearly -

Currently, using the APTListModel on a Panel, tables are being added/attached by the user. (this is working fine)

However, you if one of these tables has a table linked to it, it is currently not being shown in the panel & I would like to display it under the top-level/attached 'parent' table.

So, if the user attaches any tables that have linked tables - I would like to display the linked tables below them (as 'nodes'/'children' I think are the proper terms), but I cannot figure out how to do this....

Does that help at all? I'm pretty new to all of this GUI lingo, so I apologize if I am not using the terms correctly. I've been working on this for about a week with a couple of GUI books and searching the Internet and I was hoping that I'd get some assistance on here because its got me stumped and I don't think it should be as hard as I'm making it...

Thanks again,

-Jeanna

JGeiera at 2007-7-9 6:09:00 > top of Java-index,Desktop,Core GUI APIs...