KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > gui > controlx > search > SearchControlDefinition


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2005 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.cms.gui.controlx.search;
14
15 import org.apache.commons.lang.StringUtils;
16
17
18 /**
19  * @author Philipp Bracher
20  * @version $Revision: 6341 $ ($Author: philipp $)
21  */

22 public class SearchControlDefinition {
23
24     /**
25      * The name of the definition
26      */

27     private String JavaDoc name;
28
29     /**
30      * Normaly the same as the name of the field, but used to build the query
31      */

32     private String JavaDoc column;
33
34     /**
35      * Display name
36      */

37     private String JavaDoc label;
38
39     /**
40      * Used for the rendering in javascript.
41      */

42     private String JavaDoc type;
43
44     /**
45      * Default type is edit.
46      */

47     public SearchControlDefinition() {
48         setType("edit");
49     }
50
51     public SearchControlDefinition(String JavaDoc name, String JavaDoc label) {
52         this(name, label, "edit");
53     }
54
55     public SearchControlDefinition(String JavaDoc name, String JavaDoc label, String JavaDoc type) {
56         setName(name);
57         setLabel(label);
58         setType(type);
59     }
60
61     public String JavaDoc getJsField() {
62         return this.getName()
63             + ": {name:'"
64             + this.getName()
65             + "', label:'"
66             + this.getLabel()
67             + "', type:'"
68             + this.getType()
69             + "'}";
70     }
71
72     public SearchControl getSearchControlInstance(String JavaDoc value, String JavaDoc constraint) {
73         if (this.type.equals("date")) {
74             return new DateSearchControl(this, value, constraint);
75         }
76
77         return new SearchControl(this, value, constraint);
78     }
79
80     /**
81      * @return Returns the type.
82      */

83     public String JavaDoc getType() {
84         return this.type;
85     }
86
87     /**
88      * @param type The type to set.
89      */

90     public void setType(String JavaDoc type) {
91         this.type = type;
92     }
93
94     /**
95      * @return Returns the label.
96      */

97     public String JavaDoc getLabel() {
98         return this.label;
99     }
100
101     /**
102      * @param label The label to set.
103      */

104     public void setLabel(String JavaDoc label) {
105         this.label = label;
106     }
107
108     /**
109      * @return Returns the name.
110      */

111     public String JavaDoc getName() {
112         return this.name;
113     }
114
115     /**
116      * @param name The name to set.
117      */

118     public void setName(String JavaDoc name) {
119         if (StringUtils.isEmpty(this.getColumn())) {
120             this.setColumn(name);
121         }
122         // avoid broken javascripts
123
this.name = StringUtils.replace(name, ":", "_");
124     }
125
126     /**
127      * @return Returns the column.
128      */

129     public String JavaDoc getColumn() {
130         return this.column;
131     }
132
133     /**
134      * @param column The column to set.
135      */

136     public void setColumn(String JavaDoc column) {
137         this.column = column;
138     }
139
140 }
141
Popular Tags