001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.forms.formmodel;
018:
019: import org.apache.cocoon.forms.FormsException;
020: import org.apache.cocoon.forms.event.RepeaterEvent;
021: import org.apache.cocoon.forms.event.RepeaterListener;
022: import org.apache.cocoon.forms.event.WidgetEventMulticaster;
023:
024: /**
025: * The {@link WidgetDefinition} part of a Repeater widget, see {@link Repeater} for more information.
026: *
027: * @version $Id: RepeaterDefinition.java 449452 2006-09-24 18:26:03Z simoneg $
028: */
029: public class RepeaterDefinition extends AbstractContainerDefinition {
030:
031: private int initialSize = 0;
032: private int minSize;
033: private int maxSize;
034: private boolean orderable;
035: private RepeaterListener listener;
036:
037: private boolean enhanced = false;
038: private int initialPage = 0;
039: private int pageSize;
040: private String customPageId;
041:
042: public RepeaterDefinition(int initialSize, int minSize,
043: int maxSize, boolean selectable, boolean orderable) {
044: super ();
045: this .initialSize = initialSize;
046: this .minSize = minSize;
047: this .maxSize = maxSize;
048: this .orderable = orderable;
049: }
050:
051: public RepeaterDefinition(int initialSize, int minSize,
052: int maxSize, boolean selectable, boolean orderable,
053: boolean enhanced, int initialPage, int pageSize,
054: String customPageId) {
055: super ();
056: this .initialSize = initialSize;
057: this .minSize = minSize;
058: this .maxSize = maxSize;
059: this .orderable = orderable;
060: this .enhanced = enhanced;
061: this .initialPage = initialPage;
062: this .pageSize = pageSize;
063: this .customPageId = customPageId;
064: }
065:
066: /**
067: * initialize this definition with the other, sort of like a copy constructor
068: */
069: public void initializeFrom(WidgetDefinition definition)
070: throws Exception {
071: super .initializeFrom(definition);
072:
073: if (!(definition instanceof RepeaterDefinition)) {
074: throw new FormsException("Parent definition "
075: + definition.getClass().getName()
076: + " is not a RepeaterDefinition.", getLocation());
077: }
078:
079: RepeaterDefinition other = (RepeaterDefinition) definition;
080: this .initialSize = other.initialSize;
081: this .maxSize = other.maxSize;
082: this .minSize = other.minSize;
083: this .enhanced = other.enhanced;
084: this .orderable = other.orderable;
085: this .initialPage = other.initialPage;
086: this .pageSize = other.pageSize;
087: }
088:
089: public Widget createInstance() {
090: if (enhanced) {
091: return new EnhancedRepeater(this );
092: } else {
093: return new Repeater(this );
094: }
095: }
096:
097: public int getInitialSize() {
098: return this .initialSize;
099: }
100:
101: public int getMaxSize() {
102: return this .maxSize;
103: }
104:
105: public int getMinSize() {
106: return this .minSize;
107: }
108:
109: public boolean getOrderable() {
110: return this .orderable;
111: }
112:
113: public void addRepeaterListener(RepeaterListener listener) {
114: checkMutable();
115: this .listener = WidgetEventMulticaster.add(this .listener,
116: listener);
117: }
118:
119: public void fireRepeaterEvent(RepeaterEvent event) {
120: if (this .listener != null) {
121: this .listener.repeaterModified(event);
122: }
123: }
124:
125: public boolean hasRepeaterListeners() {
126: return this .listener != null;
127: }
128:
129: public RepeaterListener getRepeaterListener() {
130: return this .listener;
131: }
132:
133: public int getInitialPage() {
134: return initialPage;
135: }
136:
137: public int getPageSize() {
138: return pageSize;
139: }
140:
141: public boolean isEnhanced() {
142: return enhanced;
143: }
144:
145: public String getCustomPageId() {
146: return customPageId;
147: }
148:
149: }
|