KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > workbench > palette > Palette


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.workbench.palette;
16
17 import java.util.List JavaDoc;
18
19 import org.apache.tapestry.IPage;
20 import org.apache.tapestry.IRequestCycle;
21 import org.apache.tapestry.annotations.InjectPage;
22 import org.apache.tapestry.contrib.palette.SortMode;
23 import org.apache.tapestry.form.IPropertySelectionModel;
24 import org.apache.tapestry.form.StringPropertySelectionModel;
25 import org.apache.tapestry.html.BasePage;
26 import org.apache.tapestry.valid.IValidationDelegate;
27
28 /**
29  * @author Howard Lewis Ship
30  */

31
32 public abstract class Palette extends BasePage
33 {
34     public abstract List JavaDoc getSelectedColors();
35
36     public abstract String JavaDoc getSort();
37
38     private IPropertySelectionModel _sortModel;
39
40     /**
41      * Invoked before {@link #formSubmit(IRequestCycle)} if the user clicks the "advance" button.
42      */

43
44     @InjectPage("PaletteResults")
45     public abstract PaletteResults getResultsPage();
46
47     public IPage advance()
48     {
49         IValidationDelegate delegate = (IValidationDelegate) getBeans().getBean("delegate");
50         
51         if (delegate.getHasErrors()) return null;
52         
53         // Since Palette and palette.Results come from
54
// a library now, we need to make sure
55
// the namespace id is part of the name.
56

57         PaletteResults results = getResultsPage();
58
59         results.setSelectedColors(getSelectedColors());
60
61         return results;
62     }
63
64     private IPropertySelectionModel colorModel;
65
66     private String JavaDoc[] colors =
67     { "Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet" };
68
69     public IPropertySelectionModel getColorModel()
70     {
71         if (colorModel == null)
72             colorModel = new StringPropertySelectionModel(colors);
73
74         return colorModel;
75     }
76
77     public IPropertySelectionModel getSortModel()
78     {
79         if (_sortModel == null)
80         {
81             String JavaDoc[] options = new String JavaDoc[]
82             { SortMode.NONE, SortMode.LABEL, SortMode.VALUE, SortMode.USER };
83
84             _sortModel = new StringPropertySelectionModel(options);
85         }
86
87         return _sortModel;
88     }
89 }
Popular Tags