Search in sources :

Example 6 with DisplayableValue

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);
}
Also used : IChoiceRenderer(org.apache.wicket.markup.html.form.IChoiceRenderer) AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) DropDownChoicePanel(com.evolveum.midpoint.web.component.input.DropDownChoicePanel) IModel(org.apache.wicket.model.IModel) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) DisplayableValue(com.evolveum.midpoint.util.DisplayableValue) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Example 7 with DisplayableValue

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();
        }
    };
}
Also used : AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) DisplayableValue(com.evolveum.midpoint.util.DisplayableValue) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

DisplayableValue (com.evolveum.midpoint.util.DisplayableValue)7 ArrayList (java.util.ArrayList)3 List (java.util.List)2 AbstractReadOnlyModel (org.apache.wicket.model.AbstractReadOnlyModel)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 PolyStringNormalizer (com.evolveum.midpoint.prism.polystring.PolyStringNormalizer)1 DropDownChoicePanel (com.evolveum.midpoint.web.component.input.DropDownChoicePanel)1 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)1 IChoiceRenderer (org.apache.wicket.markup.html.form.IChoiceRenderer)1 IModel (org.apache.wicket.model.IModel)1