001: /*
002: * @author <a href="mailto:novotny@gridsphere.org">Jason Novotny</a>
003: * @version $Id: BaseComponentBean.java 6385 2007-10-25 14:02:26Z wehrens $
004: */
005:
006: package org.gridsphere.provider.portletui.beans;
007:
008: import java.util.Locale;
009:
010: /**
011: * The abstract <code>BaseComponentBean</code> defines the visual bean properties of all ui tag beans
012: */
013: public abstract class BaseComponentBean extends BaseBean implements
014: Comparable {
015:
016: protected String name = null;
017: protected String value = null;
018: protected boolean readonly = false;
019: protected boolean disabled = false;
020: protected String key = null;
021:
022: protected String cssStyle = null;
023: protected String cssClass = null;
024: protected String id = null;
025:
026: /**
027: * Constructs a default base component bean
028: */
029: public BaseComponentBean() {
030: super ();
031: }
032:
033: /**
034: * Constructs a base component bean using the supplied visual bean type identifier
035: *
036: * @param vbName the supplied visual bean type identifier
037: */
038: public BaseComponentBean(String vbName) {
039: super (vbName);
040: }
041:
042: /**
043: * Sets the id of the bean (not to be confused with beanId)
044: *
045: * @param id the id of the bean
046: */
047: public void setId(String id) {
048: this .id = id;
049: }
050:
051: /**
052: * Gets the id of the bean
053: *
054: * @return id of the bean
055: */
056: public String getId() {
057: return this .id;
058: }
059:
060: /**
061: * Sets the name of the bean
062: *
063: * @param name the name of the bean
064: */
065: public void setName(String name) {
066: this .name = name;
067: }
068:
069: /**
070: * Returns the name of the bean
071: *
072: * @return name of the bean
073: */
074: public String getName() {
075: return this .name;
076: }
077:
078: /**
079: * Sets the bean value
080: *
081: * @param value the bean value
082: */
083: public void setValue(String value) {
084: this .value = value;
085: }
086:
087: /**
088: * Returns the bean value
089: *
090: * @return the bean value
091: */
092: public String getValue() {
093: return value;
094: }
095:
096: /**
097: * Returns the key used to identify localized text
098: *
099: * @return the key used to identify localized text
100: */
101: public String getKey() {
102: return key;
103: }
104:
105: /**
106: * Sets the key used to identify localized text
107: *
108: * @param key the key used to identify localized text
109: */
110: public void setKey(String key) {
111: this .key = key;
112: }
113:
114: /**
115: * Returns true if bean is in disabled state.
116: *
117: * @return state
118: */
119: public boolean isDisabled() {
120: return disabled;
121: }
122:
123: /**
124: * Sets the disabled attribute of the bean to be 'flag' state
125: *
126: * @param flag is true if the bean is to be disabled, false otherwise
127: */
128: public void setDisabled(boolean flag) {
129: this .disabled = flag;
130: }
131:
132: /**
133: * Returns disabled String if bean is disabled
134: *
135: * @return disabled String if bean is disabled or blank otherwise
136: */
137: protected String checkDisabled() {
138: if (disabled) {
139: // 'disabled' replaced by 'disabled="disabled"' for XHTML 1.0 Strict compliance
140: return " disabled=\"disabled\" ";
141: } else {
142: return "";
143: }
144: }
145:
146: /**
147: * Sets the bean to readonly
148: *
149: * @param flag is true if the bean is read-only, false otherwise
150: */
151: public void setReadOnly(boolean flag) {
152: this .readonly = flag;
153: }
154:
155: /**
156: * Returns the read-only status of the bean
157: *
158: * @return true if bean is read-only, false otherwise
159: */
160: public boolean isReadOnly() {
161: return readonly;
162: }
163:
164: /**
165: * Returns 'readonly' string if bean is read-only, blank string otherwise
166: *
167: * @return 'readonly' string if bean is read-only, blank string otherwise
168: */
169: protected String checkReadOnly() {
170: if (readonly) {
171: return " readonly ";
172: } else {
173: return "";
174: }
175: }
176:
177: public int compareTo(Object o) {
178: BaseComponentBean otherBean = (BaseComponentBean) o;
179: return value.compareToIgnoreCase(otherBean.getValue());
180: }
181:
182: /**
183: * Returns the current css style
184: *
185: * @return css style of the element
186: */
187: public String getCssStyle() {
188: return cssStyle;
189: }
190:
191: /**
192: * Sets the css style of the element.
193: *
194: * @param cssStyle the css style
195: */
196: public void setCssStyle(String cssStyle) {
197: if (cssStyle != null)
198: this .cssStyle = cssStyle;
199: }
200:
201: /**
202: * Returns the current css class of the element.
203: *
204: * @return css class of the element
205: */
206: public String getCssClass() {
207: return cssClass;
208: }
209:
210: /**
211: * Sets the css class of the element. If null nothing will be changed.
212: *
213: * @param cssClass the css class
214: */
215: public void setCssClass(String cssClass) {
216: if (cssClass != null)
217: this .cssClass = cssClass;
218: }
219:
220: public void clearCssClass() {
221: this .cssClass = null;
222: }
223:
224: public void addCssClass(String cssClass) {
225: if (this .cssClass == null)
226: this .cssClass = "";
227: if (cssClass != null)
228: this .cssClass += " " + cssClass;
229: }
230:
231: /**
232: * Returns the formatted css commands for inserting into html components.
233: *
234: * @return formatted css string for style/class attribute
235: */
236: protected String getFormattedCss() {
237: String result = "";
238: if (this .cssStyle != null) {
239: result = " style=\"" + this .cssStyle + "\"";
240: }
241: if (this .cssClass != null) {
242: result += " class=\"" + this .cssClass + "\"";
243: }
244: return result;
245: }
246:
247: public Locale getLocale() {
248: return locale;
249: }
250:
251: public void setLocale(Locale locale) {
252: this .locale = locale;
253: }
254:
255: /**
256: * Adds a css style to the exiting style.
257: *
258: * @param style style to be added
259: */
260: public void addCssStyle(String style) {
261: if (cssStyle != null) {
262: cssStyle += style;
263: } else {
264: this .setCssStyle(style);
265: }
266:
267: }
268:
269: /**
270: * Deletes the current css style.
271: */
272: public void deleteCssStyle() {
273: cssStyle = null;
274: }
275:
276: /**
277: * Deletes the current css class setting.
278: */
279: public void deleteCssClass() {
280: cssClass = null;
281: }
282: }
|