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.list;
016:
017: import java.io.Serializable;
018: import java.util.ArrayList;
019: import java.util.Iterator;
020: import java.util.List;
021:
022: /**
023: * This class represents the ordering information supplied by user in a series
024: * of UI interactions.
025: *
026: * @author Jevgeni Kabanov (ekabanov <i>at</i> araneaframework <i>dot</i> org)
027: */
028: public class OrderInfo implements Serializable {
029:
030: protected List fields = new ArrayList();
031:
032: /**
033: * Returns the ordering fields.
034: *
035: * @return the ordering fields.
036: */
037: public List getFields() {
038: return this .fields;
039: }
040:
041: /**
042: * Clears ordering fields.
043: */
044: public void clearFields() {
045: this .fields.clear();
046: }
047:
048: /**
049: * Adds an ordering field.
050: *
051: * @param field
052: * an ordering field.
053: */
054: public void addField(OrderInfoField field) {
055: this .fields.add(field);
056: }
057:
058: /**
059: * Returns view model.
060: *
061: * @return view model.
062: */
063: public ViewModel getViewModel() {
064: return new ViewModel();
065: }
066:
067: /**
068: * View model.
069: *
070: * @author Jevgeni Kabanov (ekabanov <i>at</i> araneaframework <i>dot</i> org)
071: */
072: public class ViewModel implements Serializable {
073: private List fields = new ArrayList();
074:
075: /**
076: * Takes a snapshot of outer class state.
077: */
078: public ViewModel() {
079: for (Iterator i = OrderInfo.this .fields.iterator(); i
080: .hasNext();) {
081: this .fields.add(((OrderInfoField) i.next())
082: .getViewModel());
083: }
084: }
085:
086: /**
087: * Returns the ordering fields.
088: *
089: * @return the ordering fields.
090: */
091: public List getFields() {
092: return this .fields;
093: }
094: }
095:
096: public String toString() {
097: StringBuffer sb = new StringBuffer("OrderInfo (");
098: for (Iterator i = this .fields.iterator(); i.hasNext();) {
099: OrderInfoField field = (OrderInfoField) i.next();
100: sb.append(field.toString());
101: if (i.hasNext()) {
102: sb.append("; ");
103: }
104: }
105: sb.append(")");
106: return sb.toString();
107: }
108: }
|