001 package org.tynamo.pages;
002
003 import org.apache.tapestry5.annotations.Component;
004 import org.apache.tapestry5.annotations.Environmental;
005 import org.apache.tapestry5.annotations.Property;
006 import org.apache.tapestry5.ioc.annotations.Inject;
007 import org.apache.tapestry5.services.PropertyOutputContext;
008 import org.tynamo.components.Composition;
009 import org.tynamo.components.Download;
010 import org.tynamo.descriptor.TynamoPropertyDescriptor;
011 import org.tynamo.services.DescriptorService;
012 import org.tynamo.services.TynamoBeanContext;
013
014 import java.util.Collection;
015
016 public class PropertyDisplayBlocks
017 {
018 @Inject
019 private DescriptorService descriptorService;
020
021 @Environmental
022 @Property(write = false)
023 private PropertyOutputContext context;
024
025 @Environmental
026 @Property(write = false)
027 private TynamoBeanContext tynamoBeanContext;
028
029 @Property
030 private Object loopIterator;
031
032 @Property
033 private int loopIndex;
034
035 @Component(parameters = {"collection=context.propertyValue", "clientId=prop:context.propertyId",
036 "collectionDescriptor=propertyDescriptor", "owner=tynamoBeanContext.bean"})
037 private Composition composition;
038
039 @Component(parameters = {"model=tynamoBeanContext.bean", "propertyDescriptor=propertyDescriptor"})
040 private Download download;
041
042 public Object[] getShowPageContext()
043 {
044 return new Object[]{context.getPropertyValue().getClass(), context.getPropertyValue()};
045 }
046
047 public Object[] getLoopShowPageContext()
048 {
049 return new Object[]{loopIterator.getClass(), loopIterator};
050 }
051
052 public boolean isLastElement()
053 {
054 return loopIndex >= ((Collection) context.getPropertyValue()).size() - 1;
055 }
056
057 public TynamoPropertyDescriptor getPropertyDescriptor()
058 {
059 return descriptorService.getClassDescriptor(tynamoBeanContext.getBeanClass())
060 .getPropertyDescriptor(context.getPropertyId());
061 }
062
063 }