List of usage examples for org.apache.wicket.model AbstractReadOnlyModel AbstractReadOnlyModel
AbstractReadOnlyModel
From source file:com.evolveum.midpoint.web.component.form.multivalue.MultiValueTextFormGroup.java
License:Apache License
private void initLayout(final IModel<String> label, final String labelSize, final String textSize, final boolean required) { Label l = new Label(ID_LABEL, label); if (StringUtils.isNotEmpty(labelSize)) { l.add(AttributeAppender.prepend("class", labelSize)); }/*from w ww. j a v a 2 s . co m*/ add(l); ListView repeater = new ListView<T>(ID_REPEATER, getModel()) { @Override protected void populateItem(final ListItem<T> item) { WebMarkupContainer textWrapper = new WebMarkupContainer(ID_TEXT_WRAPPER); textWrapper.add(AttributeAppender.prepend("class", new AbstractReadOnlyModel<String>() { @Override public String getObject() { StringBuilder sb = new StringBuilder(); if (StringUtils.isNotEmpty(textSize)) { sb.append(textSize).append(' '); } if (item.getIndex() > 0 && StringUtils.isNotEmpty(getOffsetClass())) { sb.append(getOffsetClass()).append(' '); sb.append(CLASS_MULTI_VALUE); } return sb.toString(); } })); item.add(textWrapper); TextField text = new TextField(ID_TEXT, createTextModel(item.getModel())); text.add(new AjaxFormComponentUpdatingBehavior("onblur") { @Override protected void onUpdate(AjaxRequestTarget target) { } }); text.setRequired(required); text.add(AttributeAppender.replace("placeholder", label)); text.setLabel(label); textWrapper.add(text); FeedbackPanel feedback = new FeedbackPanel(ID_FEEDBACK, new ComponentFeedbackMessageFilter(text)); textWrapper.add(feedback); WebMarkupContainer buttonGroup = new WebMarkupContainer(ID_BUTTON_GROUP); buttonGroup.add(AttributeAppender.append("class", new AbstractReadOnlyModel<String>() { @Override public String getObject() { if (item.getIndex() > 0 && StringUtils.isNotEmpty(labelSize)) { return CLASS_MULTI_VALUE; } return null; } })); item.add(buttonGroup); initButtons(buttonGroup, item); } }; add(repeater); }
From source file:com.evolveum.midpoint.web.component.form.multivalue.MultiValueTextPanel.java
License:Apache License
protected void initPanelLayout() { WebMarkupContainer placeholderContainer = new WebMarkupContainer(ID_PLACEHOLDER_CONTAINER); placeholderContainer.setOutputMarkupPlaceholderTag(true); placeholderContainer.setOutputMarkupPlaceholderTag(true); placeholderContainer.add(new VisibleEnableBehaviour() { @Override/*from w ww . ja v a2s . c om*/ public boolean isVisible() { return getModel().getObject().isEmpty(); } }); add(placeholderContainer); AjaxLink placeholderAdd = new AjaxLink(ID_PLACEHOLDER_ADD) { @Override public void onClick(AjaxRequestTarget target) { addValuePerformed(target); } }; placeholderAdd.add(new AttributeAppender("class", new AbstractReadOnlyModel<String>() { @Override public String getObject() { if (buttonsDisabled()) { return " " + CSS_DISABLED; } return ""; } })); placeholderAdd.setOutputMarkupId(true); placeholderAdd.setOutputMarkupPlaceholderTag(true); placeholderContainer.add(placeholderAdd); ListView repeater = new ListView<T>(ID_REPEATER, getModel()) { @Override protected void populateItem(final ListItem<T> item) { TextField text = new TextField<>(ID_TEXT, createTextModel(item.getModel())); text.add(new AjaxFormComponentUpdatingBehavior("onblur") { @Override protected void onUpdate(AjaxRequestTarget target) { } }); text.add(AttributeAppender.replace("placeholder", createEmptyItemPlaceholder())); item.add(text); WebMarkupContainer buttonGroup = new WebMarkupContainer(ID_BUTTON_GROUP); item.add(buttonGroup); initButtons(buttonGroup, item); } }; repeater.setOutputMarkupId(true); repeater.setOutputMarkupPlaceholderTag(true); repeater.add(new VisibleEnableBehaviour() { @Override public boolean isVisible() { return !getModel().getObject().isEmpty(); } }); add(repeater); }
From source file:com.evolveum.midpoint.web.component.form.ValueChoosePanel.java
License:Apache License
protected IModel<String> createTextModel(final IModel<T> model) { return new AbstractReadOnlyModel<String>() { private static final long serialVersionUID = 1L; @Override/*from www . j a va 2 s.c o m*/ public String getObject() { T ort = (T) model.getObject(); if (ort instanceof PrismReferenceValue) { PrismReferenceValue prv = (PrismReferenceValue) ort; return prv == null ? null : (prv.getTargetName() != null ? (prv.getTargetName().getOrig() + (prv.getTargetType() != null ? ": " + prv.getTargetType().getLocalPart() : "")) : prv.getOid()); } else if (ort instanceof ObjectViewDto) { return ((ObjectViewDto) ort).getName(); } return ort != null ? ort.toString() : null; } }; }
From source file:com.evolveum.midpoint.web.component.GuiComponents.java
License:Apache License
private static IModel<List<Boolean>> createChoices() { return new AbstractReadOnlyModel<List<Boolean>>() { @Override// w w w . j a va2 s . c o m public List<Boolean> getObject() { List<Boolean> list = new ArrayList<Boolean>(); list.add(null); list.add(Boolean.TRUE); list.add(Boolean.FALSE); return list; } }; }
From source file:com.evolveum.midpoint.web.component.input.ExpressionEditorPanel.java
License:Apache License
@Override protected void initLayout() { loadModel();//w w w . j a v a 2 s.co m Label typeLabel = new Label(ID_LABEL_TYPE, createStringResource(getTypeLabelKey())); add(typeLabel); DropDownChoice type = new DropDownChoice<>(ID_TYPE, new PropertyModel<ExpressionUtil.ExpressionEvaluatorType>(model, ExpressionTypeDto.F_TYPE), WebMiscUtil.createReadonlyModelFromEnum(ExpressionUtil.ExpressionEvaluatorType.class), new EnumChoiceRenderer<ExpressionUtil.ExpressionEvaluatorType>(this)); type.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { model.getObject().updateExpressionType(); target.add(get(ID_LANGUAGE_CONTAINER), get(ID_POLICY_CONTAINER), get(ID_EXPRESSION)); } }); type.setOutputMarkupId(true); type.setOutputMarkupPlaceholderTag(true); type.setNullValid(true); add(type); WebMarkupContainer languageContainer = new WebMarkupContainer(ID_LANGUAGE_CONTAINER); languageContainer.setOutputMarkupId(true); languageContainer.setOutputMarkupPlaceholderTag(true); languageContainer.add(new VisibleEnableBehaviour() { @Override public boolean isVisible() { return ExpressionUtil.ExpressionEvaluatorType.SCRIPT.equals(model.getObject().getType()); } }); add(languageContainer); DropDownChoice language = new DropDownChoice<>(ID_LANGUAGE, new PropertyModel<ExpressionUtil.Language>(model, ExpressionTypeDto.F_LANGUAGE), WebMiscUtil.createReadonlyModelFromEnum(ExpressionUtil.Language.class), new EnumChoiceRenderer<ExpressionUtil.Language>(this)); language.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { model.getObject().updateExpressionLanguage(); target.add(get(ID_LANGUAGE_CONTAINER), get(ID_POLICY_CONTAINER), get(ID_EXPRESSION)); } }); language.setNullValid(false); languageContainer.add(language); WebMarkupContainer policyContainer = new WebMarkupContainer(ID_POLICY_CONTAINER); policyContainer.setOutputMarkupId(true); policyContainer.setOutputMarkupPlaceholderTag(true); policyContainer.add(new VisibleEnableBehaviour() { @Override public boolean isVisible() { return ExpressionUtil.ExpressionEvaluatorType.GENERATE.equals(model.getObject().getType()); } }); add(policyContainer); DropDownChoice policyRef = new DropDownChoice<>(ID_POLICY_REF, new PropertyModel<ObjectReferenceType>(model, ExpressionTypeDto.F_POLICY_REF), new AbstractReadOnlyModel<List<ObjectReferenceType>>() { @Override public List<ObjectReferenceType> getObject() { return createPasswordPolicyList(); } }, new IChoiceRenderer<ObjectReferenceType>() { @Override public Object getDisplayValue(ObjectReferenceType object) { return policyMap.get(object.getOid()); } @Override public String getIdValue(ObjectReferenceType object, int index) { return Integer.toString(index); } }); policyRef.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { model.getObject().updateExpressionValuePolicyRef(); target.add(get(ID_LANGUAGE_CONTAINER), get(ID_POLICY_CONTAINER), get(ID_EXPRESSION)); } }); policyRef.setNullValid(true); policyContainer.add(policyRef); Label expressionLabel = new Label(ID_LABEL_EXPRESSION, createStringResource(getExpressionLabelKey())); add(expressionLabel); TextArea expression = new TextArea<>(ID_EXPRESSION, new PropertyModel<String>(model, ExpressionTypeDto.F_EXPRESSION)); expression.setOutputMarkupId(true); add(expression); AjaxSubmitLink update = new AjaxSubmitLink(ID_BUTTON_UPDATE) { @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { updateExpressionPerformed(target); } }; add(update); Label typeTooltip = new Label(ID_T_TYPE); typeTooltip.add(new InfoTooltipBehavior()); add(typeTooltip); Label languageTooltip = new Label(ID_T_LANGUAGE); languageTooltip.add(new InfoTooltipBehavior()); languageContainer.add(languageTooltip); Label policyTooltip = new Label(ID_T_POLICY); policyTooltip.add(new InfoTooltipBehavior()); policyContainer.add(policyTooltip); Label expressionTooltip = new Label(ID_T_EXPRESSION); expressionTooltip.add(new InfoTooltipBehavior()); add(expressionTooltip); }
From source file:com.evolveum.midpoint.web.component.input.TextDetailsPanel.java
License:Apache License
public TextDetailsPanel(String id, IModel<T> model, Class clazz) { super(id);/*from w ww. j av a2 s . c o m*/ final TextField<T> text = new TextField<>(ID_INPUT, model); text.setType(clazz); add(text); Label details = new Label(ID_DETAILS); details.add(AttributeModifier.replace("title", new AbstractReadOnlyModel<String>() { @Override public String getObject() { return createAssociationTooltip(); } })); details.add(new InfoTooltipBehavior() { @Override public String getDataPlacement() { return "bottom"; } }); add(details); }
From source file:com.evolveum.midpoint.web.component.input.ThreeStateBooleanPanel.java
License:Apache License
protected void initLayout(final String optionOneLabel, final String optionTwoLabel, final String optionThreeLabel, final String buttonCssClass) { AjaxButton buttonTrue = new AjaxButton(ID_BUTTON_ONE, new AbstractReadOnlyModel<String>() { @Override//from www . j a v a 2s . c o m public String getObject() { if (optionOneLabel == null) { return getString("ThreeStateBooleanPanel.true"); } else { return getString(optionOneLabel); } } }) { @Override public void onClick(AjaxRequestTarget target) { stateChanged(Boolean.TRUE, target); } }; buttonTrue.setOutputMarkupId(true); buttonTrue.add(prepareButtonCssClass(buttonCssClass)); buttonTrue.add(prepareActiveButtonAppender(Boolean.TRUE)); add(buttonTrue); AjaxButton buttonUndef = new AjaxButton(ID_BUTTON_TWO, new AbstractReadOnlyModel<String>() { @Override public String getObject() { if (optionTwoLabel == null) { return getString("ThreeStateBooleanPanel.undef"); } else { return getString(optionTwoLabel); } } }) { @Override public void onClick(AjaxRequestTarget target) { stateChanged(null, target); } }; buttonUndef.setOutputMarkupId(true); buttonUndef.add(prepareButtonCssClass(buttonCssClass)); buttonUndef.add(prepareActiveButtonAppender(null)); add(buttonUndef); AjaxButton buttonFalse = new AjaxButton(ID_BUTTON_THREE, new AbstractReadOnlyModel<String>() { @Override public String getObject() { if (optionThreeLabel == null) { return getString("ThreeStateBooleanPanel.false"); } else { return getString(optionThreeLabel); } } }) { @Override public void onClick(AjaxRequestTarget target) { stateChanged(Boolean.FALSE, target); } }; buttonFalse.setOutputMarkupId(true); buttonFalse.add(prepareButtonCssClass(buttonCssClass)); buttonFalse.add(prepareActiveButtonAppender(Boolean.FALSE)); add(buttonFalse); }
From source file:com.evolveum.midpoint.web.component.input.ThreeStateBooleanPanel.java
License:Apache License
private AttributeAppender prepareActiveButtonAppender(final Boolean value) { return new AttributeAppender("class", new AbstractReadOnlyModel<String>() { @Override/*from w ww. j a v a 2 s .c o m*/ public String getObject() { if (getModel() != null) { return getModel().getObject() == value ? " active" : null; } return null; } }); }
From source file:com.evolveum.midpoint.web.component.input.TwoStateBooleanPanel.java
License:Apache License
protected void initLayout(final String optionOneLabel, final String optionTwoLabel, final String buttonCssClass) { AjaxButton buttonFalse = new AjaxButton(ID_BUTTON_ONE, new AbstractReadOnlyModel<String>() { @Override//from w w w . j a v a2 s .co m public String getObject() { if (optionOneLabel == null) { return getString("ThreeStateBooleanPanel.false"); } else { return getString(optionOneLabel); } } }) { @Override public void onClick(AjaxRequestTarget target) { stateChanged(Boolean.FALSE, target); } }; buttonFalse.setOutputMarkupId(true); buttonFalse.add(prepareButtonCssClass(buttonCssClass)); buttonFalse.add(prepareActiveButtonAppender(Boolean.FALSE)); add(buttonFalse); AjaxButton buttonTrue = new AjaxButton(ID_BUTTON_TWO, new AbstractReadOnlyModel<String>() { @Override public String getObject() { if (optionTwoLabel == null) { return getString("ThreeStateBooleanPanel.true"); } else { return getString(optionTwoLabel); } } }) { @Override public void onClick(AjaxRequestTarget target) { stateChanged(Boolean.TRUE, target); } }; buttonTrue.setOutputMarkupId(true); buttonTrue.add(prepareButtonCssClass(buttonCssClass)); buttonTrue.add(prepareActiveButtonAppender(Boolean.TRUE)); add(buttonTrue); }
From source file:com.evolveum.midpoint.web.component.menu.MainMenuPanel.java
License:Apache License
private void initLayout() { final MainMenuItem menu = getModelObject(); WebMarkupContainer item = new WebMarkupContainer(ID_ITEM); item.add(AttributeModifier.replace("class", new AbstractReadOnlyModel<String>() { private static final long serialVersionUID = 1L; @Override/*from w w w . j a v a 2s . c o m*/ public String getObject() { if (menu.isMenuActive((WebPage) getPage())) { return "active"; } for (MenuItem item : menu.getItems()) { if (item.isMenuActive((WebPage) getPage())) { return "active"; } } return !menu.getItems().isEmpty() ? "treeview" : null; } })); add(item); WebMarkupContainer link; if (menu.getPageClass() != null) { link = new AjaxLink(ID_LINK) { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { mainMenuPerformed(menu); } }; } else if (menu instanceof AdditionalMenuItem) { link = new AjaxLink(ID_LINK) { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { additionalMenuPerformed(menu); } }; } else { link = new WebMarkupContainer(ID_LINK); } item.add(link); WebMarkupContainer icon = new WebMarkupContainer(ID_ICON); icon.add(AttributeModifier.replace("class", new PropertyModel<>(menu, MainMenuItem.F_ICON_CLASS))); link.add(icon); Label label = new Label(ID_LABEL, menu.getNameModel()); link.add(label); final PropertyModel<String> bubbleModel = new PropertyModel<>(menu, MainMenuItem.F_BUBBLE_LABEL); Label bubble = new Label(ID_BUBBLE, bubbleModel); bubble.add(new VisibleEnableBehaviour() { private static final long serialVersionUID = 1L; @Override public boolean isVisible() { return bubbleModel.getObject() != null; } }); link.add(bubble); WebMarkupContainer arrow = new WebMarkupContainer(ID_ARROW); arrow.add(new VisibleEnableBehaviour() { private static final long serialVersionUID = 1L; @Override public boolean isVisible() { return !menu.getItems().isEmpty() && bubbleModel.getObject() == null; } }); link.add(arrow); WebMarkupContainer submenu = new WebMarkupContainer(ID_SUBMENU); submenu.add(new VisibleEnableBehaviour() { private static final long serialVersionUID = 1L; @Override public boolean isVisible() { return !menu.getItems().isEmpty(); } }); item.add(submenu); ListView<MenuItem> subItem = new ListView<MenuItem>(ID_SUB_ITEM, new Model((Serializable) menu.getItems())) { @Override protected void populateItem(ListItem<MenuItem> listItem) { createSubmenu(listItem); } }; submenu.add(subItem); }