KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > databinding > datagrid > runtime > config > DefaultDataGridConfig


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

18 package org.apache.beehive.netui.databinding.datagrid.runtime.config;
19
20 import java.util.List JavaDoc;
21
22 import javax.servlet.ServletRequest JavaDoc;
23
24 import org.apache.beehive.netui.databinding.datagrid.api.sort.Sort;
25 import org.apache.beehive.netui.databinding.datagrid.api.sort.SortModel;
26 import org.apache.beehive.netui.databinding.datagrid.api.sort.SortStrategy;
27 import org.apache.beehive.netui.databinding.datagrid.api.filter.FilterModel;
28 import org.apache.beehive.netui.databinding.datagrid.api.filter.Filter;
29 import org.apache.beehive.netui.databinding.datagrid.api.pager.PagerModel;
30 import org.apache.beehive.netui.databinding.datagrid.api.rendering.PagerRenderer;
31 import org.apache.beehive.netui.databinding.datagrid.api.rendering.StyleModel;
32 import org.apache.beehive.netui.databinding.datagrid.api.DataGridConfig;
33 import org.apache.beehive.netui.databinding.datagrid.api.DataGridResourceProvider;
34 import org.apache.beehive.netui.databinding.datagrid.api.DataGridState;
35 import org.apache.beehive.netui.databinding.datagrid.api.DataGridStateCodec;
36 import org.apache.beehive.netui.databinding.datagrid.runtime.rendering.pager.PreviousNextPagerRenderer;
37 import org.apache.beehive.netui.databinding.datagrid.runtime.model.style.DefaultStyleModel;
38 import org.apache.beehive.netui.databinding.datagrid.runtime.model.style.EmptyStyleModel;
39
40 /**
41  * <p>
42  * Default implementation of the {@link DataGridConfig} base class. This class is used to provide concrete
43  * implementations of state containers and service providers for the data grid.
44  * </p>
45  */

