View Javadoc

1   package org.starobjects.wicket.ui.components.entity;
2   
3   import org.apache.wicket.Component;
4   import org.apache.wicket.model.IModel;
5   import org.nakedobjects.metamodel.adapter.NakedObject;
6   import org.nakedobjects.metamodel.facets.object.value.ValueFacet;
7   import org.nakedobjects.metamodel.spec.NakedObjectSpecification;
8   import org.starobjects.wicket.model.models.EntityModel;
9   import org.starobjects.wicket.ui.ComponentFactoryAbstract;
10  import org.starobjects.wicket.ui.ComponentType;
11  
12  /**
13   * Convenience adapter for a number of {@link ComponentFactoryAbstract component factory}s that
14   * where the created {@link Component} are backed by an {@link EntityModel}.
15   */
16  public abstract class EntityComponentFactoryAbstract extends ComponentFactoryAbstract {
17  
18  	private static final long serialVersionUID = 1L;
19  
20  	public EntityComponentFactoryAbstract(ComponentType componentType) {
21  		super(componentType);
22  	}
23  
24  	public EntityComponentFactoryAbstract(ComponentType componentType, String name) {
25  		super(componentType, name);
26  	}
27  
28  	@Override
29  	protected ApplicationAdvice appliesTo(IModel<?> model) {
30  		if (!(model instanceof EntityModel)) {
31  			return ApplicationAdvice.DOES_NOT_APPLY;
32  		}
33  		EntityModel entityModel = (EntityModel) model;
34  		NakedObject adapter = entityModel.getObject();
35  		if (adapter == null) {
36  			// is ok;
37  		}
38  		NakedObjectSpecification specification = entityModel.getTypeOfSpecification();
39  		final boolean isObject = specification.isObject();
40  		final boolean isValue = specification.containsFacet(ValueFacet.class);
41  		return appliesIf(isObject && !isValue);
42  	}
43  
44  }