View Javadoc

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