KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > riotfamily > forms > AbstractEditorBase


1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1
3  * The contents of this file are subject to the Mozilla Public License Version
4  * 1.1 (the "License"); you may not use this file except in compliance with
5  * the License. You may obtain a copy of the License at
6  * http://www.mozilla.org/MPL/
7  *
8  * Software distributed under the License is distributed on an "AS IS" basis,
9  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
10  * for the specific language governing rights and limitations under the
11  * License.
12  *
13  * The Original Code is Riot.
14  *
15  * The Initial Developer of the Original Code is
16  * Neteye GmbH.
17  * Portions created by the Initial Developer are Copyright (C) 2006
18  * the Initial Developer. All Rights Reserved.
19  *
20  * Contributor(s):
21  * Felix Gnass [fgnass at neteye dot de]
22  *
23  * ***** END LICENSE BLOCK ***** */

24 package org.riotfamily.forms;
25
26
27 /**
28  * Abstract base class for editor elements.
29  *
30  * @author Felix Gnass [fgnass at neteye dot de]
31  */

32 public abstract class AbstractEditorBase extends AbstractElement {
33
34     private String JavaDoc paramName;
35
36     private String JavaDoc desiredParamName;
37     
38     private EditorBinding binding;
39     
40     private String JavaDoc fieldName;
41     
42     public EditorBinding getEditorBinding() {
43         return binding;
44     }
45     
46     public final void setEditorBinding(EditorBinding binding) {
47         this.binding = binding;
48         afterBindingSet();
49     }
50     
51     protected void afterBindingSet() {
52     }
53     
54     public void setDesiredParamName(String JavaDoc desiredParamName) {
55         this.desiredParamName = desiredParamName;
56     }
57     
58     protected String JavaDoc getDesiredParamName() {
59         if (desiredParamName != null) {
60             return desiredParamName;
61         }
62         if (binding != null) {
63             return binding.getProperty();
64         }
65         return null;
66     }
67     
68     public String JavaDoc getParamName() {
69         if (paramName == null) {
70             paramName = getForm().createUniqueParameterName(getDesiredParamName());
71             log.debug("Param name for element " + getId() + " is: " + paramName);
72         }
73         return paramName;
74     }
75
76     public void setParamName(String JavaDoc paramName) {
77         this.paramName = paramName;
78     }
79
80     public void setFieldName(String JavaDoc fieldName) {
81         this.fieldName = fieldName;
82     }
83     
84     public String JavaDoc getFieldName() {
85         if (fieldName != null) {
86             return fieldName;
87         }
88         if (binding != null) {
89             return binding.getPropertyPath();
90         }
91         return "unbound-" + getId();
92     }
93     
94     public String JavaDoc getLabel() {
95         String JavaDoc label = super.getLabel();
96         if (label == null && binding != null) {
97             label = MessageUtils.getLabel(this, binding);
98             super.setLabel(label);
99         }
100         return label;
101     }
102         
103     public String JavaDoc getHint() {
104         String JavaDoc hint = super.getHint();
105         if (hint == null && binding != null) {
106             hint = MessageUtils.getHint(this, binding);
107             super.setHint(hint);
108         }
109         return hint;
110     }
111 }
112
Popular Tags