View Javadoc

1   /*
2    * $Id: Category.java 471756 2006-11-06 15:01:43Z husted $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "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.views.jsp.ui;
22  
23  import java.util.ArrayList;
24  import java.util.HashMap;
25  import java.util.List;
26  import java.util.Map;
27  
28  /***
29   * Used by Tree Component Test. Copied from showcase.
30   */
31  public class Category {
32      private static Map<Long, Category> catMap = new HashMap<Long, Category>();
33  
34      static {
35          new Category(1, "Root",
36                  new Category(2, "Java",
37                          new Category(3, "Web Frameworks",
38                                  new Category(4, "Struts"),
39                                  new Category(7, "Stripes"),
40                                  new Category(8, "Rife")),
41                          new Category(9, "Persistence",
42                                  new Category(10, "iBatis"),
43                                  new Category(11, "Hibernate"),
44                                  new Category(12, "JDO"),
45                                  new Category(13, "JDBC"))),
46                  new Category(14, "JavaScript",
47                          new Category(15, "Dojo"),
48                          new Category(16, "Prototype"),
49                          new Category(17, "Scriptaculous"),
50                          new Category(18, "OpenRico"),
51                          new Category(19, "DWR")));
52      }
53  
54      public static Category getById(long id) {
55          return catMap.get(id);
56      }
57  
58      private long id;
59      private String name;
60      private List<Category> children;
61      private boolean toggle;
62  
63      public Category(long id, String name, Category... children) {
64          this.id = id;
65          this.name = name;
66          this.children = new ArrayList<Category>();
67          for (Category child : children) {
68              this.children.add(child);
69          }
70  
71          catMap.put(id, this);
72      }
73  
74      public long getId() {
75          return id;
76      }
77  
78      public void setId(long id) {
79          this.id = id;
80      }
81  
82      public String getName() {
83          return name;
84      }
85  
86      public void setName(String name) {
87          this.name = name;
88      }
89  
90      public List<Category> getChildren() {
91          return children;
92      }
93  
94      public void setChildren(List<Category> children) {
95          this.children = children;
96      }
97  
98      public void toggle() {
99          toggle = !toggle;
100     }
101 
102     public boolean isToggle() {
103         return toggle;
104     }
105 }