Bette way to referenced tree model nodes from UI to perform actions on them

A singleton facade is built.

Its init() method loads several "tree model configs", each of them referenced by a name.

This singleton creates a Project instance for a given "tree model config" calling the facade method -> createProject(String pjrName, String modelConfigName)

When the Project is built a new Model instance is set ( remember the model instance is a tree holding nodes )

The new Project instance built is added to a List that the facade has and then it's returned to the UI part that called ->createProject(prjName,modelconfigName)

Given the Project instance the UI has to build a JTree representation of the model that the project references and the UI will have button actions that should call methods of the Nodes of the model referenced by the Project.

Doing it this way the UI will be able to reference objects directly without going through the facade.

Maybe I should return to the UI something like a ProjectKey instance instead of letting have the UI the Project instance ?

It should be better if I process the possible node actions behind the Facade and not the UI, but how can I do it ?

Having a ProjectKey in my UI I could ask the facade a model tree representation but not having the real nodes, otherwise having some NodeKey instances ?

[1332 byte] By [jfreebsda] at [2007-11-26 13:04:05]
# 1

You should store your data in a domain specific model, which can be done by creating a user-defined type. Eg, "ProjectModel.java". That domain-specific model should be the backing data structure for the tree model.

The facade may create the domain model, and that model will listen to changes to the tree model, and vice versa, using property change listeners. Then the UI implements a bunch of actions like add node, remove node, move node, etc. Each time an action is performed on the tree , the tree model hears about it , and further down the listener chain the domain model hears about it. At this point, you can process the actions behind the facade.

jvaudrya at 2007-7-7 17:09:24 > top of Java-index,Other Topics,Patterns & OO Design...
# 2

Sounds like you want to represent a tree structure, without a reference to the real tree.

I'll take it further: maybe you don't want the UI to know there's a real tree data-structure with nodes and pointers to children, because maybe you build the tree on the fly from a database.

So use the Builder pattern instead of committing to a specific data structure.

Google results for Builder pattern: http://www.google.com/search?hl=en&q=builder+pattern&btnG=Google+Search

Your UI should know how to construct nodes and children graphically, when told. This means it should have methods like addNode, but related to the domain: addSubProject maybe.

A Project object is the Director, knowing which part goes where, but it doesn't know the real end result (a JPanel or HTML). So it has a method buildProject(Builder e) or exportProject(Exporter e), where all logic of assembling the parts is.

When you have that, write a class JTreeProjectExporter implements Exporter.

Hope this helps.

gewittera at 2007-7-7 17:09:24 > top of Java-index,Other Topics,Patterns & OO Design...
# 3

Suppose I have a Swing client and this client calls the method facade "createTreeModel(prjName)", this method creates a new Project instance and returns the instance to the Swing client.

The project has a tree representation.

Now the client must show up this tree on a JTree.

When building the JTree, builds each node setting the real node that gets from the Project instance.

The graphical tree has been made and a user may click on some node and perform an actions as for example :

((ProjectDomainNode) (defaultMutableTreeNode.getUserObject())).evaluate();

And that's the way a node is evaluated.

If a web interface is created the way of evaluating a ProjectDomainNode should be different.

Maybe the facade must public a method evaluate(string nodeName)

where this method should be responsable of getting the node from the project and calling evaluate() ?

Maybe I could use a node Node"Key" object to access the ProjectDomainNode that is behind the facade ?

jfreebsda at 2007-7-7 17:09:24 > top of Java-index,Other Topics,Patterns & OO Design...