Return-Path: Delivered-To: apmail-cocoon-cvs-archive@www.apache.org Received: (qmail 41024 invoked from network); 2 Nov 2004 10:35:01 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 2 Nov 2004 10:35:01 -0000 Received: (qmail 13380 invoked by uid 500); 2 Nov 2004 10:35:00 -0000 Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 13218 invoked by uid 500); 2 Nov 2004 10:34:59 -0000 Mailing-List: contact cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@cocoon.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list cvs@cocoon.apache.org Received: (qmail 13205 invoked by uid 99); 2 Nov 2004 10:34:59 -0000 X-ASF-Spam-Status: No, hits=-10.0 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Tue, 02 Nov 2004 02:34:57 -0800 Received: (qmail 40962 invoked by uid 65534); 2 Nov 2004 10:34:55 -0000 Date: 2 Nov 2004 10:34:55 -0000 Message-ID: <20041102103455.40957.qmail@minotaur.apache.org> From: sylvain@apache.org To: cvs@cocoon.apache.org Subject: svn commit: rev 56365 - in cocoon/branches/BRANCH_2_1_X: . src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/v2 src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/v3 src/blocks/forms/java/org/apache/cocoon/forms/formmodel src/blocks/forms/java/org/apache/cocoon/forms/generation src/blocks/forms/java/org/apache/cocoon/forms/transformation src/blocks/forms/samples src/blocks/forms/samples/dreamteam/flow src/blocks/forms/samples/forms src/blocks/forms/samples/resources X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Author: sylvain Date: Tue Nov 2 02:34:54 2004 New Revision: 56365 Added: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/WidgetState.java (contents, props changed) Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/ScriptableWidget.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/v2/ScriptableWidget.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/v3/ScriptableWidget.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractContainerWidget.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinition.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinitionBuilder.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Action.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AggregateField.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanField.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Field.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Form.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Messages.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MultiValueField.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Output.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Repeater.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Struct.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Union.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Upload.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Widget.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/generation/JXMacrosHelper.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/generation/jx-macros.xml cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/transformation/EffectWidgetReplacingPipe.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/dreamteam/flow/team.js cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/forms/carselector_form.xml cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/resources/forms-advanced-field-styling.xsl cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/resources/forms-calendar-styling.xsl cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/resources/forms-field-styling.xsl cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/sitemap.xmap cocoon/branches/BRANCH_2_1_X/status.xml Log: added widget states Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/ScriptableWidget.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/ScriptableWidget.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/ScriptableWidget.java Tue Nov 2 02:34:54 2004 @@ -22,6 +22,7 @@ import org.apache.cocoon.forms.formmodel.Output; import org.apache.cocoon.forms.formmodel.Repeater; import org.apache.cocoon.forms.formmodel.Widget; +import org.apache.cocoon.forms.formmodel.WidgetState; import org.mozilla.javascript.Context; import org.mozilla.javascript.NativeArray; import org.mozilla.javascript.Scriptable; @@ -30,7 +31,7 @@ import org.mozilla.javascript.Wrapper; /** - * @version $Id: ScriptableWidget.java,v 1.5 2004/05/07 22:04:20 joerg Exp $ + * @version $Id$ * */ public class ScriptableWidget extends ScriptableObject { @@ -275,6 +276,27 @@ public String jsGet_id() { return delegate.getId(); + } + + public WidgetState jsGet_state() { + return delegate.getState(); + } + + public void jsSet_state(Object stateObj) { + Object obj = unwrap(stateObj); + WidgetState state = null; + + if (obj instanceof String) { + state = WidgetState.stateForName((String)obj); + } else if (obj instanceof WidgetState) { + state = (WidgetState)obj; + } + + if (state == null) { + throw new IllegalArgumentException("Invalid value for widgetState " + stateObj); + } + + delegate.setState(state); } public Scriptable jsGet_parent() { Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/v2/ScriptableWidget.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/v2/ScriptableWidget.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/v2/ScriptableWidget.java Tue Nov 2 02:34:54 2004 @@ -35,12 +35,14 @@ import org.apache.cocoon.forms.formmodel.Submit; import org.apache.cocoon.forms.formmodel.Upload; import org.apache.cocoon.forms.formmodel.Widget; +import org.apache.cocoon.forms.formmodel.WidgetState; import org.apache.cocoon.forms.validation.ValidationError; import org.apache.cocoon.forms.validation.ValidationErrorAware; import org.mozilla.javascript.Context; import org.mozilla.javascript.JavaScriptException; import org.mozilla.javascript.NativeArray; import org.mozilla.javascript.Function; +import org.mozilla.javascript.NativeJavaObject; import org.mozilla.javascript.Scriptable; import org.mozilla.javascript.ScriptableObject; import org.mozilla.javascript.Undefined; @@ -53,7 +55,7 @@ import java.util.HashMap; /** - * @version $Id: ScriptableWidget.java,v 1.12 2004/05/11 09:30:24 mpo Exp $ + * @version $Id$ * */ public class ScriptableWidget extends ScriptableObject { @@ -459,6 +461,27 @@ public String jsFunction_getId() { return delegate.getId(); + } + + public WidgetState jsGet_state() { + return delegate.getState(); + } + + public void jsSet_state(Object stateObj) { + Object obj = unwrap(stateObj); + WidgetState state = null; + + if (obj instanceof String) { + state = WidgetState.stateForName((String)obj); + } else if (obj instanceof WidgetState) { + state = (WidgetState)obj; + } + + if (state == null) { + throw new IllegalArgumentException("Invalid value for widgetState " + stateObj); + } + + delegate.setState(state); } public ScriptableWidget jsFunction_getSubmitWidget() { Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/v3/ScriptableWidget.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/v3/ScriptableWidget.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript/v3/ScriptableWidget.java Tue Nov 2 02:34:54 2004 @@ -32,6 +32,7 @@ import org.apache.cocoon.forms.formmodel.Submit; import org.apache.cocoon.forms.formmodel.Upload; import org.apache.cocoon.forms.formmodel.Widget; +import org.apache.cocoon.forms.formmodel.WidgetState; import org.apache.cocoon.forms.validation.ValidationError; import org.apache.cocoon.forms.validation.ValidationErrorAware; import org.apache.cocoon.forms.validation.WidgetValidator; @@ -51,7 +52,7 @@ import java.util.HashMap; /** - * @version $Id: ScriptableWidget.java,v 1.4 2004/05/08 11:27:54 bruno Exp $ + * @version $Id$ * */ public class ScriptableWidget extends ScriptableObject implements ValueChangedListener, ActionListener, WidgetValidator { @@ -450,6 +451,27 @@ public String jsFunction_getId() { return delegate.getId(); + } + + public WidgetState jsGet_state() { + return delegate.getState(); + } + + public void jsSet_state(Object stateObj) { + Object obj = unwrap(stateObj); + WidgetState state = null; + + if (obj instanceof String) { + state = WidgetState.stateForName((String)obj); + } else if (obj instanceof WidgetState) { + state = (WidgetState)obj; + } + + if (state == null) { + throw new IllegalArgumentException("Invalid value for widgetState " + stateObj); + } + + delegate.setState(state); } public ScriptableWidget jsFunction_getSubmitWidget() { Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractContainerWidget.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractContainerWidget.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractContainerWidget.java Tue Nov 2 02:34:54 2004 @@ -37,7 +37,8 @@ /** * Constructs AbstractContainerWidget */ - public AbstractContainerWidget() { + public AbstractContainerWidget(AbstractWidgetDefinition definition) { + super(definition); widgets = new WidgetList(); } @@ -70,7 +71,9 @@ * of the contained widgets. */ public void readFromRequest(FormContext formContext) { - widgets.readFromRequest(formContext); + if (getCombinedState().isAcceptingInputs()) { + widgets.readFromRequest(formContext); + } } /** @@ -85,6 +88,9 @@ * extra validation rules on this containment level are ok. */ public boolean validate() { + if (!getCombinedState().isAcceptingInputs()) + return true; + // Validate children first, then always validate self. Return combined result. final boolean valid = widgets.validate(); return super.validate() && valid; @@ -100,6 +106,8 @@ * @throws SAXException */ public void generateItemSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException { - widgets.generateSaxFragment(contentHandler, locale); + if (getCombinedState().isDisplayingValues()) { + widgets.generateSaxFragment(contentHandler, locale); + } } } Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java Tue Nov 2 02:34:54 2004 @@ -45,6 +45,11 @@ private Widget parent; /** + * The widget's own state + */ + private WidgetState state = WidgetState.ACTIVE; + + /** * Lazy loaded reference to the top-level form. */ private Form form; @@ -58,7 +63,10 @@ * Storage for the widget allocated attributes */ private Map attributes; - + + protected AbstractWidget(AbstractWidgetDefinition definition) { + this.state = definition.getState(); + } /** * Gets the id of this widget. @@ -92,7 +100,8 @@ /** * @return The parent-widget of this widget. */ - public Widget getParent() { + // This method is final in order for other methods in this class to use this.parent + public final Widget getParent() { return parent; } @@ -123,6 +132,25 @@ return this.form; } + public WidgetState getState() { + return this.state; + } + + public void setState(WidgetState state) { + if (state == null) { + throw new IllegalArgumentException("A widget state cannot be set to null"); + } + this.state = state; + } + + public WidgetState getCombinedState() { + if (parent == null) { + return this.state; + } else { + return WidgetState.strictest(this.state, parent.getCombinedState()); + } + } + public String getRequestParameterName() { Widget myParent = getParent(); if (myParent != null) { @@ -231,8 +259,13 @@ } } - public boolean validate() { + + // Consider widget valid if it doesn't accept user inputs + if (!getCombinedState().isAcceptingInputs()) { + return true; + } + // Test validators from the widget definition if (!getDefinition().validate(this)) { // Failed @@ -270,7 +303,9 @@ * @throws SAXException */ public void generateLabel(ContentHandler contentHandler) throws SAXException { - getDefinition().generateDisplayData("label", contentHandler); + if (getCombinedState().isDisplayingValues()) { + getDefinition().generateDisplayData("label", contentHandler); + } } @@ -285,7 +320,7 @@ * @param locale in which context potential content needs to be put. * @throws SAXException */ - public void generateItemSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException { + protected void generateItemSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException { // Do nothing } @@ -295,7 +330,7 @@ * * @return the main elementname for this widget's sax-fragment. */ - public abstract String getXMLElementName(); + protected abstract String getXMLElementName(); /** * The XML attributes used in {@link #generateSaxFragment(ContentHandler, Locale)} @@ -311,13 +346,19 @@ * * @return the attributes for the main element for this widget's sax-fragment. */ - public AttributesImpl getXMLElementAttributes() { + protected AttributesImpl getXMLElementAttributes() { AttributesImpl attrs = new AttributesImpl(); // top-level widget-containers like forms will have their id set to "" // for those the @id should not be included. if (getId().length() != 0) { attrs.addCDATAAttribute("id", getRequestParameterName()); } + + // Add the "state" attribute is different from active (the default state) + WidgetState state = getCombinedState(); + if (state != WidgetState.ACTIVE) { + attrs.addCDATAAttribute("state", getCombinedState().getName()); + } return attrs; } @@ -333,7 +374,7 @@ * * @see WidgetDefinition#generateDisplayData(ContentHandler) */ - public void generateDisplayData(ContentHandler contentHandler) throws SAXException { + protected void generateDisplayData(ContentHandler contentHandler) throws SAXException { getDefinition().generateDisplayData(contentHandler); } @@ -360,15 +401,18 @@ */ public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException { - String element = this.getXMLElementName(); - AttributesImpl attrs = getXMLElementAttributes(); - contentHandler.startElement(Constants.INSTANCE_NS, element, Constants.INSTANCE_PREFIX_COLON + element, attrs); - - generateDisplayData(contentHandler); - - generateItemSaxFragment(contentHandler, locale); - - contentHandler.endElement(Constants.INSTANCE_NS, element, Constants.INSTANCE_PREFIX_COLON + element); + if (getCombinedState().isDisplayingValues()) { + + String element = this.getXMLElementName(); + AttributesImpl attrs = getXMLElementAttributes(); + contentHandler.startElement(Constants.INSTANCE_NS, element, Constants.INSTANCE_PREFIX_COLON + element, attrs); + + generateDisplayData(contentHandler); + + generateItemSaxFragment(contentHandler, locale); + + contentHandler.endElement(Constants.INSTANCE_NS, element, Constants.INSTANCE_PREFIX_COLON + element); + } } public Object getAttribute(String name) { Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinition.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinition.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinition.java Tue Nov 2 02:34:54 2004 @@ -46,6 +46,7 @@ private Map attributes; private Map displayData; private List validators; + private WidgetState state = WidgetState.ACTIVE; protected CreateListener createListener; @@ -74,7 +75,15 @@ public WidgetDefinition getParent() { return this.parent; } + + public WidgetState getState() { + return this.state; + } + public void setState(WidgetState state) { + this.state = state; + } + protected void setLocation(String location) { this.location = location; } Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinitionBuilder.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinitionBuilder.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinitionBuilder.java Tue Nov 2 02:34:54 2004 @@ -81,6 +81,17 @@ widgetDefinition.setId(id); } + // state + String stateValue = DomHelper.getAttribute(widgetElement, "state", null); + if (stateValue != null) { + WidgetState state = WidgetState.stateForName(stateValue); + if (state == null) { + throw new Exception ("Unknow value '" + stateValue +"' for state attribute at " + + DomHelper.getLocation(widgetElement)); + } + widgetDefinition.setState(state); + } + // attributes Element attrContainer = DomHelper.getChildElement(widgetElement, Constants.DEFINITION_NS, "attributes", false); if (attrContainer != null) { Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Action.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Action.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Action.java Tue Nov 2 02:34:54 2004 @@ -28,7 +28,7 @@ * ActionEvent when a requestparameter is present with as name the id of this Action widget, and as * value a non-empty value. * - * @version $Id: Action.java,v 1.10 2004/05/07 13:42:09 mpo Exp $ + * @version $Id$ */ public class Action extends AbstractWidget implements ActionListenerEnabled { private final ActionDefinition definition; @@ -36,6 +36,7 @@ private ActionListener listener; public Action(ActionDefinition definition) { + super(definition); this.definition = definition; } @@ -44,6 +45,9 @@ } public void readFromRequest(final FormContext formContext) { + if (!getCombinedState().isAcceptingInputs()) + return; + Form form = getForm(); // Set the submit widget if we can determine it from the request Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AggregateField.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AggregateField.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AggregateField.java Tue Nov 2 02:34:54 2004 @@ -95,6 +95,9 @@ } public void readFromRequest(FormContext formContext) { + if (!getCombinedState().isAcceptingInputs()) + return; + String newEnteredValue = formContext.getRequest().getParameter(getRequestParameterName()); if (newEnteredValue != null) { // There is one aggregated entered value. Read it and split it. @@ -187,6 +190,9 @@ } public boolean validate() { + if (!getCombinedState().isAcceptingInputs()) + return true; + if (enteredValue != null && !fieldsHaveValues()) { XMLizable failMessage = getAggregateFieldDefinition().getSplitFailMessage(); if (failMessage != null) { Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanField.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanField.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanField.java Tue Nov 2 02:34:54 2004 @@ -51,6 +51,7 @@ protected ValidationError validationError; public BooleanField(BooleanFieldDefinition definition) { + super(definition); this.definition = definition; } @@ -59,6 +60,9 @@ } public void readFromRequest(FormContext formContext) { + if (!getCombinedState().isAcceptingInputs()) + return; + validationError = null; Object oldValue = value; String param = formContext.getRequest().getParameter(getRequestParameterName()); Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Field.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Field.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Field.java Tue Nov 2 02:34:54 2004 @@ -112,6 +112,7 @@ public Field(FieldDefinition fieldDefinition) { + super(fieldDefinition); this.fieldDefinition = fieldDefinition; } @@ -170,6 +171,9 @@ } public void readFromRequest(FormContext formContext) { + if (!getCombinedState().isAcceptingInputs()) + return; + String newEnteredValue = formContext.getRequest().getParameter(getRequestParameterName()); // FIXME: Should we consider only non-null values, which allows to // split a form across several screens? @@ -205,6 +209,9 @@ } public boolean validate() { + if (!getCombinedState().isAcceptingInputs()) + return true; + if (this.valueState == VALUE_UNPARSED) { doParse(); } Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Form.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Form.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Form.java Tue Nov 2 02:34:54 2004 @@ -53,6 +53,7 @@ private CursorableLinkedList events; public Form(FormDefinition definition) { + super(definition); this.definition = definition; } Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Messages.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Messages.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Messages.java Tue Nov 2 02:34:54 2004 @@ -34,7 +34,7 @@ *

This widget is typically used to communicate extra validation errors or other messages * to the user, that aren't associated with any other widget in particular. * - * @version $Id: Messages.java,v 1.8 2004/04/30 12:19:01 bruno Exp $ + * @version $Id$ */ public class Messages extends AbstractWidget { private ArrayList messages = new ArrayList(); @@ -44,6 +44,7 @@ private static final String MESSAGE_EL = "message"; protected Messages(MessagesDefinition definition) { + super(definition); this.definition = definition; } @@ -52,11 +53,16 @@ } public void readFromRequest(FormContext formContext) { - messages.clear(); + if (getCombinedState().isAcceptingInputs()) { + messages.clear(); + } } public boolean validate() { - return messages.size() == 0; + if (!getCombinedState().isAcceptingInputs()) + return true; + else + return messages.size() == 0; } /** Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MultiValueField.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MultiValueField.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MultiValueField.java Tue Nov 2 02:34:54 2004 @@ -58,6 +58,7 @@ private ValidationError validationError; public MultiValueField(MultiValueFieldDefinition definition) { + super(definition); this.definition = definition; } @@ -66,6 +67,9 @@ } public void readFromRequest(FormContext formContext) { + if (!getCombinedState().isAcceptingInputs()) + return; + enteredValues = formContext.getRequest().getParameterValues(getRequestParameterName()); validationError = null; values = null; @@ -99,6 +103,9 @@ } public boolean validate() { + if (!getCombinedState().isAcceptingInputs()) + return true; + if (values != null) validationError = definition.getDatatype().validate(values, new ExpressionContextImpl(this)); else Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Output.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Output.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Output.java Tue Nov 2 02:34:54 2004 @@ -31,7 +31,7 @@ * *

An Output widget is always valid and never required. * - * @version $Id: Output.java,v 1.9 2004/05/07 13:42:09 mpo Exp $ + * @version $Id$ */ public class Output extends AbstractWidget implements DataWidget { @@ -47,6 +47,7 @@ } protected Output(OutputDefinition definition) { + super(definition); this.definition = definition; } @@ -73,7 +74,7 @@ return OUTPUT_EL; } - public void generateItemSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException { + protected void generateItemSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException { // the value if (value != null) { contentHandler.startElement(Constants.INSTANCE_NS, VALUE_EL, Constants.INSTANCE_PREFIX_COLON + VALUE_EL, XMLUtils.EMPTY_ATTRIBUTES); Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Repeater.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Repeater.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Repeater.java Tue Nov 2 02:34:54 2004 @@ -48,6 +48,7 @@ private final List rows = new ArrayList(); public Repeater(RepeaterDefinition repeaterDefinition) { + super(repeaterDefinition); this.definition = repeaterDefinition; // setup initial size removeRows(); @@ -179,6 +180,9 @@ } public void readFromRequest(FormContext formContext) { + if (!getCombinedState().isAcceptingInputs()) + return; + // read number of rows from request, and make an according number of rows String sizeParameter = formContext.getRequest().getParameter(getRequestParameterName() + ".size"); if (sizeParameter != null) { @@ -215,6 +219,9 @@ } public boolean validate() { + if (!getCombinedState().isAcceptingInputs()) + return true; + boolean valid = true; Iterator rowIt = rows.iterator(); while (rowIt.hasNext()) { @@ -303,6 +310,8 @@ public class RepeaterRow extends AbstractContainerWidget { public RepeaterRow(AbstractWidgetDefinition definition) { + super(definition); + setParent(Repeater.this); ((ContainerDefinition)definition).createWidgets(this); } @@ -319,10 +328,6 @@ return String.valueOf(rows.indexOf(this)); } - public Widget getParent() { - return Repeater.this; - } - public Form getForm() { return Repeater.this.getForm(); } @@ -334,10 +339,6 @@ // public String getFullyQualifiedId() { // return getParent().getNamespace() + "." + getId(); // } - - public void setParent(Widget widget) { - throw new RuntimeException("Parent of RepeaterRow is fixed, and cannot be set."); - } public boolean validate() { // Validate only child widtgets, as the definition's validators are those of the parent repeater Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Struct.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Struct.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Struct.java Tue Nov 2 02:34:54 2004 @@ -19,7 +19,7 @@ /** * A container {@link Widget} which can hold zero or more child widgets. * - * @version $Id: Struct.java,v 1.4 2004/04/20 22:19:27 mpo Exp $ + * @version $Id$ */ public class Struct extends AbstractContainerWidget { private static final String STRUCT_EL = "struct"; @@ -27,6 +27,7 @@ private final StructDefinition definition; public Struct(StructDefinition definition) { + super(definition); this.definition = definition; } Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Union.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Union.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Union.java Tue Nov 2 02:34:54 2004 @@ -37,6 +37,7 @@ private final UnionDefinition definition; public Union(UnionDefinition definition) { + super(definition); this.definition = definition; // TODO: Remove after moving logic to Field. //item.enteredValue = (String)definition.getDefaultValue(); @@ -74,6 +75,9 @@ } public void readFromRequest(FormContext formContext) { + if (!getCombinedState().isAcceptingInputs()) + return; + // Ensure the case widget has read its value caseWidget.readFromRequest(formContext); @@ -101,6 +105,9 @@ // TODO: Simplify this logic. public boolean validate() { + if (!getCombinedState().isAcceptingInputs()) + return true; + Widget widget; boolean valid = true; // Read current case from request Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Upload.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Upload.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Upload.java Tue Nov 2 02:34:54 2004 @@ -43,6 +43,7 @@ private ValidationError validationError; public Upload(UploadDefinition uploadDefinition) { + super(uploadDefinition); this.uploadDefinition = uploadDefinition; } @@ -67,6 +68,9 @@ } public void readFromRequest(FormContext formContext) { + if (!getCombinedState().isAcceptingInputs()) + return; + Object obj = formContext.getRequest().get(getRequestParameterName()); // If the request object is a Part, keep it @@ -97,6 +101,9 @@ } public boolean validate() { + if (!getCombinedState().isAcceptingInputs()) + return true; + if (this.part == null) { if (this.uploadDefinition.isRequired()) { this.validationError = new ValidationError(new I18nMessage("general.field-required", Constants.I18N_CATALOGUE)); Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Widget.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Widget.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Widget.java Tue Nov 2 02:34:54 2004 @@ -49,7 +49,7 @@ * keeps the Widgets small and light to create. This mechanism is similar to * classes and objects in Java. * - * @version CVS $Id: Widget.java,v 1.15 2004/05/11 12:55:53 vgritsenko Exp $ + * @version CVS $Id$ */ public interface Widget { @@ -88,7 +88,34 @@ * of the widget. */ public Form getForm(); - + + /** + * Get the widget's own state. Note that this state is not the one actually considered + * for handling requests and producing output. For these matters, the combined state is used. + * + * @see #getCombinedState() + * @return the widget's own state + */ + public WidgetState getState(); + + /** + * Set the widget's own state. This may change its combined state, and those of its + * children, if any. + * + * @param state the new wiget state + */ + public void setState(WidgetState state); + + /** + * Get the widget's combined state, which is the strictest of its own state and parent state. + * This combined state is the one that will be used by the widget to know if request + * parameters should be considered and if some output must be produced. + * + * @see WidgetState#strictest(WidgetState, WidgetState) + * @return the combined state + */ + public WidgetState getCombinedState(); + /** * @return the id prefixed with the namespace, this name should be unique * accross all widgets on the form. Added: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/WidgetState.java ============================================================================== --- (empty file) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/WidgetState.java Tue Nov 2 02:34:54 2004 @@ -0,0 +1,130 @@ +/* + * Copyright 1999-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.forms.formmodel; + +import org.apache.commons.lang.enums.ValuedEnum; + +/** + * The state of a widget. States are ordered from the most featured ("active") + * to the most constrained ("invisible"), so that state combinations can be + * computed: a widget's combined state is the strictest between the widget's own + * state and its parent state. + * + * @version CVS $Id$ + */ +public class WidgetState extends ValuedEnum { + + private static final int ACTIVE_VALUE = 3; + + private static final int DISABLED_VALUE = 2; + + private static final int INVISIBLE_VALUE = 1; + + /** + * Active state. This is the default state, where widgets read their values + * from the request and display them. + */ + public static final WidgetState ACTIVE = new WidgetState("active", ACTIVE_VALUE); + + /** + * Disabled state. Values are displayed, but user input is ignored. + */ + public static final WidgetState DISABLED = new WidgetState("disabled", DISABLED_VALUE); + + /** + * Invisible state. Values are not displayed and user input is ignored. + */ + public static final WidgetState INVISIBLE = new WidgetState("invisible", INVISIBLE_VALUE); + + /** + * Private constructor + */ + private WidgetState(String name, int value) { + super(name, value); + } + + /** + * Get a state given its name. Valid names are "active", "disabled", + * "invisible". + * + * @param name the state name + * @return the state, or null if name doesn't + * denote a known state name + */ + public static WidgetState stateForName(String name) { + return (WidgetState) getEnum(WidgetState.class, name); + } + + /** + * Determine the strictest of two states. "invisible" is stricter than + * "disabled" which is stricter than "active" + * + * @param one a state + * @param two another state + * @return the strictes of one and two + */ + public static WidgetState strictest(WidgetState one, WidgetState two) { + return (one.getValue() < two.getValue()) ? one : two; + } + + /** + * Test if the current state is stricter than another one. + * + * @param other a state + * @return true if this is stricter + * than other + */ + public boolean stricterThan(WidgetState other) { + return this.getValue() < other.getValue(); + } + + /** + * Does this state accept user inputs? + * + * @return true if this state accepts user inputs. + */ + public boolean isAcceptingInputs() { + return this.getValue() == ACTIVE_VALUE; + } + + /** + * Does this state display widget values? + * + * @return true if this state displays widget values. + */ + public boolean isDisplayingValues() { + return this.getValue() > INVISIBLE_VALUE; + } + +// Potential features provided by ValuedEnum that don't seem to be needed now +// +// public static WidgetState stateForValue(int stateValue) { +// return (WidgetState) getEnum(WidgetState.class, stateValue); +// } +// +// public static Map getEnumMap() { +// return getEnumMap(WidgetState.class); +// } +// +// public static List getStateList() { +// return getEnumList(WidgetState.class); +// } +// +// public static Iterator iterator() { +// return iterator(WidgetState.class); +// } + +} \ No newline at end of file Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/generation/JXMacrosHelper.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/generation/JXMacrosHelper.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/generation/JXMacrosHelper.java Tue Nov 2 02:34:54 2004 @@ -59,7 +59,7 @@ this.cocoonConsumer = consumer; } - public void startForm(Map attributes) throws SAXException { + public void startForm(Form form, Map attributes) throws SAXException { // build attributes AttributesImpl attrs = new AttributesImpl(); Iterator iter = attributes.entrySet().iterator(); @@ -187,6 +187,10 @@ public boolean isSelectedCase(Widget unionWidget, String caseValue) { String value = (String)unionWidget.getValue(); return caseValue.equals(value != null ? value : ""); + } + + public boolean isVisible(Widget widget) { + return widget.getCombinedState().isDisplayingValues(); } /** Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/generation/jx-macros.xml ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/generation/jx-macros.xml (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/generation/jx-macros.xml Tue Nov 2 02:34:54 2004 @@ -7,12 +7,14 @@ --> - - + + + - + +   - + + + disabled + +  
  - + + + disabled + +  
  - + + + disabled + +  
  - + + + disabled + +  
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/resources/forms-calendar-styling.xsl ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/resources/forms-calendar-styling.xsl (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/resources/forms-calendar-styling.xsl Tue Nov 2 02:34:54 2004 @@ -69,11 +69,19 @@ - - - Calendar - + + + + Calendar + + + + + Calendar + + + Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/resources/forms-field-styling.xsl ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/resources/forms-field-styling.xsl (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/resources/forms-field-styling.xsl Tue Nov 2 02:34:54 2004 @@ -65,6 +65,10 @@ +--> + + + disabled +