01: /*
02: * $Id: Category.java 476710 2006-11-19 05:05:14Z mrdon $
03: *
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
20: */
21: package org.apache.struts2.showcase.ajax.tree;
22:
23: import java.util.ArrayList;
24: import java.util.HashMap;
25: import java.util.List;
26: import java.util.Map;
27:
28: /**
29: */
30: public class Category {
31: private static Map<Long, Category> catMap = new HashMap<Long, Category>();
32:
33: static {
34: new Category(1, "Root", new Category(2, "Java", new Category(3,
35: "Web Frameworks", new Category(4, "Struts"),
36: new Category(7, "Stripes"), new Category(8, "Rife")),
37: new Category(9, "Persistence", new Category(10,
38: "iBatis"), new Category(11, "Hibernate"),
39: new Category(12, "JDO"), new Category(13,
40: "JDBC"))), new Category(14,
41: "JavaScript", new Category(15, "Dojo"), new Category(
42: 16, "Prototype"), new Category(17,
43: "Scriptaculous"), new Category(18, "OpenRico"),
44: new Category(19, "DWR")));
45: }
46:
47: public static Category getById(long id) {
48: return catMap.get(id);
49: }
50:
51: private long id;
52: private String name;
53: private List<Category> children;
54: private boolean toggle;
55:
56: public Category(long id, String name, Category... children) {
57: this .id = id;
58: this .name = name;
59: this .children = new ArrayList<Category>();
60: for (Category child : children) {
61: this .children.add(child);
62: }
63:
64: catMap.put(id, this );
65: }
66:
67: public long getId() {
68: return id;
69: }
70:
71: public void setId(long id) {
72: this .id = id;
73: }
74:
75: public String getName() {
76: return name;
77: }
78:
79: public void setName(String name) {
80: this .name = name;
81: }
82:
83: public List<Category> getChildren() {
84: return children;
85: }
86:
87: public void setChildren(List<Category> children) {
88: this .children = children;
89: }
90:
91: public void toggle() {
92: toggle = !toggle;
93: }
94:
95: public boolean isToggle() {
96: return toggle;
97: }
98: }
|