01: /*
02: * Copyright 2008 Gerd Ziegler (www.gerdziegler.de)
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: * http://www.apache.org/licenses/LICENSE-2.0
07: * Unless required by applicable law or agreed to in writing,
08: * software distributed under the License is distributed on an
09: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
10: * either express or implied. See the License for the specific
11: * language governing permissions and limitations under the License.
12: * 13.02.2008
13: * @author www.gerdziegler.de
14: */
15: package org.ztemplates.yui.treeview;
16:
17: import java.util.List;
18: import java.util.Random;
19:
20: import org.ztemplates.web.ZTemplates;
21:
22: public class YTreeViewFactory {
23: public static YTreeView createRandomTreeView() {
24: Random rnd = new Random();
25: YTreeView treeView = new YTreeView(ZTemplates
26: .getRenderService().createJavaScriptId());
27: addRandomNodes(treeView.getNodes(), 3, rnd);
28: return treeView;
29: }
30:
31: private static void addRandomNodes(List<YTreeNode> nodes,
32: int depth, Random rnd) {
33: if (depth == 0)
34: return;
35: for (int i = 0; i < 4; i++) {
36: YTreeNode crt = new YTreeNode("node");
37: nodes.add(crt);
38: if (rnd.nextInt() % 4 != 0) {
39: addRandomNodes(crt.getNodes(), depth - 1, rnd);
40: }
41: }
42: }
43:
44: }
|