46 public class DefaultDataGridConfig
47     extends DataGridConfig {
48
49     private static final String JavaDoc STYLE_POLICY_NAME_EMPTY = "empty";
50     private static final String JavaDoc STYLE_POLICY_NAME_DEFAULT = "default";
51     private static final String JavaDoc STYLE_PREFIX_DEFAULT = "datagrid";
52
53     private static final StyleModel DEFAULT_STYLE_POLICY = new DefaultStyleModel(STYLE_PREFIX_DEFAULT);
54     private static final StyleModel EMPTY_STYLE_POLICY = new EmptyStyleModel();
55     private static final SortStrategy SORT_STRATEGY = new DefaultSortStrategy();
56
57     /**
58      * Create a {@link DataGridState} object. The default implementation returned is
59      * {@link DataGridState}.
60      * @return a data grid state implementation
61      */

62     public DataGridState createDataGridState() {
63         return new DataGridState();
64     }
65
66     /**
67      * Create a {@link Sort} object. The default implementation returned is {@link Sort}.
68      * @return a sort
69      */

70     public Sort createSort() {
71         return new Sort();
72     }
73
74     /**
75      * Create a {@link Filter} object. The default implementation returned is {@link Filter}.
76      * @return a filter
77      */

78     public Filter createFilter() {
79         return new Filter();
80     }
81
82     /**
83      * Create a {@link SortModel} object. The default implementation returned is {@link SortModel} with a
84      * {@link SortStrategy} of {@link org.apache.beehive.netui.databinding.datagrid.runtime.config.DefaultSortStrategy}.
85      * @param sorts the list of sorts for a data grid
86      * @return a sort model
87      */

88     public SortModel createSortModel(List JavaDoc/*<Sort>*/ sorts) {
89         SortModel sortModel = new SortModel(sorts);
90         sortModel.setSortStrategy(SORT_STRATEGY);
91         return sortModel;
92     }
93
94     /**
95      * Create a {@link FilterModel} object. The default implementation returned is {@link FilterModel}.
96      * @param filters the list of filters for a data grid
97      * @return a filter model
98      */

99     public FilterModel createFilterModel(List JavaDoc/*<Filter>*/ filters) {
100         return new FilterModel(filters);
101     }
102
103     /**
104      * Create a {@link PagerModel} object. The default implementation returned is {@link PagerModel}.
105      * @return a pager model
106      */

107     public PagerModel createPagerModel() {
108         return new PagerModel();
109     }
110
111     /**
112      * Create a {@link DataGridStateCodec} for a grid with the given name for the given {@link ServletRequest}.
113      * @param request the current request
114      * @param gridName a data grid's name
115      * @return the state encoder / decoder for a data grid's request state
116      */

117     public DataGridStateCodec createStateCodec(ServletRequest JavaDoc request, String JavaDoc gridName) {
118         DefaultDataGridStateCodec codec = new DefaultDataGridStateCodec(this);
119         codec.setServletRequest(request);
120         codec.setGridName(gridName);
121         return codec;
122     }
123
124     /**
125      * Get the default {@link PagerRenderer}. The default pager renderer will display a pager with previous / next
126      * page links via the implementation class {@link PreviousNextPagerRenderer}.
127      * @return the pager renderer
128      */

129     public PagerRenderer getDefaultPagerRenderer() {
130         return new PreviousNextPagerRenderer();
131     }
132
133     /**
134      * Get a {@link DataGridResourceProvider}. The default implementation class is
135      * {@link org.apache.beehive.netui.databinding.datagrid.runtime.config.DefaultDataGridResourceProvider}
136      * and provides a basic implementation that reads messages from the default .properties file.
137      * @return the resource provider
138      */

139     public DataGridResourceProvider getDefaultResourceProvider() {
140         return new DefaultDataGridResourceProvider();
141     }
142
143     /**
144      * Get a {@link DataGridResourceProvider} for the given resource bundle path. The default implementation
145      * will set this resource bundle but does not enable message chaining.
146      * @param resourceBundle a resource bundle specifically requested by a data grid
147      * @return the resource provider
148      */

149     public DataGridResourceProvider getResourceProvider(String JavaDoc resourceBundle) {
150         DataGridResourceProvider resourceProvider = new DefaultDataGridResourceProvider();
151         resourceProvider.setResourceBundlePath(resourceBundle);
152         return resourceProvider;
153     }
154
155     /**
156      * Get a {@link StyleModel} given a model name and a style class prefix. This class exposes two available
157      * style names:
158      * <table>
159      * <tr><td>Name</td><td>Description</td><td>Implementation Class</td></tr>
160      * <tr><td><code>empty</code></td>
161      * <td>Renders CSS style classes that are non-prefixed and generally empty.</td>
162      * <td>{@link EmptyStyleModel}</td>
163      * </tr>
164      * <tr><td><code>default</code></td>
165      * <td>Renders CSS style classes with names using a default prefix of <code>datagrid</code></td>
166      * <td>{@link DefaultStyleModel}</td>
167      * </tr>
168      * </table>
169      * When using the <code>empty</code> style model, styles rendered on the &lt;table&gt; element will
170      * be empty; the same style rendered wtih the <code>default</code> style model will render as
171      * <code>class="datagrid"</code>. If the style prefix "foo" is provided for the <code>default</code> style policy
172      * the style name will be rendered as <code>class="foo"</code>.x
173      * @param name the name of a {@link StyleModel} implementation to use
174      * @param classPrefix the prefix for a style name
175      * @return the style model
176      */

177     public StyleModel getStyleModel(String JavaDoc name, String JavaDoc classPrefix) {
178         if(name == null || name.equals(STYLE_POLICY_NAME_DEFAULT)) {
179             if(classPrefix != null)
180                 return new DefaultStyleModel(classPrefix);
181             else return DEFAULT_STYLE_POLICY;
182         }
183         else if(name != null && name.equals(STYLE_POLICY_NAME_EMPTY))
184             return EMPTY_STYLE_POLICY;
185         else return DEFAULT_STYLE_POLICY;
186     }
187 }
188
Popular Tags