001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.jbpm.util;
022:
023: import com.liferay.portal.kernel.util.StringPool;
024: import com.liferay.portal.kernel.util.StringUtil;
025: import com.liferay.portal.kernel.util.Validator;
026:
027: import java.io.Serializable;
028:
029: import java.util.ArrayList;
030: import java.util.List;
031:
032: import org.jbpm.context.def.VariableAccess;
033:
034: /**
035: * <a href="TaskFormElement.java.html"><b><i>View Source</i></b></a>
036: *
037: * @author Charles May
038: *
039: */
040: public class TaskFormElement implements Serializable {
041:
042: public static final String TYPE_CHECKBOX = "checkbox";
043:
044: public static final String TYPE_DATE = "date";
045:
046: public static final String TYPE_EMAIL = "email";
047:
048: public static final String TYPE_NUMBER = "number";
049:
050: public static final String TYPE_PASSWORD = "password";
051:
052: public static final String TYPE_PHONE = "phone";
053:
054: public static final String TYPE_RADIO = "radio";
055:
056: public static final String TYPE_SELECT = "select";
057:
058: public static final String TYPE_TEXT = "text";
059:
060: public static final String TYPE_TEXTAREA = "textarea";
061:
062: public TaskFormElement() {
063: }
064:
065: public TaskFormElement(VariableAccess variableAccess, String value) {
066: _variableName = variableAccess.getVariableName();
067:
068: String[] dataElements = StringUtil.split(_variableName,
069: StringPool.COLON);
070:
071: _type = dataElements[0];
072: _displayName = dataElements[1];
073:
074: if (_type.equals(TYPE_CHECKBOX) || _type.equals(TYPE_RADIO)
075: || _type.equals(TYPE_SELECT)) {
076:
077: String[] values = StringUtil.split(dataElements[2],
078: StringPool.COMMA);
079:
080: for (int i = 0; i < values.length; i++) {
081: _valueList.add(values[i]);
082: }
083: }
084:
085: _value = value;
086: _readable = variableAccess.isReadable();
087: _writable = variableAccess.isWritable();
088: _required = variableAccess.isRequired();
089: }
090:
091: public String getDisplayName() {
092: return _displayName;
093: }
094:
095: public void setDisplayName(String displayName) {
096: _displayName = displayName;
097: }
098:
099: public String getDateName() {
100: if (Validator.isNotNull(_displayName)) {
101: return StringUtil.replace(_displayName, StringPool.DASH,
102: StringPool.UNDERLINE);
103: } else {
104: return _displayName;
105: }
106: }
107:
108: public String getVariableName() {
109: return _variableName;
110: }
111:
112: public void setVariableName(String variableName) {
113: _variableName = variableName;
114: }
115:
116: public String getType() {
117: return _type;
118: }
119:
120: public void setType(String type) {
121: _type = type;
122: }
123:
124: public String getValue() {
125: return _value;
126: }
127:
128: public void setValue(String value) {
129: _value = value;
130: }
131:
132: public List getValueList() {
133: return _valueList;
134: }
135:
136: public void setValueList(List valueList) {
137: _valueList = valueList;
138: }
139:
140: public boolean isReadable() {
141: return _readable;
142: }
143:
144: public void setReadable(boolean readable) {
145: _readable = readable;
146: }
147:
148: public boolean isRequired() {
149: return _required;
150: }
151:
152: public void setRequired(boolean required) {
153: _required = required;
154: }
155:
156: public boolean isWritable() {
157: return _writable;
158: }
159:
160: public void setWritable(boolean writable) {
161: _writable = writable;
162: }
163:
164: public boolean isReadOnly() {
165: return !_writable;
166: }
167:
168: private String _displayName;
169: private String _variableName;
170: private String _type;
171: private String _value;
172: private List _valueList = new ArrayList();
173: private boolean _readable = true;
174: private boolean _writable = true;
175: private boolean _required = true;
176:
177: }
|