001: // Copyright 2007 The Apache Software Foundation
002: //
003: // Licensed under the Apache License, Version 2.0 (the "License");
004: // you may not use this file except in compliance with the License.
005: // You may obtain a copy of the License at
006: //
007: // http://www.apache.org/licenses/LICENSE-2.0
008: //
009: // Unless required by applicable law or agreed to in writing, software
010: // distributed under the License is distributed on an "AS IS" BASIS,
011: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: // See the License for the specific language governing permissions and
013: // limitations under the License.
014:
015: package org.apache.tapestry.internal.beaneditor;
016:
017: import static org.apache.tapestry.ioc.internal.util.Defense.notBlank;
018:
019: import org.apache.tapestry.PropertyConduit;
020: import org.apache.tapestry.beaneditor.BeanModel;
021: import org.apache.tapestry.beaneditor.PropertyModel;
022: import org.apache.tapestry.internal.TapestryInternalUtils;
023: import org.apache.tapestry.ioc.Messages;
024: import org.apache.tapestry.ioc.services.ClassFabUtils;
025:
026: public class PropertyModelImpl implements PropertyModel {
027: private final BeanModel _model;
028:
029: private final String _name;
030:
031: private final PropertyConduit _conduit;
032:
033: private final String _id;
034:
035: private String _label;
036:
037: private int _order;
038:
039: private String _dataType;
040:
041: private boolean _sortable;
042:
043: public PropertyModelImpl(BeanModel model, final String name,
044: final PropertyConduit conduit, Messages messages) {
045: _model = model;
046: _name = name;
047: _conduit = conduit;
048:
049: _id = TapestryInternalUtils
050: .extractIdFromPropertyExpression(name);
051: _order = TapestryInternalUtils.defaultOrder(conduit);
052:
053: _label = TapestryInternalUtils
054: .defaultLabel(_id, messages, name);
055:
056: // Primitive types need to be converted to wrapper types before checking to see
057: // if they are sortable.
058:
059: Class wrapperType = ClassFabUtils
060: .getWrapperType(getPropertyType());
061:
062: _sortable = Comparable.class.isAssignableFrom(wrapperType);
063: }
064:
065: public String getId() {
066: return _id;
067: }
068:
069: public Class getPropertyType() {
070: return _conduit == null ? Object.class : _conduit
071: .getPropertyType();
072: }
073:
074: public PropertyConduit getConduit() {
075: return _conduit;
076: }
077:
078: public PropertyModel label(String label) {
079: notBlank(label, "label");
080:
081: _label = label;
082:
083: return this ;
084: }
085:
086: public String getLabel() {
087: return _label;
088: }
089:
090: public String getPropertyName() {
091: return _name;
092: }
093:
094: public int getOrder() {
095: return _order;
096: }
097:
098: public PropertyModel order(int order) {
099: _order = order;
100:
101: return this ;
102: }
103:
104: public BeanModel model() {
105: return _model;
106: }
107:
108: public PropertyModel dataType(String dataType) {
109: _dataType = dataType;
110:
111: return this ;
112: }
113:
114: public String getDataType() {
115: return _dataType;
116: }
117:
118: public boolean isSortable() {
119: return _sortable;
120: }
121:
122: public PropertyModel sortable(boolean sortable) {
123: _sortable = sortable;
124:
125: return this;
126: }
127: }
|