Search in sources :

Example 1 with Property

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

the class ResultParser method createGetter.

/**
 * Creates a getter for a given property.
 * @param property
 * @return
 */
private static Getter createGetter(Property property) {
    Getter getter = null;
    ContentType propType = property.getContentType();
    if (propType == ContentType.BooleanType) {
        getter = (rs, sel) -> {
            return rs.getAsBoolean(sel);
        };
    } else if (propType == ContentType.DateType) {
        getter = (rs, sel) -> {
            return rs.getAsString(sel);
        };
    } else if (propType == ContentType.DoubleType || propType == ContentType.FloatType) {
        getter = (rs, sel) -> {
            return rs.getAsDouble(sel);
        };
    } else if (propType == ContentType.IntegerType) {
        getter = (rs, sel) -> {
            return rs.getAsInteger(sel);
        };
    } else if (propType == ContentType.LongType) {
        getter = (rs, sel) -> {
            return rs.getAsLong(sel);
        };
    } else if (propType == ContentType.Text) {
        getter = (rs, sel) -> {
            return rs.getAsString(sel);
        };
    } else if (propType.isEntityList()) {
        getter = (rs, sel) -> {
            try {
                return rs.getAsArray(sel);
            } catch (Throwable t) {
                Log.p("Failed to get selector " + sel + " from result " + rs);
                Log.e(t);
                return null;
            }
        };
    } else if (propType.isEntity()) {
        getter = (rs, sel) -> {
            return rs.get(sel);
        };
    }
    return getter;
}
Also used : EntityType(com.codename1.rad.models.EntityType) SimpleDateFormat(com.codename1.l10n.SimpleDateFormat) CharArrayReader(com.codename1.io.CharArrayReader) Date(java.util.Date) EntityList(com.codename1.rad.models.EntityList) HashMap(java.util.HashMap) Element(com.codename1.xml.Element) JSONParser(com.codename1.io.JSONParser) Log(com.codename1.io.Log) ParseException(com.codename1.l10n.ParseException) ArrayList(java.util.ArrayList) List(java.util.List) java.io(java.io) Map(java.util.Map) EntityProperty(com.codename1.rad.models.EntityProperty) Result(com.codename1.rad.processing.Result) Entity(com.codename1.rad.models.Entity) EntityFactory(com.codename1.rad.models.EntityFactory) Tag(com.codename1.rad.models.Tag) ContentType(com.codename1.rad.models.ContentType) Property(com.codename1.rad.models.Property) ContentType(com.codename1.rad.models.ContentType)

Example 2 with Property

use of com.codename1.rad.models.Property 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 Property

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

the class TextAreaPropertyView method commit.

public void commit() {
    String text = getComponent().getText();
    TextFormatterAttribute formatter = (TextFormatterAttribute) getField().findAttribute(TextFormatterAttribute.class);
    if (formatter != null) {
        if (!formatter.getValue().supportsParse()) {
            throw new RuntimeException("Formatter does not support parse committing text '" + text + "'.");
        }
        try {
            text = formatter.getValue().parse(text);
        } catch (ParseException ex) {
            throw new RuntimeException("Failed to parse text '" + text + "' for property.");
        }
    }
    getProperty().setValue(getEntity().getEntity(), ContentType.convert(ContentType.Text, text, getProperty().getContentType()));
}
Also used : TextFormatterAttribute(com.codename1.rad.models.TextFormatterAttribute) ParseException(com.codename1.l10n.ParseException)

Example 4 with Property

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

the class MultiButtonEntityView method update.

