Search in sources :

Example 1 with OptionGroupModelImpl

use of org.apache.tapestry5.internal.OptionGroupModelImpl in project tapestry-5 by apache.

the class SelectTest method option_groups.

@Test
public void option_groups() throws Exception {
    ValidationTracker tracker = mockValidationTracker();
    OptionGroupModel husbands = new OptionGroupModelImpl("Husbands", false, TapestryInternalUtils.toOptionModels("Fred,Barney"));
    OptionGroupModel wives = new OptionGroupModelImpl("Wives", true, TapestryInternalUtils.toOptionModels("Wilma,Betty"));
    List<OptionGroupModel> groupModels = CollectionFactory.newList(husbands, wives);
    Select select = new Select();
    train_getInput(tracker, select, null);
    replay();
    select.setModel(new SelectModelImpl(groupModels, null));
    select.setValueEncoder(new StringValueEncoder());
    select.setValue("Fred");
    select.setValidationTracker(tracker);
    MarkupWriter writer = new MarkupWriterImpl(new XMLMarkupModel());
    writer.element("select");
    select.options(writer);
    writer.end();
    assertEquals(writer.toString(), read("option_groups.txt"));
    verify();
}
Also used : MarkupWriterImpl(org.apache.tapestry5.internal.services.MarkupWriterImpl) SelectModelImpl(org.apache.tapestry5.internal.SelectModelImpl) OptionGroupModelImpl(org.apache.tapestry5.internal.OptionGroupModelImpl) StringValueEncoder(org.apache.tapestry5.internal.services.StringValueEncoder) XMLMarkupModel(org.apache.tapestry5.dom.XMLMarkupModel) Test(org.testng.annotations.Test)

Example 2 with OptionGroupModelImpl

use of org.apache.tapestry5.internal.OptionGroupModelImpl in project tapestry-5 by apache.

the class OptionGroupModelImplTest method strings_contructor_builds_map.

@Test
public void strings_contructor_builds_map() {
    List<OptionModel> options = Collections.emptyList();
    OptionGroupModel group = new OptionGroupModelImpl("Label", true, options, "fred", "flintstone", "barney", "rubble");
    Map<String, String> attributes = group.getAttributes();
    assertEquals(attributes.size(), 2);
    assertEquals(attributes.get("fred"), "flintstone");
    assertEquals(attributes.get("barney"), "rubble");
}
Also used : OptionGroupModel(org.apache.tapestry5.OptionGroupModel) OptionModel(org.apache.tapestry5.OptionModel) Test(org.testng.annotations.Test)

Example 3 with OptionGroupModelImpl

use of org.apache.tapestry5.internal.OptionGroupModelImpl in project tapestry-5 by apache.

the class OptionGroupModelImplTest method map_contructor_retains_map.

@Test
public void map_contructor_retains_map() {
    List<OptionModel> options = Collections.emptyList();
    Map<String, String> attributes = Collections.emptyMap();
    OptionGroupModel group = new OptionGroupModelImpl("Label", true, options, attributes);
    assertSame(group.getAttributes(), attributes);
}
Also used : OptionGroupModel(org.apache.tapestry5.OptionGroupModel) OptionModel(org.apache.tapestry5.OptionModel) Test(org.testng.annotations.Test)

Example 4 with OptionGroupModelImpl

use of org.apache.tapestry5.internal.OptionGroupModelImpl in project tapestry-5 by apache.

the class OptionGroupModelImplTest method basics.

@Test
public void basics() {
    List<OptionModel> options = Collections.emptyList();
    OptionGroupModel group = new OptionGroupModelImpl("Label", true, options);
    assertEquals(group.toString(), "OptionGroupModel[Label]");
    assertTrue(group.isDisabled());
    assertNull(group.getAttributes());
    assertSame(group.getOptions(), options);
}
Also used : OptionGroupModel(org.apache.tapestry5.OptionGroupModel) OptionModel(org.apache.tapestry5.OptionModel) Test(org.testng.annotations.Test)

Example 5 with OptionGroupModelImpl

use of org.apache.tapestry5.internal.OptionGroupModelImpl in project tapestry-5 by apache.

the class OptionGroupForm method getModel.

public SelectModel getModel() {
    return new AbstractSelectModel() {

        private List<OptionGroupModel> groupModels = null;

        public List<OptionModel> getOptions() {
            return null;
        }

        public List<OptionGroupModel> getOptionGroups() {
            if (groupModels == null) {
                computeModel();
            }
            return groupModels;
        }

        private void computeModel() {
            groupModels = new ArrayList<OptionGroupModel>();
            for (Entity entity : entityList) {
                List<OptionModel> options = new ArrayList<OptionModel>();
                options.add(new OptionModelImpl(entity.getLabel(), entity));
                OptionGroupModel groupModel = new OptionGroupModelImpl(entity.getLabel(), false, options);
                groupModels.add(groupModel);
            }
        }
    };
}
Also used : Entity(org.apache.tapestry5.integration.app1.data.Entity) OptionGroupModel(org.apache.tapestry5.OptionGroupModel) OptionModelImpl(org.apache.tapestry5.internal.OptionModelImpl) AbstractSelectModel(org.apache.tapestry5.util.AbstractSelectModel) OptionGroupModelImpl(org.apache.tapestry5.internal.OptionGroupModelImpl) OptionModel(org.apache.tapestry5.OptionModel) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Test (org.testng.annotations.Test)6 OptionGroupModel (org.apache.tapestry5.OptionGroupModel)4 OptionModel (org.apache.tapestry5.OptionModel)4 OptionGroupModelImpl (org.apache.tapestry5.internal.OptionGroupModelImpl)4 XMLMarkupModel (org.apache.tapestry5.dom.XMLMarkupModel)3 SelectModelImpl (org.apache.tapestry5.internal.SelectModelImpl)3 MarkupWriterImpl (org.apache.tapestry5.internal.services.MarkupWriterImpl)3 StringValueEncoder (org.apache.tapestry5.internal.services.StringValueEncoder)3 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Entity (org.apache.tapestry5.integration.app1.data.Entity)1 OptionModelImpl (org.apache.tapestry5.internal.OptionModelImpl)1 AbstractSelectModel (org.apache.tapestry5.util.AbstractSelectModel)1