Search in sources :

Example 1 with Entity

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

the class ResultParser method parse.

/**
 * Parses a list of Maps or Elements into an EntityList.
 * @param rows The rows to parse.
 * @param out The entity list to append to.
 * @return The resulting entity list (same as input parameter).
 * @throws IOException If parsing failed.
 */
public EntityList parse(List rows, EntityList out) throws IOException {
    for (Object row : rows) {
        Entity rowEntity = null;
        rowEntity = EntityType.createEntityForClass(out.getRowType().getEntityClass());
        if (rowEntity == null) {
            rowEntity = out.getRowType().newInstance();
        }
        Result rowResult;
        if (row instanceof Element) {
            rowResult = Result.fromContent((Element) row);
        } else if (row instanceof Map) {
            rowResult = Result.fromContent((Map) row);
        } else {
            throw new IOException("Row type " + row.getClass() + " not supported.  Expected Map or Element.");
        }
        Entity parsed = parseRow(rowResult, rowEntity);
        if (parsed != null) {
            out.add(parsed);
        }
    }
    return out;
}
Also used : Entity(com.codename1.rad.models.Entity) Element(com.codename1.xml.Element) HashMap(java.util.HashMap) Map(java.util.Map) Result(com.codename1.rad.processing.Result)

Example 2 with Entity

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

the class ButtonListPropertyView method updateSingleSelectionModel.

private void updateSingleSelectionModel() {
    Entity e = getPropertySelector().getLeafEntity();
    Property p = getPropertySelector().getLeafProperty();
    Object val = p.getValue(e.getEntity());
    ListModel model = getComponent().getModel();
    int len = model.getSize();
    int selectedIndex = model.getSelectedIndex();
    if (p.getContentType().isEntity()) {
        // For entities, we'll allow matching on ID.
        Entity currSelection = e.getEntity().getEntity(p);
        String id = currSelection.getEntity().getText(Thing.identifier);
        if (id != null) {
            for (int i = 0; i < len; i++) {
                Object rowVal = model.getItemAt(i);
                if (rowVal instanceof Entity) {
                    String rowId = ((Entity) rowVal).getEntity().getText(Thing.identifier);
                    if (Objects.equals(rowId, id)) {
                        if (i != selectedIndex) {
                            model.setSelectedIndex(i);
                        }
                        break;
                    }
                } else {
                    if (Objects.equals(id, String.valueOf(rowVal))) {
                        if (i != selectedIndex) {
                            model.setSelectedIndex(i);
                        }
                        break;
                    }
                }
            }
        } else {
            for (int i = 0; i < len; i++) {
                if (Objects.equals(e, model.getItemAt(i))) {
                    if (i != selectedIndex) {
                        model.setSelectedIndex(i);
                    }
                    break;
                }
            }
        }
    } else {
        for (int i = 0; i < len; i++) {
            if (Objects.equals(model.getItemAt(i), e.getEntity().get(p))) {
                if (selectedIndex != i) {
                    model.setSelectedIndex(i);
                }
                break;
            }
        }
    }
}
Also used : Entity(com.codename1.rad.models.Entity) MultipleSelectionListModel(com.codename1.ui.list.MultipleSelectionListModel) ListModel(com.codename1.ui.list.ListModel) DefaultListModel(com.codename1.ui.list.DefaultListModel) Property(com.codename1.rad.models.Property)

Example 3 with Entity

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

the class UIBuilder method textArea.

public TextAreaPropertyView textArea(Tag... tags) {
    FieldNode fn = new FieldNode(UI.tags(tags));
    fn.setParent(parentNode);
    return new TextAreaPropertyView(new TextArea(), entity, fn);
}
Also used : TextAreaPropertyView(com.codename1.rad.propertyviews.TextAreaPropertyView) FieldNode(com.codename1.rad.nodes.FieldNode) TextArea(com.codename1.ui.TextArea)

Example 4 with Entity

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

the class FieldEditorFormController method onStartController.

