001: /**
002: * Copyright 2006 Webmedia Group Ltd.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: **/package org.araneaframework.uilib.form.formlist;
016:
017: import java.io.Serializable;
018: import org.araneaframework.uilib.form.FormWidget;
019:
020: /**
021: * Represents one editable row.
022: *
023: * @author Jevgeni Kabanov (ekabanov <i>at</i> araneaframework <i>dot</i> org)
024: */
025: public class FormRow implements Serializable {
026:
027: protected Object rowKey;
028: protected Object row;
029: protected FormWidget rowForm;
030: protected String rowFormId;
031: protected boolean open;
032: protected BaseFormListWidget formList;
033:
034: public FormRow(BaseFormListWidget formList, Object rowKey,
035: Object row, String rowFormId, FormWidget rowForm,
036: boolean open) {
037: this .rowKey = rowKey;
038: this .row = row;
039: this .rowForm = rowForm;
040: this .rowFormId = rowFormId;
041: this .open = open;
042: this .formList = formList;
043: }
044:
045: public void open() {
046: this .open = true;
047: }
048:
049: public void close() {
050: this .open = false;
051: }
052:
053: public void reset() throws Exception {
054: getFormList().resetFormRow(getKey());
055: }
056:
057: /**
058: * Returns editable row form.
059: * @return editable row form.
060: */
061: public FormWidget getForm() {
062: return rowForm;
063: }
064:
065: /**
066: * Returns editable row key.
067: * @return editable row key.
068: */
069: public Object getKey() {
070: return rowKey;
071: }
072:
073: /**
074: * Returns whether the row is open.
075: * @return whether the row is open.
076: */
077: public boolean isOpen() {
078: return open;
079: }
080:
081: /**
082: * Sets whether the row is open.
083: * @param open whether the row is open.
084: */
085: public void setOpen(boolean open) {
086: this .open = open;
087: }
088:
089: /**
090: * Returns editable row form id.
091: * @return editable row form id.
092: */
093: public String getFormId() {
094: return rowFormId;
095: }
096:
097: /**
098: * Returns assosiated list row object.
099: * @return assosiated list row object.
100: */
101: public Object getRow() {
102: return this .row;
103: }
104:
105: /**
106: * Sets assosiated list row object.
107: */
108: public void setRow(Object row) {
109: this .row = row;
110: }
111:
112: /**
113: * Returns editable list.
114: * @return editable list.
115: */
116: public BaseFormListWidget getFormList() {
117: return formList;
118: }
119:
120: /**
121: * Returns editable row view model.
122: * @return editable row view model.
123: */
124: public ViewModel getViewModel() {
125: return new ViewModel();
126: }
127:
128: public class ViewModel {
129: protected FormWidget rowForm;
130: protected String rowFormId;
131: protected Boolean open;
132:
133: public ViewModel() {
134: this .rowForm = FormRow.this .rowForm;
135: this .rowFormId = FormRow.this .rowFormId;
136: this .open = FormRow.this .open ? Boolean.TRUE
137: : Boolean.FALSE;
138: }
139:
140: /**
141: * Returns editable row form view model.
142: * @return editable row form view model.
143: */
144: public FormWidget getRowForm() {
145: return this .rowForm;
146: }
147:
148: /**
149: * Gets whether the row is open.
150: */
151: public Boolean getOpen() {
152: return this .open;
153: }
154:
155: /**
156: * Returns editable row form id.
157: * @return editable row form id.
158: */
159: public String getRowFormId() {
160: return rowFormId;
161: }
162: }
163:
164: }
|