Search in sources :

Example 11 with PropertyModel

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;
}
Also used : PropertyModel(org.apache.tapestry5.beanmodel.PropertyModel)

Example 12 with PropertyModel

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;
}
Also used : PropertyModel(org.apache.tapestry5.beanmodel.PropertyModel)

Example 13 with PropertyModel

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;
}
Also used : PropertyModel(org.apache.tapestry5.beanmodel.PropertyModel)

Example 14 with PropertyModel

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);
    }
}
Also used : Messages(org.apache.tapestry5.commons.Messages) BeanBlockSource(org.apache.tapestry5.services.BeanBlockSource) PropertyModel(org.apache.tapestry5.beanmodel.PropertyModel) PropertyOverrides(org.apache.tapestry5.PropertyOverrides) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) ComponentResources(org.apache.tapestry5.ComponentResources) Location(org.apache.tapestry5.commons.Location) Test(org.testng.annotations.Test)

Example 15 with PropertyModel

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();
}
Also used : Messages(org.apache.tapestry5.commons.Messages) BeanModel(org.apache.tapestry5.beanmodel.BeanModel) PropertyModel(org.apache.tapestry5.beanmodel.PropertyModel) Test(org.testng.annotations.Test)

Aggregations

PropertyModel (org.apache.tapestry5.beanmodel.PropertyModel)29 Test (org.testng.annotations.Test)23 BeanModel (org.apache.tapestry5.beanmodel.BeanModel)21 Messages (org.apache.tapestry5.commons.Messages)19 PropertyConduit (org.apache.tapestry5.beanmodel.PropertyConduit)9 BeforeClass (org.testng.annotations.BeforeClass)4 ComponentResources (org.apache.tapestry5.ComponentResources)2 Location (org.apache.tapestry5.commons.Location)2 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)2 Annotation (java.lang.annotation.Annotation)1 PropertyOverrides (org.apache.tapestry5.PropertyOverrides)1 SortConstraint (org.apache.tapestry5.grid.SortConstraint)1 BeanValidationContext (org.apache.tapestry5.internal.BeanValidationContext)1 BeanBlockSource (org.apache.tapestry5.services.BeanBlockSource)1 PropertyEditContext (org.apache.tapestry5.services.PropertyEditContext)1