Forum@carlsbadcubes.com wrote:
Hello All,
Has anyone been successful creating a tree with it's nodes from an XML
descriptor file? I've been playing around with this today and can not
get around the fact that DefaultMutableTreeNode, TreeNode, etc. do not
extend from either Component or Container.
This is generally not supported, because it is the model you would like
to describe with the xml. I might say SwixMl is about 5% M, 90% V and 5%
C of the MVC acronym. The 5% of the M goes IMHO only to the initclass
but does not help *that* much for your intended goal. The only thing is
to write a complete model for this, which you have to specify in the
initclass attribute.
The addChild method of the
Parser object requires that the object you are adding be a Component or
inherited from Component. I would like to have an xml document that is
something like the following:
<tree>
<node>text1</node>
<node>text2</node>
</tree>
I have messed a little with trying to use the initclass attribute of the
tree tag but no luck so far. Any suggestion would be appreciated.
Try this:
1. Write a tree model which creates the appropriate tree in a standalone
application.
2. Specify this model-class in the initclass attribute of your tree in
the SwixMl file
> Does
anyone know if this functionality is scheduled for the next release? If
not I am going to try and adjust the addChild method myself in the
following manor:
1. Ensure the appropriate packages are imported for DefaultMutableTreeNode
2. Change the component parameter of the addChild method to an Object type
3. Create an if else block that is true for (component instanceof
DefaultMutableTreeNode)
4. Populate this block with the appropriate code to generate a node
structure for the parent (Container) tree.
5. Make addChild throw an exception on no match of any if or if else block.
6. Adjust the calling method, getSwing, to handle the exception.
You may do as you wish but I wouldn't recommend you doing so. This is
really a hack, it may look like a tree but not act like a real one. The
correct approach is to modify the model of the underlying tree otherwise
the changes on your tree are lost at random, you don't get informed
about tree changes and the like.
There may be more steps required once I dive deeper. Of course, if
someelse has a better solution or is working on this please let me know.
If you really need it for rapid prototyping, you may be better with the
following approach: Write a class which converts a given file name to a
valid TreeModel. Turn this class into a SwixMl Converter class and give
the filename to your intended tree in the model attribute of your tree.
As you mentioned, this may rise additional difficulties along
implementation, but it seems a reasonable way to do it.
Yours,
Frank
Thanks,
Andrew
------------------------------------------------------------------------
_______________________________________________
Forum mailing list
Forum@carlsbadcubes.com
http://carlsbadcubes.com/mailman/listinfo/forum_carlsbadcubes.com