001 package org.trails.component;
002
003 import org.apache.commons.logging.Log;
004 import org.apache.commons.logging.LogFactory;
005 import org.apache.tapestry.annotations.ComponentClass;
006 import org.apache.tapestry.annotations.InjectObject;
007 import org.apache.tapestry.form.IPropertySelectionModel;
008 import org.trails.descriptor.DescriptorService;
009 import org.trails.descriptor.IClassDescriptor;
010 import org.trails.persistence.PersistenceService;
011
012 /**
013 * This guy interacts with persistence service to produce a Select
014 * containing all the elements of the PropertyDescriptor's type.
015 *
016 * @author Chris Nelson
017 */
018 @ComponentClass(allowBody = false, allowInformalParameters = true)
019 public abstract class AssociationSelect extends AbstractPropertySelection
020 {
021 private static final Log LOG = LogFactory.getLog(AssociationSelect.class);
022
023 @InjectObject("service:trails.core.PersistenceService")
024 public abstract PersistenceService getPersistenceService();
025
026 @InjectObject("service:trails.core.DescriptorService")
027 public abstract DescriptorService getDescriptorService();
028
029 public IClassDescriptor getClassDescriptor()
030 {
031 return getDescriptorService().getClassDescriptor(getPropertyDescriptor().getPropertyType());
032 }
033
034 @Override
035 public IPropertySelectionModel buildSelectionModel()
036 {
037 if (LOG.isDebugEnabled())
038 {
039 LOG.debug("Building propertySelectionModel for " + getClassDescriptor().getDisplayName());
040 }
041
042 IdentifierSelectionModel selectionModel;
043 if (getInstances() != null)
044 {
045 selectionModel = new IdentifierSelectionModel(getInstances(),
046 getClassDescriptor().getIdentifierDescriptor().getName(),
047 isAllowNone());
048 } else
049 {
050 selectionModel = new IdentifierSelectionModel(getPersistenceService().getAllInstances(getClassDescriptor().getType()),
051 getClassDescriptor().getIdentifierDescriptor().getName(),
052 isAllowNone());
053 }
054 selectionModel.setNoneLabel(getNoneLabel());
055 return selectionModel;
056 }
057 }