001    // Copyright 2007, 2008 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.tapestry5.beaneditor;
016    
017    import org.apache.tapestry5.PropertyConduit;
018    import org.apache.tapestry5.ioc.AnnotationProvider;
019    
020    /**
021     * Part of a {@link org.apache.tapestry5.beaneditor.BeanModel} that defines the attributes of a single property of a
022     * bean.
023     * <p/>
024     * <p/>
025     * A PropertyModel is also an {@link AnnotationProvider}, as long as the {@link org.apache.tapestry5.PropertyConduit} is
026     * non-null.  When there is no property conduit, then {@link org.apache.tapestry5.ioc.AnnotationProvider#getAnnotation(Class)}
027     * will return null.
028     */
029    public interface PropertyModel extends AnnotationProvider
030    {
031        /**
032         * Returns the name of the property (which may, in fact, be a property expression).
033         */
034        String getPropertyName();
035    
036        /**
037         * Returns the id used to access other resources (this is based on the property name, but with any excess
038         * punctuation stripped out).
039         */
040        String getId();
041    
042        /**
043         * Returns a user-presentable label for the property.
044         */
045        String getLabel();
046    
047        /**
048         * Returns the type of the property.
049         */
050        Class getPropertyType();
051    
052        /**
053         * Returns a logical name for the type of UI needed to view or edit the property. This is initially determined from
054         * the property type.
055         */
056        String getDataType();
057    
058        /**
059         * Changes the data type for the property.
060         *
061         * @param dataType
062         * @return the property model, for further changes
063         */
064        PropertyModel dataType(String dataType);
065    
066        /**
067         * Returns an object used to read or update the property. For virtual properties (properties that do not actually
068         * exist on the bean), the conduit may be null.
069         */
070        PropertyConduit getConduit();
071    
072        /**
073         * Changes the label for the property to the provided value.
074         *
075         * @param label new label for property
076         * @return the property model, for further changes
077         */
078        PropertyModel label(String label);
079    
080        /**
081         * Returns the containing model, often used for "fluent" construction of the model.
082         */
083        BeanModel model();
084    
085        /**
086         * Returns true if the property can be used for sorting. By default, this is true only if the property type
087         * implements Comparable.
088         */
089        boolean isSortable();
090    
091        /**
092         * Updates sortable and returns the model for further changes.
093         *
094         * @return the property model, for further changes
095         */
096        PropertyModel sortable(boolean sortable);
097    }