001    /*
002     * Copyright 2004 Chris Nelson
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
007     * Unless required by applicable law or agreed to in writing,
008     * software 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 limitations under the License.
011     */
012    package org.trails.component;
013    
014    import org.apache.tapestry.BaseComponent;
015    import org.apache.tapestry.annotations.Bean;
016    import org.apache.tapestry.annotations.ComponentClass;
017    import org.apache.tapestry.annotations.Lifecycle;
018    import org.apache.tapestry.annotations.Parameter;
019    import org.apache.tapestry.valid.IValidator;
020    import org.apache.tapestry.valid.NumberValidator;
021    import org.trails.descriptor.IIdentifierDescriptor;
022    import org.trails.descriptor.IPropertyDescriptor;
023    import org.trails.page.ModelPage;
024    
025    /**
026     * Displays an id property
027     */
028    @ComponentClass(allowBody = true, allowInformalParameters = true)
029    public abstract class Identifier extends BaseComponent
030    {
031            @Parameter(defaultValue = "container.model")
032            public abstract Object getModel();
033    
034            @Parameter(defaultValue = "container.modelNew")
035            public abstract boolean isModelNew();
036    
037            @Parameter(required = true, cache = true)
038            public abstract IPropertyDescriptor getDescriptor();
039    
040            @Parameter(required = false, defaultValue = "page.validatorTranslatorService.getValidator(descriptor)")
041            public abstract IValidator getValidator();
042    
043            @Bean(lifecycle = Lifecycle.PAGE)
044            public abstract NumberValidator getNumberValidator();
045    
046            public boolean isEditable()
047            {
048                    return !((IIdentifierDescriptor) getDescriptor()).isGenerated() && ((ModelPage) getPage()).isModelNew();
049            }
050    }