Search in sources :

Example 46 with ResourceModel

use of org.apache.wicket.model.ResourceModel 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)

Example 47 with ResourceModel

use of org.apache.wicket.model.ResourceModel in project midpoint by Evolveum.

the class QNameIChoiceRenderer method getDisplayValue.

@Override
public Object getDisplayValue(QName qname) {
    if (qname == null) {
        return null;
    }
    String realPrefix = prefix != null && !prefix.isEmpty() ? (prefix + ".") : "";
    String key = realPrefix + qname.getLocalPart();
    return new ResourceModel(key, qname.getLocalPart()).getObject();
}
Also used : ResourceModel(org.apache.wicket.model.ResourceModel)

Example 48 with ResourceModel

use of org.apache.wicket.model.ResourceModel in project wiquery by WiQuery.

the class OptionsTestCase method testOptionsWrappedModels.

@Test
public void testOptionsWrappedModels() {
    // this method test the use of wrapped models in options
    OptionsTestPanel panel = new OptionsTestPanel("panel");
    Options options = panel.getOptions();
    // put an IComponentAssignedModel
    options.putString("test", new ResourceModel("key"));
    options.putString("test1", new Model<String>("Test1"));
    options.put("test2", false);
    OptionsTestPage page = new OptionsTestPage(panel);
    page = tester.startPage(page);
    String expectedResult = "Test";
    // result should has been read from resources.
    String result = options.get("test");
    log.info("result=" + result);
    log.info("expectedResult=" + expectedResult);
    assertEquals(expectedResult, result);
    assertEquals("Test1", options.get("test1"));
    assertEquals(false, options.getBoolean("test2").booleanValue());
    tester.assertNoErrorMessage();
}
Also used : ResourceModel(org.apache.wicket.model.ResourceModel) Test(org.junit.Test)

Aggregations

ResourceModel (org.apache.wicket.model.ResourceModel)48 ArrayList (java.util.ArrayList)20 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)19 Label (org.apache.wicket.markup.html.basic.Label)17 StringResourceModel (org.apache.wicket.model.StringResourceModel)15 Panel (org.apache.wicket.markup.html.panel.Panel)11 List (java.util.List)9 AbstractTab (org.apache.wicket.extensions.markup.html.tabs.AbstractTab)9 AjaxBootstrapTabbedPanel (de.agilecoders.wicket.core.markup.html.bootstrap.tabs.AjaxBootstrapTabbedPanel)8 ITab (org.apache.wicket.extensions.markup.html.tabs.ITab)8 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)8 IColumn (org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn)6 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)5 Form (org.apache.wicket.markup.html.form.Form)5 Serializable (java.io.Serializable)4 HashMap (java.util.HashMap)4 WizardMgtPanel (org.apache.syncope.client.console.wizards.WizardMgtPanel)4 Fragment (org.apache.wicket.markup.html.panel.Fragment)4 NavbarButton (de.agilecoders.wicket.core.markup.html.bootstrap.navbar.NavbarButton)3 StringUtils (org.apache.commons.lang3.StringUtils)3