001// Licensed under the Apache License, Version 2.0 (the "License");
002// you may not use this file except in compliance with the License.
003// You may obtain a copy of the License at
004//
005//     http://www.apache.org/licenses/LICENSE-2.0
006//
007// Unless required by applicable law or agreed to in writing, software
008// distributed under the License is distributed on an "AS IS" BASIS,
009// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
010// See the License for the specific language governing permissions and
011// limitations under the License.
012
013package org.apache.tapestry5.beaneditor;
014
015import org.apache.tapestry5.PropertyConduit;
016import org.apache.tapestry5.ioc.AnnotationProvider;
017
018/**
019 * Part of a {@link org.apache.tapestry5.beaneditor.BeanModel} that defines the attributes of a single property of a
020 * bean.
021 *
022 *
023 * A PropertyModel is also an {@link AnnotationProvider}, as long as the {@link org.apache.tapestry5.PropertyConduit} is
024 * non-null.  When there is no property conduit, then {@link org.apache.tapestry5.ioc.AnnotationProvider#getAnnotation(Class)}
025 * will return null.
026 */
027public interface PropertyModel extends AnnotationProvider
028{
029    /**
030     * Returns the name of the property (which may, in fact, be a property expression).
031     */
032    String getPropertyName();
033
034    /**
035     * Returns the id used to access other resources (this is based on the property name, but with any excess
036     * punctuation stripped out).
037     */
038    String getId();
039
040    /**
041     * Returns a user-presentable label for the property.
042     */
043    String getLabel();
044
045    /**
046     * Returns the type of the property.
047     */
048    Class getPropertyType();
049
050    /**
051     * Returns a logical name for the type of UI needed to view or edit the property. This is initially determined from
052     * the property type.
053     */
054    String getDataType();
055
056    /**
057     * Changes the data type for the property.
058     *
059     * @param dataType
060     * @return the property model, for further changes
061     */
062    PropertyModel dataType(String dataType);
063
064    /**
065     * Returns an object used to read or update the property. For virtual properties (properties that do not actually
066     * exist on the bean), the conduit may be null.
067     */
068    PropertyConduit getConduit();
069
070    /**
071     * Changes the label for the property to the provided value.
072     *
073     * @param label new label for property
074     * @return the property model, for further changes
075     */
076    PropertyModel label(String label);
077
078    /**
079     * Returns the containing model, often used for "fluent" construction of the model.
080     */
081    BeanModel model();
082
083    /**
084     * Returns true if the property can be used for sorting. By default, this is true only if the property type
085     * implements Comparable.
086     */
087    boolean isSortable();
088
089    /**
090     * Updates sortable and returns the model for further changes.
091     *
092     * @return the property model, for further changes
093     */
094    PropertyModel sortable(boolean sortable);
095}