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