| 1 |
|
package org.trails.component; |
| 2 |
|
|
| 3 |
|
import org.apache.commons.logging.Log; |
| 4 |
|
import org.apache.commons.logging.LogFactory; |
| 5 |
|
import org.apache.tapestry.annotations.ComponentClass; |
| 6 |
|
import org.apache.tapestry.annotations.InjectObject; |
| 7 |
|
import org.apache.tapestry.form.IPropertySelectionModel; |
| 8 |
|
import org.trails.descriptor.DescriptorService; |
| 9 |
|
import org.trails.descriptor.IClassDescriptor; |
| 10 |
|
import org.trails.persistence.PersistenceService; |
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
@ComponentClass(allowBody = false, allowInformalParameters = true) |
| 19 |
3 |
public abstract class AssociationSelect extends AbstractPropertySelection |
| 20 |
|
{ |
| 21 |
1 |
private static final Log LOG = LogFactory.getLog(AssociationSelect.class); |
| 22 |
|
|
| 23 |
|
@InjectObject("spring:persistenceService") |
| 24 |
|
public abstract PersistenceService getPersistenceService(); |
| 25 |
|
|
| 26 |
|
@InjectObject("spring:descriptorService") |
| 27 |
|
public abstract DescriptorService getDescriptorService(); |
| 28 |
|
|
| 29 |
|
public IClassDescriptor getClassDescriptor() |
| 30 |
|
{ |
| 31 |
7 |
return getDescriptorService().getClassDescriptor(getPropertyDescriptor().getPropertyType()); |
| 32 |
|
} |
| 33 |
|
|
| 34 |
|
@Override |
| 35 |
|
public IPropertySelectionModel buildSelectionModel() |
| 36 |
|
{ |
| 37 |
3 |
if (LOG.isDebugEnabled()) |
| 38 |
|
{ |
| 39 |
0 |
LOG.debug("Building propertySelectionModel for " + getClassDescriptor().getDisplayName()); |
| 40 |
|
} |
| 41 |
|
|
| 42 |
|
IdentifierSelectionModel selectionModel; |
| 43 |
3 |
if (getInstances() != null) |
| 44 |
|
{ |
| 45 |
0 |
selectionModel = new IdentifierSelectionModel(getInstances(), |
| 46 |
0 |
getClassDescriptor().getIdentifierDescriptor().getName(), |
| 47 |
0 |
isAllowNone()); |
| 48 |
|
} else |
| 49 |
|
{ |
| 50 |
6 |
selectionModel = new IdentifierSelectionModel(getPersistenceService().getAllInstances(getClassDescriptor().getType()), |
| 51 |
3 |
getClassDescriptor().getIdentifierDescriptor().getName(), |
| 52 |
3 |
isAllowNone()); |
| 53 |
|
} |
| 54 |
3 |
selectionModel.setNoneLabel(getNoneLabel()); |
| 55 |
3 |
return selectionModel; |
| 56 |
|
} |
| 57 |
|
} |