• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help on design of Swing application

 
Grub de Bliek
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I'm having a problem here with the design of my Swing app. It is a typical application with a JTree for navigation on the left, and a screen on the right.
Each node in the tree implements an interface with the method JPanel getScreen(), so I'm able to set the screen on the right with the correct screen when selected. This way I can add any node with an own screen to the navigation tree.

Because I want to keep View and Model separated, each Node in the tree contains a DataObject. Lets say my application displays files and directories, then I have a DirectoryNode containing a DirectoryDAO, and a FileNode containing a FileDAO. When a node is clicked, details of the object belonging to it are shown in the screen on right.
All looks good to me so far. I have a lot of different types of DataObjects displayed in my application.

However my problem is that I've several objects that must be available for all of them. For example, because I want to be able to show modal dialogs, I need to have the top level JFrame available for each node. Also, because I must be able to add and remove nodes, I must be able to access the navigation tree from any node. Those are the View objects that must be available.

Also, my DataObjects are nested. Like with Directories and Files, each File or Directory must be able to access the properties of its parent directories. Those are the Model objects that must be available to the child DataObjects.



I've been trying to implement this using a "Context" object which I'm passing to the constructor of any child node added to the tree. Context just contains the JFrame, the Tree, and the parent DataObject. Any new DataObject in the tree just adds itself to the Context and passes the context to its children.

However this is a far from perfect solution.
1. First of all, Model and View are mixed in my Context object, which I don't want.
2. Secondly, not all properties of Context can be final because after creation they must be set by the child data objects. This means they can be null, or set with wrong values.

I really don't know how to handle this, and my whole beautiful application gets messed up right now. Does anyone have some suggestions for me how to solve this?

Thank you very, very much.
[ June 21, 2005: Message edited by: Grub de Bliek ]
 
Tad Dicks
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. First of all, Model and View are mixed in my Context object, which I don't want.


Well you could separate out your context object, into two separate objects one that contains model information and one that contains view(gui) information.

You said each node needs its own top-level frame for modal windows, how important is it that each node's modal windows not block other node's windows?
If its not that important, you could do each node as a panel.

However my problem is that I've several objects that must be available for all of them. For example, because I want to be able to show modal dialogs, I need to have the top level JFrame available for each node. Also, because I must be able to add and remove nodes, I must be able to access the navigation tree from any node. Those are the View objects that must be available.


In my app I have done what I said... the base frame (actually an internal frame) has split pane one side with the JTree(lhs), the otherside with a JPanel with information for each node(Rhs). The rhs changes as different nodes are selected. Modal windows would just be child windows to this frame (honestly I'm not sure how it works with internal frames if it blocks all of them, or if it has to be a child to the main desktop window, in my case its not important).

If you implemented/extended a JTree a child node should have access to its parent easily enough through getParent().

2. Secondly, not all properties of Context can be final because after creation they must be set by the child data objects. This means they can be null, or set with wrong values.

I don't think it would be useful to make the properties of your context object "constants." I'm not sure what the problem is with values being set null, or with "wrong values." You're going to have to do checking/validation to make sure the data is right/not null (or just handle nulls as a legitimate value) thats just a part of coding (if I'm wrong here please someone tell me what I'm missing, it would make life much easier).

-Tad
 
Don Kiddick
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so you have two panels a left tree like one and a right one that displays details of the thing selected in the left. The right panel can also display details of the selected objects parents.

one way...

Your left panel, let�s call it TreePanel. You can add listeners to it. AddTreePanelListener. TreePanelListeners declare a method nodeSelected(DefaultMutableTreeNode node).
Your right panel has/is a TreePanelListener. It listens to your tree panel and when a new node is selected, it gets the user object from it and instantiates (or sets the relevant values on pre created object) the relevent sort of DetailsPanel. If the details panel needs information on the parent you can call treeNode.getParent(). If the details panel needs to display a modal dialog you can either pass a reference to the JFrame when you instantiate it or use SwingUtilities.getWindowAncestor(c).

hope that helps,
D.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!