Search in sources :

Example 6 with SearchSpecialItemPanel

use of com.evolveum.midpoint.web.component.search.SearchSpecialItemPanel in project midpoint by Evolveum.

the class RelationSearchItem method createSpecialSearchPanel.

@Override
public SearchSpecialItemPanel createSpecialSearchPanel(String id) {
    return new SearchSpecialItemPanel(id, new PropertyModel<>(searchBoxConfiguration, SearchBoxConfigurationHelper.F_RELATION_ITEM)) {

        @Override
        protected WebMarkupContainer initSearchItemField(String id) {
            ReadOnlyModel<List<QName>> availableRelations = new ReadOnlyModel<>(() -> {
                List<QName> choices = new ArrayList();
                IModel<RelationSearchItemConfigurationType> relationItem = getModelValue();
                List<QName> relations = relationItem.getObject().getSupportedRelations();
                if (relations != null && relations.size() > 1) {
                    choices.add(PrismConstants.Q_ANY);
                }
                choices.addAll(relations);
                return choices;
            });
            DropDownChoicePanel inputPanel = new DropDownChoicePanel(id, new PropertyModel(getModelValue(), RelationSearchItemConfigurationType.F_DEFAULT_VALUE.getLocalPart()), availableRelations, new QNameIChoiceRenderer() {

                private static final long serialVersionUID = 1L;

                @Override
                public Object getDisplayValue(QName relation) {
                    RelationDefinitionType relationDef = WebComponentUtil.getRelationDefinition(relation);
                    if (relationDef != null) {
                        DisplayType display = relationDef.getDisplay();
                        if (display != null) {
                            PolyStringType label = display.getLabel();
                            if (PolyStringUtils.isNotEmpty(label)) {
                                return WebComponentUtil.getTranslatedPolyString(label);
                            }
                        }
                    }
                    if (QNameUtil.match(PrismConstants.Q_ANY, relation)) {
                        return new ResourceModel("RelationTypes.ANY", relation.getLocalPart()).getObject();
                    }
                    return super.getDisplayValue(relation);
                }
            }, false);
            inputPanel.getBaseFormComponent().add(WebComponentUtil.getSubmitOnEnterKeyDownBehavior("searchSimple"));
            inputPanel.getBaseFormComponent().add(AttributeAppender.append("style", "width: 100px; max-width: 400px !important;"));
            inputPanel.getBaseFormComponent().add(new EnableBehaviour(() -> availableRelations.getObject().size() > 1));
            inputPanel.setOutputMarkupId(true);
            return inputPanel;
        }

        @Override
        protected IModel<String> createLabelModel() {
            return Model.of(WebComponentUtil.getTranslatedPolyString(getReltaionConfig().getDisplay().getLabel()));
        }

        @Override
        protected IModel<String> createHelpModel() {
            return Model.of(WebComponentUtil.getTranslatedPolyString(getReltaionConfig().getDisplay().getHelp()));
        }
    };
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) DropDownChoicePanel(com.evolveum.midpoint.web.component.input.DropDownChoicePanel) QNameIChoiceRenderer(com.evolveum.midpoint.gui.impl.component.input.QNameIChoiceRenderer) DisplayType(com.evolveum.midpoint.xml.ns._public.common.common_3.DisplayType) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) PropertyModel(org.apache.wicket.model.PropertyModel) RelationDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.RelationDefinitionType) ReadOnlyModel(com.evolveum.midpoint.gui.api.model.ReadOnlyModel) ResourceModel(org.apache.wicket.model.ResourceModel) ArrayList(java.util.ArrayList) List(java.util.List) RelationSearchItemConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.RelationSearchItemConfigurationType) SearchSpecialItemPanel(com.evolveum.midpoint.web.component.search.SearchSpecialItemPanel) EnableBehaviour(com.evolveum.midpoint.web.component.util.EnableBehaviour)

Aggregations

SearchSpecialItemPanel (com.evolveum.midpoint.web.component.search.SearchSpecialItemPanel)6 PropertyModel (org.apache.wicket.model.PropertyModel)6 DropDownChoicePanel (com.evolveum.midpoint.web.component.input.DropDownChoicePanel)4 VisibleBehaviour (com.evolveum.midpoint.web.component.util.VisibleBehaviour)3 QName (javax.xml.namespace.QName)3 PrismReferenceDefinition (com.evolveum.midpoint.prism.PrismReferenceDefinition)2 ReferenceValueSearchPanel (com.evolveum.midpoint.web.component.search.ReferenceValueSearchPanel)2 EnableBehaviour (com.evolveum.midpoint.web.component.util.EnableBehaviour)2 ArrayList (java.util.ArrayList)2 EnumChoiceRenderer (org.apache.wicket.markup.html.form.EnumChoiceRenderer)2 IModel (org.apache.wicket.model.IModel)2 ReadOnlyModel (com.evolveum.midpoint.gui.api.model.ReadOnlyModel)1 PageBase (com.evolveum.midpoint.gui.api.page.PageBase)1 QNameIChoiceRenderer (com.evolveum.midpoint.gui.impl.component.input.QNameIChoiceRenderer)1 VariablesMap (com.evolveum.midpoint.schema.expression.VariablesMap)1 SpecialSearchItem (com.evolveum.midpoint.web.component.search.SpecialSearchItem)1 DisplayType (com.evolveum.midpoint.xml.ns._public.common.common_3.DisplayType)1 RelationDefinitionType (com.evolveum.midpoint.xml.ns._public.common.common_3.RelationDefinitionType)1 RelationSearchItemConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.RelationSearchItemConfigurationType)1 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)1