Search in sources :

Example 11 with Entity

use of com.codename1.rad.models.Entity in project CodeRAD by shannah.

the class DefaultEntityListCellRenderer method getListCellRendererComponent.

@Override
public EntityView getListCellRendererComponent(EntityListView list, Entity value, int index, boolean isSelected, boolean isFocused) {
    ListNode listNode = (ListNode) list.getViewNode();
    MultiButtonEntityView out = new MultiButtonEntityView(value, listNode.getRowTemplate());
    ActionNode node = listNode.getAction(ActionCategories.LIST_SELECT_ACTION);
    if (node != null) {
        out.setAction(node);
    }
    return makeSwipeable(value, listNode.getRowTemplate(), out);
}
Also used : ActionNode(com.codename1.rad.nodes.ActionNode) MultiButtonEntityView(com.codename1.rad.ui.entityviews.MultiButtonEntityView) ListNode(com.codename1.rad.nodes.ListNode)

Example 12 with Entity

use of com.codename1.rad.models.Entity in project CodeRAD by shannah.

the class DefaultPropertyViewFactory method createPropertyView.

@Override
public PropertyView createPropertyView(Entity entity, FieldNode field) {
    PropertyViewFactory typeFactory = registry.get(field.getWidgetType(entity.getEntity().getEntityType()));
    if (typeFactory == null) {
        throw new IllegalArgumentException("Type " + field.getWidgetType() + " not supported");
    }
    PropertyView out = typeFactory.createPropertyView(entity, field);
    PropertyViewDecoratorAttribute decoratorAtt = (PropertyViewDecoratorAttribute) field.findAttribute(PropertyViewDecoratorAttribute.class);
    if (decoratorAtt != null) {
        out = decoratorAtt.getValue().decorate(out);
    }
    NodeList decorators = field.getChildNodes(PropertyViewDecoratorNode.class);
    if (decorators != null) {
        for (Node n : decorators) {
            out = ((PropertyViewDecoratorNode) n).getValue().decorate(out);
        }
    }
    return out;
}
Also used : PropertyViewDecoratorAttribute(com.codename1.rad.attributes.PropertyViewDecoratorAttribute) PropertyViewFactoryNode(com.codename1.rad.nodes.PropertyViewFactoryNode) Node(com.codename1.rad.nodes.Node) PropertyViewDecoratorNode(com.codename1.rad.nodes.PropertyViewDecoratorNode) FieldNode(com.codename1.rad.nodes.FieldNode) OptionsNode(com.codename1.rad.nodes.OptionsNode) PropertyViewDecoratorNode(com.codename1.rad.nodes.PropertyViewDecoratorNode) LabelPropertyView(com.codename1.rad.propertyviews.LabelPropertyView) TextFieldPropertyView(com.codename1.rad.propertyviews.TextFieldPropertyView) TablePropertyView(com.codename1.rad.propertyviews.TablePropertyView) ButtonListPropertyView(com.codename1.rad.propertyviews.ButtonListPropertyView) CheckBoxPropertyView(com.codename1.rad.propertyviews.CheckBoxPropertyView) ComboBoxPropertyView(com.codename1.rad.propertyviews.ComboBoxPropertyView) SwitchPropertyView(com.codename1.rad.propertyviews.SwitchPropertyView) TextAreaPropertyView(com.codename1.rad.propertyviews.TextAreaPropertyView)

Example 13 with Entity

use of com.codename1.rad.models.Entity in project CodeRAD by shannah.

the class EntityEditor method build.

private void build() {
    if (built) {
        return;
    }
    built = true;
    removeAll();
    buildTopActionsBar(rootNode, this, entity);
    if (getRootView() != null) {
        setLayout(new BorderLayout());
        buildView();
    } else if (getRootList() != null) {
        setLayout(new BorderLayout());
        buildList();
    } else {
        setLayout(BoxLayout.y());
        buildSections();
    }
    buildBottomActionsBar(rootNode, this, entity);
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout)

Example 14 with Entity

use of com.codename1.rad.models.Entity in project CodeRAD by shannah.

the class EntityEditor method buildList.

private void buildList() {
    if (entity instanceof EntityList) {
        EntityListView listView = new EntityListView((EntityList) entity, getRootList());
        add(BorderLayout.CENTER, listView);
    }
}
Also used : EntityListView(com.codename1.rad.ui.entityviews.EntityListView) EntityList(com.codename1.rad.models.EntityList)

Example 15 with Entity

use of com.codename1.rad.models.Entity in project CodeRAD by shannah.

the class ResultParserTest method simpleJSONTest.

private void simpleJSONTest() throws Exception {
    EntityType personType = new EntityTypeBuilder().string(Person.name).string(Person.email).Date(Person.birthDate).build();
    ResultParser parser = new ResultParser(personType).property("name", Person.name).property("email", Person.email).property("dob", Person.birthDate, dateStr -> {
        if (!(dateStr instanceof String)) {
            return null;
        }
        String str = (String) dateStr;
        if (str.isEmpty()) {
            return null;
        }
        SimpleDateFormat fmt = new SimpleDateFormat("MMM d, yyyy");
        try {
            return fmt.parse(str);
        } catch (ParseException ex) {
            Log.e(ex);
            return null;
        }
    });
    String json = "{\"name\":\"Paul\", \"email\":\"paul@example.com\", \"dob\" : \"December 27, 1978\"}";
    Entity person = parser.parseRow(Result.fromContent(json, Result.JSON), personType.newInstance());
    assertEqual("Paul", person.getEntity().getText(Person.name));
    assertEqual("paul@example.com", person.getEntity().getText(Person.email));
}
Also used : Entity(com.codename1.rad.models.Entity) ResultParser(com.codename1.rad.io.ResultParser) ParseException(com.codename1.l10n.ParseException) SimpleDateFormat(com.codename1.l10n.SimpleDateFormat)

Aggregations

Entity (com.codename1.rad.models.Entity)38 Property (com.codename1.rad.models.Property)15 EntityList (com.codename1.rad.models.EntityList)13 Container (com.codename1.ui.Container)12 BorderLayout (com.codename1.ui.layouts.BorderLayout)11 ActionNode (com.codename1.rad.nodes.ActionNode)10 FieldNode (com.codename1.rad.nodes.FieldNode)10 Form (com.codename1.ui.Form)8 ViewNode (com.codename1.rad.nodes.ViewNode)7 GridLayout (com.codename1.ui.layouts.GridLayout)7 SimpleDateFormat (com.codename1.l10n.SimpleDateFormat)6 ResultParser (com.codename1.rad.io.ResultParser)6 Component (com.codename1.ui.Component)6 Element (com.codename1.xml.Element)6 BadgeUIID (com.codename1.rad.attributes.BadgeUIID)5 Thing (com.codename1.rad.schemas.Thing)5 Button (com.codename1.ui.Button)5 BoxLayout (com.codename1.ui.layouts.BoxLayout)5 Map (java.util.Map)5 Log (com.codename1.io.Log)4