use of com.evolveum.midpoint.util.DisplayableValue in project midpoint by Evolveum.
the class WebComponentUtil method createEnumPanel.
public static DropDownChoicePanel createEnumPanel(final PrismPropertyDefinition def, String id, final IModel model, final Component component) {
// final Class clazz = model.getObject().getClass();
final Object o = model.getObject();
final IModel<List<DisplayableValue>> enumModelValues = new AbstractReadOnlyModel<List<DisplayableValue>>() {
@Override
public List<DisplayableValue> getObject() {
List<DisplayableValue> values = null;
if (def.getAllowedValues() != null) {
values = new ArrayList<>(def.getAllowedValues().size());
for (Object v : def.getAllowedValues()) {
if (v instanceof DisplayableValue) {
values.add(((DisplayableValue) v));
}
}
}
return values;
}
};
return new DropDownChoicePanel(id, model, enumModelValues, new IChoiceRenderer() {
@Override
public Object getObject(String id, IModel choices) {
if (StringUtils.isBlank(id)) {
return null;
}
return ((List) choices.getObject()).get(Integer.parseInt(id));
}
@Override
public Object getDisplayValue(Object object) {
if (object instanceof DisplayableValue) {
return ((DisplayableValue) object).getLabel();
}
for (DisplayableValue v : enumModelValues.getObject()) {
if (object.equals(v.getValue())) {
return v.getLabel();
}
}
return object;
}
@Override
public String getIdValue(Object object, int index) {
if (object instanceof String && enumModelValues != null && enumModelValues.getObject() != null) {
List<DisplayableValue> enumValues = enumModelValues.getObject();
for (DisplayableValue v : enumValues) {
if (object.equals(v.getValue())) {
return String.valueOf(enumValues.indexOf(v));
}
}
}
return String.valueOf(index);
}
}, true);
}
use of com.evolveum.midpoint.util.DisplayableValue in project midpoint by Evolveum.
the class SearchItemPanel method createLabelModel.
private IModel<String> createLabelModel() {
return new AbstractReadOnlyModel<String>() {
@Override
public String getObject() {
SearchItem item = getModelObject();
StringBuilder sb = new StringBuilder();
sb.append(item.getName());
sb.append(": ");
List<String> values = new ArrayList<>();
for (DisplayableValue value : (List<DisplayableValue>) item.getValues()) {
if (StringUtils.isNotEmpty(value.getLabel())) {
values.add(value.getLabel());
}
}
if (!values.isEmpty()) {
String or = createStringResource("SearchItemPanel.or").getString();
sb.append('"');
sb.append(StringUtils.join(values, "\" " + or + " \""));
sb.append('"');
} else {
String all = createStringResource("SearchItemPanel.all").getString();
sb.append(all);
}
return sb.toString();
}
};
}
Aggregations