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;
}
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;
}
}
}
}
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);
}
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);
}
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);
}
Aggregations