001: /* ***** BEGIN LICENSE BLOCK *****
002: * Version: MPL 1.1
003: * The contents of this file are subject to the Mozilla Public License Version
004: * 1.1 (the "License"); you may not use this file except in compliance with
005: * the License. You may obtain a copy of the License at
006: * http://www.mozilla.org/MPL/
007: *
008: * Software distributed under the License is distributed on an "AS IS" basis,
009: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
010: * for the specific language governing rights and limitations under the
011: * License.
012: *
013: * The Original Code is Riot.
014: *
015: * The Initial Developer of the Original Code is
016: * Neteye GmbH.
017: * Portions created by the Initial Developer are Copyright (C) 2006
018: * the Initial Developer. All Rights Reserved.
019: *
020: * Contributor(s):
021: * Felix Gnass [fgnass at neteye dot de]
022: *
023: * ***** END LICENSE BLOCK ***** */
024: package org.riotfamily.forms;
025:
026: import java.io.PrintWriter;
027:
028: import org.riotfamily.forms.request.FormRequest;
029:
030: /**
031: * Interface to be implemented by all form elements. If you want to create a
032: * new element you will most likely want to subclass one of the abstract base
033: * classes in the <code>de.neteye.forms.element.support</code> package.
034: */
035: public interface Element {
036:
037: /**
038: * Sets the element's unique id. Ids are assigned when an element is
039: * registered with a form.
040: *
041: * @see Form#registerElement(Element)
042: */
043: public void setId(String id);
044:
045: /**
046: * Returns the previously assigned id.
047: */
048: public String getId();
049:
050: /**
051: * Sets a reference to the form that contains the element.
052: */
053: public void setForm(Form form);
054:
055: /**
056: * Returns the form that contains the element.
057: */
058: public Form getForm();
059:
060: /**
061: * Sets the FormContext. Invoked by {@link Form#registerElement(Element)}
062: * or {@link Form#setFormContext(FormContext)}.
063: */
064: public void setFormContext(FormContext formContext);
065:
066: /**
067: * Sets the element's parent. E.g. the parent element is taken into account
068: * to determine the enabled state of the element.
069: */
070: public void setParent(Element parent);
071:
072: /**
073: * Returns the element's parent.
074: */
075: public Element getParent();
076:
077: /**
078: * This method is invoked whenever a HTTP request needs to be processed.
079: * Elements may implement this method to change their internal state
080: * according to parameters found in the request.
081: */
082: public void processRequest(FormRequest request);
083:
084: /**
085: * Renders the element to the given writer.
086: */
087: public void render(PrintWriter writer);
088:
089: /**
090: * Focuses the element.
091: */
092: public void focus();
093:
094: /**
095: * Returns whether the element will accept user input. The state should
096: * be considered during rendering, i.e. disabled elements should look
097: * different than enabled ones.
098: */
099: public boolean isEnabled();
100:
101: /**
102: * Enables (or disables) the element.
103: */
104: public void setEnabled(boolean enabled);
105:
106: /**
107: * Returns whether the element is mandatory and must be filled out by
108: * the user.
109: */
110: public boolean isRequired();
111:
112: /**
113: * Sets whether the element is required.
114: */
115: public void setRequired(boolean required);
116:
117: /**
118: * Returns whether the element is composed of multiple widgets.
119: * The information may be used by templates to render composite elements
120: * in the same style as element groups or nested forms.
121: */
122: public boolean isCompositeElement();
123:
124: }
|