001 // Copyright 2004, 2005 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 015 package org.apache.tapestry.junit.mock.c14; 016 017 import java.util.ArrayList; 018 import java.util.Collections; 019 import java.util.HashMap; 020 import java.util.List; 021 import java.util.Map; 022 023 import org.apache.tapestry.IRequestCycle; 024 import org.apache.tapestry.form.IPropertySelectionModel; 025 import org.apache.tapestry.form.StringPropertySelectionModel; 026 import org.apache.tapestry.html.BasePage; 027 028 /** 029 * Page for testing the {@link org.apache.tapestry.form.ListEdit} component. 030 * 031 * @author Howard Lewis Ship 032 * @since 3.0 033 */ 034 035 public abstract class ListEdit extends BasePage 036 { 037 public abstract Map getColorMap(); 038 039 public abstract void setColorMap(Map colorMap); 040 041 public abstract String getColorKey(); 042 043 private IPropertySelectionModel _colorModel; 044 045 public IPropertySelectionModel getColorModel() 046 { 047 if (_colorModel == null) 048 _colorModel = buildColorModel(); 049 050 return _colorModel; 051 } 052 053 private IPropertySelectionModel buildColorModel() 054 { 055 // ResourceBundle bundle = ResourceBundle.getBundle( 056 // Color.class.getName() + "Strings", 057 // getLocale()); 058 059 return new StringPropertySelectionModel(Color.ALL_COLORS); 060 } 061 062 public List getSortedColorKeys() 063 { 064 Map map = getColorMap(); 065 List result = new ArrayList(map.keySet()); 066 067 Collections.sort(result); 068 069 return result; 070 } 071 072 protected void finishLoad() 073 { 074 Map colorMap = new HashMap(); 075 076 colorMap.put("Food", Color.RED); 077 colorMap.put("Clothing", Color.BLACK); 078 colorMap.put("Eye Color", Color.BLUE); 079 080 setColorMap(colorMap); 081 } 082 083 /** 084 * Had to implement these cause I couldn't remember the OGNL syntax for accessing a Map key. 085 */ 086 087 public void setColor(String color) 088 { 089 getColorMap().put(getColorKey(), color); 090 } 091 092 public String getColor() 093 { 094 return (String) getColorMap().get(getColorKey()); 095 } 096 097 public void formSubmit(IRequestCycle cycle) 098 { 099 ListEditResults results = (ListEditResults) cycle.getPage("ListEditResults"); 100 101 results.setColorMap(getColorMap()); 102 103 cycle.activate(results); 104 } 105 106 }