001 package org.apache.myfaces.tobago.model; 002 003 /* 004 * Licensed to the Apache Software Foundation (ASF) under one or more 005 * contributor license agreements. See the NOTICE file distributed with 006 * this work for additional information regarding copyright ownership. 007 * The ASF licenses this file to You under the Apache License, Version 2.0 008 * (the "License"); you may not use this file except in compliance with 009 * the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 */ 019 020 import java.util.EnumSet; 021 import java.util.HashMap; 022 import java.util.Map; 023 import java.util.Set; 024 025 public enum TreeSelectable { 026 027 OFF("off"), 028 MULTI("multi"), 029 SINGLE("single"), 030 MULTI_LEAF_ONLY("multiLeafOnly"), 031 SINGLE_LEAF_ONLY("singleLeafOnly"), 032 SIBLING("sibling"), 033 SIBLING_LEAF_ONLY("siblingLeafOnly"), 034 MULTI_SUB_TREE("multiSubTree"), 035 SINGLE_SUB_TREE("singleSubTree"); 036 037 private String value; 038 039 TreeSelectable(String value) { 040 this.value = value; 041 } 042 043 public String getValue() { 044 return value; 045 } 046 047 private static final Map<String, TreeSelectable> MAPPING; 048 049 static { 050 MAPPING = new HashMap<String, TreeSelectable>(); 051 052 for (TreeSelectable action : TreeSelectable.values()) { 053 MAPPING.put(action.getValue(), action); 054 } 055 } 056 057 /** 058 * @param name Name of the TreeSelectable 059 * @return The matching tree selection (can't be null). 060 * @throws IllegalArgumentException When the name doesn't match any TreeSelectable. 061 */ 062 public static TreeSelectable parse(String name) throws IllegalArgumentException { 063 TreeSelectable value = MAPPING.get(name); 064 if (value != null) { 065 return value; 066 } else { 067 throw new IllegalArgumentException("Unknown name for TreeSelectable: '" + name + "'"); 068 } 069 } 070 071 public boolean isSupportedByTree() { 072 return TREE_VALUES.contains(this); 073 } 074 075 private static final Set<TreeSelectable> TREE_VALUES = EnumSet.noneOf(TreeSelectable.class); 076 077 static { 078 TREE_VALUES.add(MULTI); 079 TREE_VALUES.add(SINGLE); 080 TREE_VALUES.add(MULTI_LEAF_ONLY); 081 TREE_VALUES.add(SINGLE_LEAF_ONLY); 082 } 083 084 public boolean isSupportedByTreeListbox() { 085 return TREE_LISTBOX_VALUES.contains(this); 086 } 087 088 private static final Set<TreeSelectable> TREE_LISTBOX_VALUES = EnumSet.noneOf(TreeSelectable.class); 089 090 static { 091 TREE_LISTBOX_VALUES.add(SINGLE); 092 TREE_LISTBOX_VALUES.add(MULTI_LEAF_ONLY); 093 TREE_LISTBOX_VALUES.add(SINGLE_LEAF_ONLY); 094 } 095 }