KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > junit > mock > c14 > ListEdit


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.junit.mock.c14;
16
17 import java.util.ArrayList JavaDoc;
18 import java.util.Collections JavaDoc;
19 import java.util.HashMap JavaDoc;
20 import java.util.List JavaDoc;
21 import java.util.Map JavaDoc;
22
23 import org.apache.tapestry.IRequestCycle;
24 import org.apache.tapestry.form.IPropertySelectionModel;
25 import org.apache.tapestry.form.StringPropertySelectionModel;
26 import org.apache.tapestry.html.BasePage;
27
28 /**
29  * Page for testing the {@link org.apache.tapestry.form.ListEdit} component.
30  *
31  * @author Howard Lewis Ship
32  * @since 3.0
33  */

34
35 public abstract class ListEdit extends BasePage
36 {
37     public abstract Map JavaDoc getColorMap();
38
39     public abstract void setColorMap(Map JavaDoc colorMap);
40
41     public abstract String JavaDoc getColorKey();
42
43     private IPropertySelectionModel _colorModel;
44
45     public IPropertySelectionModel getColorModel()
46     {
47         if (_colorModel == null)
48             _colorModel = buildColorModel();
49
50         return _colorModel;
51     }
52
53     private IPropertySelectionModel buildColorModel()
54     {
55         // ResourceBundle bundle = ResourceBundle.getBundle(
56
// Color.class.getName() + "Strings",
57
// getLocale());
58

59         return new StringPropertySelectionModel(Color.ALL_COLORS);
60     }
61
62     public List JavaDoc getSortedColorKeys()
63     {
64         Map JavaDoc map = getColorMap();
65         List JavaDoc result = new ArrayList JavaDoc(map.keySet());
66
67         Collections.sort(result);
68
69         return result;
70     }
71
72     protected void finishLoad()
73     {
74         Map JavaDoc colorMap = new HashMap JavaDoc();
75
76         colorMap.put("Food", Color.RED);
77         colorMap.put("Clothing", Color.BLACK);
78         colorMap.put("Eye Color", Color.BLUE);
79
80         setColorMap(colorMap);
81     }
82
83     /**
84      * Had to implement these cause I couldn't remember the OGNL syntax for accessing a Map key.
85      */

86
87     public void setColor(String JavaDoc color)
88     {
89         getColorMap().put(getColorKey(), color);
90     }
91
92     public String JavaDoc getColor()
93     {
94         return (String JavaDoc) getColorMap().get(getColorKey());
95     }
96
97     public void formSubmit(IRequestCycle cycle)
98     {
99         ListEditResults results = (ListEditResults) cycle.getPage("ListEditResults");
100
101         results.setColorMap(getColorMap());
102
103         cycle.activate(results);
104     }
105
106 }
107
Popular Tags