@Override
public void update() {
    EntityType type = getEntity().getEntity().getEntityType();
    boolean changed = false;
    if (line1PropDirty) {
        line1PropDirty = false;
        line1Prop = line1Prop == null ? type.findProperty(line1, Thing.name) : line1Prop;
        if (line1Prop != null) {
            String text = type.getText(line1Prop, entity.getEntity());
            if (!Objects.equals(text, getTextLine1())) {
                setTextLine1(text);
                changed = true;
            }
        }
    }
    if (line2PropDirty) {
        line2PropDirty = false;
        line2Prop = line2Prop == null ? type.findProperty(line2, Thing.description) : line2Prop;
        if (line2Prop != null) {
            String text = type.getText(line2Prop, entity.getEntity());
            if (!Objects.equals(text, getTextLine2())) {
                setTextLine2(text);
                changed = true;
            }
        }
    }
    if (line3PropDirty) {
        line3PropDirty = false;
        line3Prop = line3Prop == null ? type.findProperty(line3) : line3Prop;
        if (line3Prop != null) {
            String text = type.getText(line3Prop, entity.getEntity());
            if (!Objects.equals(text, getTextLine3())) {
                setTextLine3(text);
                changed = true;
            }
        }
    }
    if (line4PropDirty) {
        line4PropDirty = false;
        line4Prop = line4Prop == null ? type.findProperty(line4) : line4Prop;
        if (line4Prop != null) {
            String text = type.getText(line4Prop, entity.getEntity());
            if (!Objects.equals(text, getTextLine4())) {
                setTextLine4(text);
                changed = true;
            }
        }
    }
    if (iconDirty) {
        iconDirty = false;
        Property iconProp = this.iconProp != null ? this.iconProp : type.findProperty(icon);
        this.iconProp = iconProp;
        if (iconProp != null) {
            Object iconData = iconProp.getValue(getEntity().getEntity());
            if (iconData != null) {
                IconRendererAttribute iconRendererAtt = (IconRendererAttribute) viewNode.findInheritedAttribute(IconRendererAttribute.class);
                EntityImageRenderer iconRenderer = iconRendererAtt == null ? new DefaultEntityImageRenderer() : iconRendererAtt.getValue();
                iconRenderer.createImage(this, iconProp, 0, false, false).ready(im -> {
                    setIcon(im);
                    revalidateLater();
                });
            }
        }
    }
    if (changed) {
        revalidateLater();
    }
}
Also used : EntityType(com.codename1.rad.models.EntityType) EntityImageRenderer(com.codename1.rad.ui.image.EntityImageRenderer) DefaultEntityImageRenderer(com.codename1.rad.ui.image.DefaultEntityImageRenderer) IconRendererAttribute(com.codename1.rad.attributes.IconRendererAttribute) ViewProperty(com.codename1.rad.ui.ViewProperty) Property(com.codename1.rad.models.Property) DefaultEntityImageRenderer(com.codename1.rad.ui.image.DefaultEntityImageRenderer)

Example 5 with Property

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

the class ProfileAvatarsTitleComponent method initUI.

private void initUI() {
    setLayout(new BorderLayout());
    wrapper = new Container(new FanLayout(FanLayout.X_AXIS));
    avatarWrapperViewController.setView(wrapper);
    $(wrapper).selectAllStyles().setPadding(0).setMargin(0).setBorder(Border.createEmpty());
    int len = getEntity().size();
    for (int i = len - 1; i >= 0; i--) {
        // for (Entity child : getEntity()) {
        Entity child = getEntity().get(i);
        ProfileAvatarView v = createAvatar(child);
        wrapper.add(v);
    }
    add(CENTER, wrapper);
    StringBuilder text = new StringBuilder();
    Property nameProp = getEntity().getRowType().findProperty(Thing.name);
    if (getEntity().size() > 0) {
        if (nameProp != null) {
            text.append(getEntity().get(0).getEntity().getText(nameProp));
        }
    }
    if (getEntity().size() == 2) {
        if (nameProp != null) {
            text.append(" & ").append(getEntity().get(1).getEntity().getText(nameProp));
        }
    }
    if (getEntity().size() > 2) {
        if (text.length() == 0) {
            text.append(getEntity().size()).append(" People");
        } else {
            text.append(" and ").append(getEntity().size() - 1).append(" others");
        }
    }
    Label lbl = new Label(text.toString());
    lbl.setUIID("AccountAvatarsTitleComponentText");
    add(SOUTH, FlowLayout.encloseCenter(lbl));
}
Also used : Entity(com.codename1.rad.models.Entity) Container(com.codename1.ui.Container) BorderLayout(com.codename1.ui.layouts.BorderLayout) FanLayout(com.codename1.rad.layouts.FanLayout) Label(com.codename1.ui.Label) Property(com.codename1.rad.models.Property)

Aggregations

Entity (com.codename1.rad.models.Entity)22 Property (com.codename1.rad.models.Property)16 IOException (java.io.IOException)11 ResultParser (com.codename1.rad.io.ResultParser)10 ArrayList (java.util.ArrayList)10 SimpleDateFormat (com.codename1.l10n.SimpleDateFormat)9 Component (com.codename1.ui.Component)9 Element (com.codename1.xml.Element)8 ParseException (com.codename1.l10n.ParseException)7 Container (com.codename1.ui.Container)7 Label (com.codename1.ui.Label)7 SortedProperties (com.codename1.ant.SortedProperties)6 Log (com.codename1.io.Log)6 Form (com.codename1.ui.Form)6 AnimationObject (com.codename1.ui.animations.AnimationObject)6 Map (java.util.Map)6 Thing (com.codename1.rad.schemas.Thing)5 XMLParser (com.codename1.xml.XMLParser)5 StringReader (java.io.StringReader)5 List (java.util.List)5