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: /**
027: * Abstract base class for editor elements.
028: *
029: * @author Felix Gnass [fgnass at neteye dot de]
030: */
031: public abstract class AbstractEditorBase extends AbstractElement {
032:
033: private String paramName;
034:
035: private String desiredParamName;
036:
037: private EditorBinding binding;
038:
039: private String fieldName;
040:
041: public EditorBinding getEditorBinding() {
042: return binding;
043: }
044:
045: public final void setEditorBinding(EditorBinding binding) {
046: this .binding = binding;
047: afterBindingSet();
048: }
049:
050: protected void afterBindingSet() {
051: }
052:
053: public void setDesiredParamName(String desiredParamName) {
054: this .desiredParamName = desiredParamName;
055: }
056:
057: protected String getDesiredParamName() {
058: if (desiredParamName != null) {
059: return desiredParamName;
060: }
061: if (binding != null) {
062: return binding.getProperty();
063: }
064: return null;
065: }
066:
067: public String getParamName() {
068: if (paramName == null) {
069: paramName = getForm().createUniqueParameterName(
070: getDesiredParamName());
071: log.debug("Param name for element " + getId() + " is: "
072: + paramName);
073: }
074: return paramName;
075: }
076:
077: public void setParamName(String paramName) {
078: this .paramName = paramName;
079: }
080:
081: public void setFieldName(String fieldName) {
082: this .fieldName = fieldName;
083: }
084:
085: public String getFieldName() {
086: if (fieldName != null) {
087: return fieldName;
088: }
089: if (binding != null) {
090: return binding.getPropertyPath();
091: }
092: return "unbound-" + getId();
093: }
094:
095: public String getLabel() {
096: String label = super .getLabel();
097: if (label == null && binding != null) {
098: label = MessageUtils.getLabel(this , binding);
099: super .setLabel(label);
100: }
101: return label;
102: }
103:
104: public String getHint() {
105: String hint = super.getHint();
106: if (hint == null && binding != null) {
107: hint = MessageUtils.getHint(this, binding);
108: super.setHint(hint);
109: }
110: return hint;
111: }
112: }
|