KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mdarad > framework > util > struts > criteria > ListCriterion


1 /*
2     Mdarad-Toolobox is a collection of tools for Architected RAD
3     (Rapid Application Development) based on an MDA approach.
4     The toolbox contains frameworks and generators for many environments
5     (JAVA, J2EE, Hibernate, .NET, C++, etc.) which allow to generate
6     applications from a design Model
7     Copyright (C) 2004-2005 Elapse Technologies Inc.
8
9     This library is free software; you can redistribute it and/or
10     modify it under the terms of the GNU General Public
11     License as published by the Free Software Foundation; either
12     version 2.1 of the License, or (at your option) any later version.
13
14     This library is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17     General Public License for more details.
18
19     You should have received a copy of the GNU General Public
20     License along with this library; if not, write to the Free Software
21     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */

23 package org.mdarad.framework.util.struts.criteria;
24
25 import java.util.Collection JavaDoc;
26 import java.util.Locale JavaDoc;
27
28 import org.mdarad.framework.expr.Criterion;
29 import org.mdarad.framework.expr.OperatorTypes;
30
31 /**
32  * This class represents a search criterion that presents a list of values to the user.
33  * To use this criterion, you need to set a {@link List List} of {@link CriterionListElement CriterionListElement}
34  * to the criterion. This list will be displayed as the selection of values.
35  * @author Philippe Brouillette
36  * @version 1.0
37  */

38 public class ListCriterion extends FormCriterion {
39
40     /**
41      * Constructor that takes all the properties to initialize a search
42      * criterion. By default, the criterion is dynamic.
43      * @param name name of the criterion. This name must be unique
44      * as it is a key in a map.
45      * @param associatedEntity class type associated to this criterion
46      * @param property property used for the query criterion
47      * @param bundleName bundle name
48      * @param locale locale information
49      * @see FormCriterion#FormCriterion(String, CriterionProperty, String, Locale) FormCriterion
50      */

51     public ListCriterion(String JavaDoc name, Class JavaDoc associatedEntity, CriterionProperty property, String JavaDoc bundleName, Locale JavaDoc locale) {
52         super(name, associatedEntity, property, bundleName, locale);
53     }
54
55     /**
56      * Constructor that clones a query criterion. This constructor is used
57      * to instanciate a criterion in a search form when the form
58      * contains dynamic criteria.
59      * @param criterion query criterion that must be of
60      * type <code>ListCriterion</code>
61      * @see FormCriterion#FormCriterion(FormCriterion) FormCriterion
62      */

63     public ListCriterion(ListCriterion criterion) {
64         super(criterion);
65         setList(criterion.getList());
66     }
67     
68     /**
69      * Method that assigns the value of the criterion as a String. This method
70      * is needed for the user interface which uses only string values.
71      * @param value value to be assigned
72      * @see FormCriterion#setPropertyValue(java.lang.String)
73      */

74     public void setPropertyValue(String JavaDoc value) {
75         if (value != null) {
76             setValue(value);
77         }
78     }
79     
80     /**
81      * Method that returns the object type of the criterion value. In this
82      * case it returns a String object.
83      *
84      * @see FormCriterion#getObjectType()
85      */

86     public Class JavaDoc getObjectType() {
87         return String JavaDoc.class;
88     }
89
90     /**
91      * Method that returns the criterion from the expression
92      * framework. ({@link Criterion})
93      * <p><b>NOTE:</b> The implementation must take care of the type
94      * of operator that is used to determine the criterion to use.
95      * @return the criterion
96      */

97     public Criterion getExprCriterion() {
98         Criterion crit = new Criterion(getAssociatedEntity(),
99                 getProperty().getName(),
100                 OperatorTypes.EQUAL,
101                 getValue());
102
103         return crit;
104     }
105
106     /**
107      * Property that keeps the list of allowable values
108      * associated to the criterion.
109      */

110     private Collection JavaDoc criterionElements;
111     
112     /**
113      * Method that adds a new allowable value to the list of elements.
114      * @param element element of the list. Must be of type
115      * {@link CriterionListElement CriterionListElement}
116      */

117     public void addCriterionElement(CriterionListElement element) {
118         if (element != null) {
119             criterionElements.add(element);
120         }
121     }
122     
123     /**
124      * Method that returns the list of allowables elements of the
125      * list.
126      * @return a {@link java.util.Collection Collection}
127      */

128     public Collection JavaDoc getList() {
129         return criterionElements;
130     }
131
132     /**
133      * Method that sets the list of allowable elements.
134      * The list must contains objects of the
135      * {@link CriterionListElement CriterionListElement}
136      * class type
137      * @param list list of {@link CriterionListElement}
138      */

139     public void setList(Collection JavaDoc list) {
140         this.criterionElements = list;
141     }
142
143     /**
144      * Method that returns the displaying pattern.
145      *
146      * @see FormCriterion#getFormPattern()
147      */

148     public CriterionFormPattern getFormPattern() {
149         return CriterionFormPatterns.NO_OPERATOR_LIST;
150     }
151     
152     /**
153      * Property that keeps the link of the onchange action in
154      * javascript. Patch to allow a on change action of a criterion.
155      */

156     private String JavaDoc onChangeAction = "";
157     
158     public String JavaDoc getOnChangeAction() {
159         return onChangeAction;
160     }
161     
162     public void setOnChangeAction(String JavaDoc onChangeAction) {
163         this.onChangeAction = onChangeAction;
164     }
165 }
Popular Tags