protected void onStartController() {
    super.onStartController();
    Form f = new Form(new BorderLayout());
    f.getToolbar().hideToolbar();
    Container titleBar = new Container(new BorderLayout(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE));
    titleBar.setSafeArea(true);
    titleBar.setUIID("TitleArea");
    if (hasBackCommand()) {
        Button back = new Button();
        FontImage.setIcon(back, FontImage.MATERIAL_ARROW_BACK_IOS, -1);
        titleBar.add(BorderLayout.WEST, back);
        back.addActionListener(evt -> {
            evt.consume();
            ActionSupport.dispatchEvent(new FormController.FormBackEvent(back));
        });
    }
    AppSectionController sectionCtl = getSectionController();
    if (sectionCtl != null) {
        Button done = new Button("Done");
        done.addActionListener(evt -> {
            evt.consume();
            ActionSupport.dispatchEvent(new AppSectionController.ExitSectionEvent(done));
        });
        titleBar.add(BorderLayout.EAST, done);
    }
    Label l = field.getLabel(entity.getEntity().getEntityType());
    if (l != null) {
        titleBar.add(BorderLayout.CENTER, new com.codename1.ui.Label(l.getValue(entity.getEntity()), "Title"));
    }
    f.add(BorderLayout.NORTH, titleBar);
    field.setAttributes(new LabelStyleAttribute(LabelStyle.None), new DescriptionStyleAttribute(DescriptionStyle.SpanLabel));
    UI ui = new UI() {

        {
            form(columns(1), field, editable(true));
        }
    };
    EntityEditor editor = new EntityEditor(entity, ui);
    editor.setScrollableY(true);
    f.add(BorderLayout.CENTER, editor);
    setView(f);
}
Also used : Form(com.codename1.ui.Form) Label(com.codename1.rad.models.Property.Label) Container(com.codename1.ui.Container) LabelStyleAttribute(com.codename1.rad.ui.EntityEditor.LabelStyleAttribute) DescriptionStyleAttribute(com.codename1.rad.ui.EntityEditor.DescriptionStyleAttribute) BorderLayout(com.codename1.ui.layouts.BorderLayout) UI(com.codename1.rad.ui.UI) Button(com.codename1.ui.Button) EntityEditor(com.codename1.rad.ui.EntityEditor)

Example 5 with Entity

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

the class FieldEditor method build.

void build() {
    if (built) {
        return;
    }
    built = true;
    setLayout(BoxLayout.y());
    Property.Label lbl = field.getLabel(entity.getEntity().getEntityType());
    LabelStyle labelStyle = field.getLabelStyle(LabelStyle.Default);
    Property.Description description = field.getDescription(entity.getEntity().getEntityType());
    DescriptionStyle descriptionStyle = field.getDescriptionStyle(DescriptionStyle.HelpButton);
    Container above = new Container(new FlowLayout());
    above.stripMarginAndPadding();
    Container wrap = new Container(new BorderLayout());
    wrap.stripMarginAndPadding();
    if (lbl != null && labelStyle != LabelStyle.None) {
        above.add(new SpanLabel(lbl.getValue()));
        if (description != null) {
            switch(descriptionStyle) {
                case HelpButton:
                    above.add(new HelpButton(description.getValue()));
                    break;
                case SpanLabel:
                    SpanLabel descriptionSpanLabel = new SpanLabel(description.getValue(), "FieldDescriptionText");
                    above.add(descriptionSpanLabel);
                    break;
            }
        }
    } else {
        if (description != null) {
            Component descCmp = null;
            switch(descriptionStyle) {
                case HelpButton:
                    descCmp = new HelpButton(description.getValue());
                    wrap.add(BorderLayout.EAST, descCmp);
                    break;
                case SpanLabel:
                    descCmp = new SpanLabel(description.getValue(), "FieldDescriptionText");
                    above.add(descCmp);
                    break;
            }
            if (descCmp != null) {
            }
        }
    }
    WidgetType widgetType = field.getWidgetType(entity.getEntity().getEntityType());
    if (widgetType != null) {
        component = field.getViewFactory().createPropertyView(entity, field);
        wrap.add(BorderLayout.CENTER, component);
    } else {
        throw new IllegalStateException("Field " + field + " has not widget type");
    }
    Container topBar = new Container(BoxLayout.y());
    NodeUtilFunctions.buildTopActionsBar(field, topBar, entity);
    if (above.getComponentCount() > 0) {
        if (topBar.getComponentCount() > 0) {
            above = BorderLayout.centerEastWest(above, topBar, null);
        }
        add(above);
    } else {
        if (topBar.getComponentCount() > 0) {
            add(topBar);
        }
    }
    add(wrap);
    NodeUtilFunctions.buildBottomActionsBar(field, this, entity);
}
Also used : DescriptionStyle(com.codename1.rad.ui.EntityEditor.DescriptionStyle) FlowLayout(com.codename1.ui.layouts.FlowLayout) LabelStyle(com.codename1.rad.ui.EntityEditor.LabelStyle) SpanLabel(com.codename1.components.SpanLabel) Container(com.codename1.ui.Container) BorderLayout(com.codename1.ui.layouts.BorderLayout) HelpButton(ca.weblite.shared.components.HelpButton) Component(com.codename1.ui.Component) WidgetType(com.codename1.rad.attributes.WidgetType) Property(com.codename1.rad.models.Property)

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