01: /*
02: * Beryl - A web platform based on XML, XSLT and Java
03: * This file is part of the Beryl XML GUI
04: *
05: * Copyright (C) 2004 Wenzel Jakob <wazlaf@tigris.org>
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation; either
10: * version 2.1 of the License, or (at your option) any later version.
11:
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this program; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-3107 USA
20: */
21:
22: package org.beryl.gui.widgets;
23:
24: import org.beryl.gui.GUIException;
25: import org.beryl.gui.MessageDialog;
26: import org.beryl.gui.Widget;
27:
28: /**
29: * This class supports lazy creation of a tree as
30: * nodes are expanded. When you definitely know
31: * that a node is leaf, execute <code>setCheckLeaf(false)</code>
32: */
33:
34: public abstract class DynamicTreeItem extends TreeItem {
35: private boolean isLoaded = false;
36:
37: public DynamicTreeItem(Widget parent, String name)
38: throws GUIException {
39: super (parent, name);
40: }
41:
42: /**
43: * Implement this function to load the child nodes. It
44: * will only be called on the first expansion
45: */
46: protected abstract void loadChildren() throws GUIException;
47:
48: public int getChildCount() {
49: if (!isLoaded && checkLeaf) {
50: try {
51: loadChildren();
52: } catch (Exception ex) {
53: GUIException ex2 = new GUIException(
54: "Error while loading dynamic tree node contents",
55: ex);
56: new MessageDialog(ex2);
57: }
58: isLoaded = true;
59: }
60: return super .getChildCount();
61: }
62:
63: /**
64: * Invalidate this dynamic tree node, remove
65: * all child nodes and refresh the tree
66: */
67: public void invalidate() throws GUIException {
68: isLoaded = false;
69: removeAllChildWidgets();
70: revalidate();
71: }
72: }
|