Search in sources :

Example 1 with ItemPanel

use of com.evolveum.midpoint.gui.impl.prism.panel.ItemPanel in project midpoint by Evolveum.

the class SchrodingerComponentInitListener method handleLocalization.

private void handleLocalization(Component component) {
    if (component instanceof PrismPropertyPanel || component instanceof PrismReferencePanel) {
        ItemPanel ppp = (ItemPanel) component;
        ItemWrapper iw = (ItemWrapper) ppp.getModel().getObject();
        String key = iw.getDisplayName();
        QName qname = iw.getItemName();
        writeDataAttribute(component, ATTR_RESOURCE_KEY, key);
        writeDataAttribute(component, ATTR_QNAME, qnameToString(qname));
        return;
    }
    if (component instanceof PrismHeaderPanel) {
        PrismHeaderPanel php = (PrismHeaderPanel) component;
        String key = php.getLabel();
        writeDataAttribute(component, ATTR_RESOURCE_KEY, key);
        return;
    }
    IModel model = null;
    if (component.getDefaultModel() instanceof StringResourceModel) {
        model = component.getDefaultModel();
    } else if (component.getInnermostModel() instanceof StringResourceModel) {
        model = component.getInnermostModel();
    } else if (component.getDefaultModel() instanceof ReadOnlyModel) {
        try {
            if (component.getDefaultModelObject() instanceof String) {
                model = component.getDefaultModel();
            }
        } catch (Exception e) {
            LOGGER.error("Schrodinger localization handling failed", e);
        }
    }
    if (model == null) {
        return;
    }
    try {
        String key = model instanceof StringResourceModel ? (String) FieldUtils.readField(model, "resourceKey", true) : (String) model.getObject();
        if (key.startsWith("${")) {
            String expression = key.substring(2, key.length() - 1);
            key = new PropertyModel<String>(FieldUtils.readField(model, "model", true), expression).getObject();
        }
        if (key != null) {
            writeDataAttribute(component, ATTR_RESOURCE_KEY, key);
        }
    } catch (Exception ex) {
    // we don't care, should be all right, unless selenium tests starts failing
    }
}
Also used : ItemWrapper(com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper) PrismPropertyPanel(com.evolveum.midpoint.gui.impl.prism.panel.PrismPropertyPanel) PrismHeaderPanel(com.evolveum.midpoint.web.component.prism.PrismHeaderPanel) IModel(org.apache.wicket.model.IModel) PrismReferencePanel(com.evolveum.midpoint.gui.impl.prism.panel.PrismReferencePanel) ReadOnlyModel(com.evolveum.midpoint.gui.api.model.ReadOnlyModel) QName(javax.xml.namespace.QName) ItemPanel(com.evolveum.midpoint.gui.impl.prism.panel.ItemPanel) PropertyModel(org.apache.wicket.model.PropertyModel) StringResourceModel(org.apache.wicket.model.StringResourceModel)

Aggregations

ReadOnlyModel (com.evolveum.midpoint.gui.api.model.ReadOnlyModel)1 ItemWrapper (com.evolveum.midpoint.gui.api.prism.wrapper.ItemWrapper)1 ItemPanel (com.evolveum.midpoint.gui.impl.prism.panel.ItemPanel)1 PrismPropertyPanel (com.evolveum.midpoint.gui.impl.prism.panel.PrismPropertyPanel)1 PrismReferencePanel (com.evolveum.midpoint.gui.impl.prism.panel.PrismReferencePanel)1 PrismHeaderPanel (com.evolveum.midpoint.web.component.prism.PrismHeaderPanel)1 QName (javax.xml.namespace.QName)1 IModel (org.apache.wicket.model.IModel)1 PropertyModel (org.apache.wicket.model.PropertyModel)1 StringResourceModel (org.apache.wicket.model.StringResourceModel)1