View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  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,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.model;
21  
22  import java.util.EnumSet;
23  import java.util.HashMap;
24  import java.util.Map;
25  import java.util.Set;
26  
27  /**
28   * @deprecated since 2.0.0, please use {@link Selectable}
29   */
30  @Deprecated
31  public enum TreeSelectable {
32  
33    OFF("off"),
34    MULTI("multi"),
35    SINGLE("single"),
36    MULTI_LEAF_ONLY("multiLeafOnly"),
37    SINGLE_LEAF_ONLY("singleLeafOnly"),
38    SIBLING("sibling"),
39    SIBLING_LEAF_ONLY("siblingLeafOnly"),
40    MULTI_SUB_TREE("multiSubTree"),
41    SINGLE_SUB_TREE("singleSubTree");
42  
43    private String value;
44  
45    TreeSelectable(final String value) {
46      this.value = value;
47    }
48  
49    public String getValue() {
50     return value;
51    }
52  
53    private static final Map<String, TreeSelectable> MAPPING;
54  
55    static {
56      MAPPING = new HashMap<String, TreeSelectable>();
57  
58      for (final TreeSelectable action : TreeSelectable.values()) {
59        MAPPING.put(action.getValue(), action);
60      }
61    }
62  
63    /**
64     * @param name Name of the TreeSelectable
65     * @return The matching tree selection (can't be null).
66     * @throws IllegalArgumentException When the name doesn't match any TreeSelectable.
67     */
68    public static TreeSelectable parse(final String name) throws IllegalArgumentException {
69      final TreeSelectable value = MAPPING.get(name);
70      if (value != null) {
71        return value;
72      } else {
73        throw new IllegalArgumentException("Unknown name for TreeSelectable: '" + name + "'");
74      }
75    }
76  
77    public boolean isSupportedByTree() {
78      return TREE_VALUES.contains(this);
79    }
80  
81    private static final Set<TreeSelectable> TREE_VALUES = EnumSet.noneOf(TreeSelectable.class);
82  
83    static {
84      TREE_VALUES.add(MULTI);
85      TREE_VALUES.add(SINGLE);
86      TREE_VALUES.add(MULTI_LEAF_ONLY);
87      TREE_VALUES.add(SINGLE_LEAF_ONLY);
88    }
89  
90    public boolean isSupportedByTreeListbox() {
91      return TREE_LISTBOX_VALUES.contains(this);
92    }
93  
94    private static final Set<TreeSelectable> TREE_LISTBOX_VALUES = EnumSet.noneOf(TreeSelectable.class);
95  
96    static {
97      TREE_LISTBOX_VALUES.add(SINGLE);
98      TREE_LISTBOX_VALUES.add(MULTI_LEAF_ONLY);
99      TREE_LISTBOX_VALUES.add(SINGLE_LEAF_ONLY);
100   }
101 }