01: // Copyright 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.corelib.pages;
16:
17: import org.apache.tapestry.FieldValidator;
18: import org.apache.tapestry.SelectModel;
19: import org.apache.tapestry.ValueEncoder;
20: import org.apache.tapestry.annotations.Component;
21: import org.apache.tapestry.annotations.Environmental;
22: import org.apache.tapestry.corelib.components.BeanEditForm;
23: import org.apache.tapestry.corelib.components.Checkbox;
24: import org.apache.tapestry.corelib.components.Select;
25: import org.apache.tapestry.corelib.components.TextField;
26: import org.apache.tapestry.services.BeanBlockContribution;
27: import org.apache.tapestry.services.BeanBlockSource;
28: import org.apache.tapestry.services.PropertyEditContext;
29: import org.apache.tapestry.util.EnumSelectModel;
30: import org.apache.tapestry.util.EnumValueEncoder;
31:
32: /**
33: * A page that exists to contain blocks used to edit different types of properties. The blocks on
34: * this page are contributed into the {@link BeanBlockSource} service configuration.
35: *
36: * @see BeanBlockContribution
37: * @see BeanEditForm
38: */
39: public class PropertyEditBlocks {
40: @Environmental
41: private PropertyEditContext _context;
42:
43: @Component(parameters={"value=context.propertyValue","label=prop:context.label","translate=prop:context.translator","validate=prop:textFieldValidator","clientId=prop:context.propertyId"})
44: private TextField _textField;
45:
46: @Component(parameters={"value=context.propertyValue","label=prop:context.label","encoder=valueEncoderForProperty","model=selectModelForProperty","validate=prop:selectValidator","clientId=prop:context.propertyId"})
47: private Select _select;
48:
49: @SuppressWarnings("unused")
50: @Component(parameters={"value=context.propertyValue","label=prop:context.label","clientId=prop:context.propertyId"})
51: private Checkbox _checkboxField;
52:
53: public PropertyEditContext getContext() {
54: return _context;
55: }
56:
57: public FieldValidator getTextFieldValidator() {
58: return _context.getValidator(_textField);
59: }
60:
61: public FieldValidator getSelectValidator() {
62: return _context.getValidator(_select);
63: }
64:
65: /** Provide a value encoder for an enum type. */
66: @SuppressWarnings("unchecked")
67: public ValueEncoder getValueEncoderForProperty() {
68: return new EnumValueEncoder(_context.getPropertyType());
69: }
70:
71: /** Provide a select mode for an enum type. */
72: @SuppressWarnings("unchecked")
73: public SelectModel getSelectModelForProperty() {
74: return new EnumSelectModel(_context.getPropertyType(), _context
75: .getContainerMessages());
76: }
77: }
|