use of org.apache.tapestry5.beanmodel.PropertyModel in project tapestry-5 by apache.
the class BeanModelImpl method exclude.
public BeanModel<T> exclude(String... propertyNames) {
for (String propertyName : propertyNames) {
PropertyModel model = properties.get(propertyName);
if (model == null)
continue;
// De-referencing from the model is needed because the name provided may not be a
// case-exact match, so we get the normalized or canonical name from the model because
// that's the one in propertyNames.
this.propertyNames.remove(model.getPropertyName());
properties.remove(propertyName);
}
return this;
}
use of org.apache.tapestry5.beanmodel.PropertyModel in project tapestry-5 by apache.
the class BeanModelImpl method include.
public BeanModel<T> include(String... propertyNames) {
List<String> reorderedPropertyNames = CollectionFactory.newList();
Map<String, PropertyModel> reduced = CollectionFactory.newCaseInsensitiveMap();
for (String name : propertyNames) {
PropertyModel model = get(name);
String canonical = model.getPropertyName();
reorderedPropertyNames.add(canonical);
reduced.put(canonical, model);
}
this.propertyNames.clear();
this.propertyNames.addAll(reorderedPropertyNames);
properties.clear();
properties.putAll(reduced);
return this;
}
use of org.apache.tapestry5.beanmodel.PropertyModel in project tapestry-5 by apache.
the class BeanModelImpl method reorder.
public BeanModel<T> reorder(String... propertyNames) {
List<String> remainingPropertyNames = CollectionFactory.newList(this.propertyNames);
List<String> reorderedPropertyNames = CollectionFactory.newList();
for (String name : propertyNames) {
PropertyModel model = get(name);
// Get the canonical form (which may differ from name in terms of case)
String canonical = model.getPropertyName();
reorderedPropertyNames.add(canonical);
remainingPropertyNames.remove(canonical);
}
this.propertyNames.clear();
this.propertyNames.addAll(reorderedPropertyNames);
// Any unspecified names are ordered to the end. Don't want them? Remove them instead.
this.propertyNames.addAll(remainingPropertyNames);
return this;
}
use of org.apache.tapestry5.beanmodel.PropertyModel in project tapestry-5 by apache.
the class PropertyEditorTest method no_editor_block_available.
@Test
public void no_editor_block_available() {
PropertyModel model = mockPropertyModel();
PropertyOverrides overrides = mockPropertyOverrides();
ComponentResources resources = mockComponentResources();
BeanBlockSource source = newMock(BeanBlockSource.class);
RuntimeException exception = new RuntimeException("Simulated failure.");
Messages messages = mockMessages();
Location l = mockLocation();
String propertyId = "foo";
String dataType = "unk";
String propertyName = "fooProp";
Object object = "[OBJECT]";
String formattedMessage = "formatted-message";
expect(model.getId()).andReturn(propertyId);
train_getOverrideBlock(overrides, propertyId, null);
expect(model.getDataType()).andReturn(dataType);
expect(source.getEditBlock(dataType)).andThrow(exception);
expect(model.getPropertyName()).andReturn(propertyName);
train_getLocation(resources, l);
expect(messages.format("core-block-error", propertyName, dataType, object, exception)).andReturn(formattedMessage);
replay();
PropertyEditor pe = new PropertyEditor();
pe.inject(resources, overrides, model, source, messages, object);
try {
pe.beginRender();
unreachable();
} catch (TapestryException ex) {
assertEquals(ex.getMessage(), formattedMessage);
assertSame(ex.getLocation(), l);
}
}
use of org.apache.tapestry5.beanmodel.PropertyModel in project tapestry-5 by apache.
the class AbstractBeanModelSourceImplTest method composite_bean.
@Test
public void composite_bean() {
Messages messages = mockMessages();
stub_contains(messages, false);
train_contains(messages, "simpleage-label", true);
train_get(messages, "simpleage-label", "Years of Age");
replay();
BeanModel model = source.create(CompositeBean.class, true, messages);
// No editor for CompositeBean, so this will be empty.
assertEquals(model.getPropertyNames(), Collections.emptyList());
// There's not editor for string arrays yet, so it won't show up normally.
PropertyModel firstName = model.add("simple.firstName");
assertEquals(firstName.getLabel(), "First Name");
PropertyModel age = model.add("simple.age");
assertEquals(age.getLabel(), "Years of Age");
CompositeBean bean = new CompositeBean();
firstName.getConduit().set(bean, "Fred");
age.getConduit().set(bean, "97");
assertEquals(bean.getSimple().getFirstName(), "Fred");
assertEquals(bean.getSimple().getAge(), 97);
bean.getSimple().setAge(24);
assertEquals(age.getConduit().get(bean), new Integer(24));
verify();
}
Aggregations