On 1/4/07, Mats Norén <[EMAIL PROTECTED]> wrote:
> Hi,
> I'm trying to find an example using the tree table with a dynamic
> model that get's reloaded every request. The current example in
> wicket-examples uses an ordinary TreeModel which is static.
>
> Is it as simple as attaching a LDM which returns a TreeModel in load()?

Then you would have to reset/ re-render the tree from scratch every
time. Your best bet is probably to look at Swing examples that do
this; the idea should be the same.

One way to load lazily - though keep in mind it doesn't clean up when
nodes are unfolded again - is to override DefaultMutableTreeNode's
getChildCount method, so that it lazily initializes itself, adding any
child nodes on the first call. Code that I'm using in project looks
like this:

        private static final class FileTemplateTreeNode extends 
TemplateTreeNode {

                boolean checkedChilds = false;

                private final File baseDir;

                private final String displayName;

                private final File file;

                private final String location;

                public FileTemplateTreeNode(File baseDir, String location) {
                        this(baseDir, location, location);
                }

                public FileTemplateTreeNode(File baseDir, String location, 
String
displayName) {
                        super(location);
                        this.baseDir = baseDir;
                        if (location == null) {
                                throw new IllegalArgumentException("location 
must be not null");
                        }
                        this.location = location;
                        this.displayName = displayName;
                        this.file = new File(baseDir, location);
                }

                @Override
                public int getChildCount() {
                        if (!checkedChilds) {
                                checkedChilds = true;
                                if (file.isDirectory()) {
                                        for (String f : 
file.list(TEMPLATE_FILTER)) {
                                                add(new 
FileTemplateTreeNode(baseDir, f));
                                        }
                                }
                        }
                        return super.getChildCount();
                }

                ...

TemplateTreeNode is a simple extension of DefaultMutableTreeNode.


Eelco

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to