use of com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteReferenceRenderer in project midpoint by Evolveum.
the class ReferenceValueSearchPopupPanel method customizationPopoverForm.
@Override
protected void customizationPopoverForm(MidpointForm midpointForm) {
FeedbackAlerts feedback = new FeedbackAlerts(ID_FEEDBACK);
feedback.setOutputMarkupId(true);
midpointForm.add(feedback);
PropertyModel<String> oidModel = new PropertyModel<>(getModel(), "oid") {
@Override
public void setObject(String object) {
super.setObject(object);
if (StringUtils.isBlank(object)) {
ReferenceValueSearchPopupPanel.this.getModelObject().asReferenceValue().setObject(null);
ReferenceValueSearchPopupPanel.this.getModelObject().setTargetName(null);
ReferenceValueSearchPopupPanel.this.getModelObject().setRelation(null);
}
}
};
TextField<String> oidField = new TextField<>(ID_OID, oidModel);
oidField.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
oidField.setOutputMarkupId(true);
oidField.add(new EnableBehaviour(this::isItemPanelEnabled));
midpointForm.add(oidField);
ReferenceAutocomplete nameField = new ReferenceAutocomplete(ID_NAME, Model.of(getModelObject()), new AutoCompleteReferenceRenderer(), getPageBase()) {
private static final long serialVersionUID = 1L;
@Override
protected boolean isAllowedNotFoundObjectRef() {
return ReferenceValueSearchPopupPanel.this.isAllowedNotFoundObjectRef();
}
@Override
protected <O extends ObjectType> Class<O> getReferenceTargetObjectType() {
if (getModelObject() != null && getModelObject().getType() != null) {
return (Class<O>) WebComponentUtil.qnameToClass(PrismContext.get(), getModelObject().getType());
}
return super.getReferenceTargetObjectType();
}
};
feedback.setFilter(new ComponentFeedbackMessageFilter(nameField));
nameField.getBaseFormComponent().add(new AjaxFormComponentUpdatingBehavior("blur") {
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
updateModel(nameField.getBaseFormComponent().getModelObject(), midpointForm, target);
}
});
nameField.setOutputMarkupId(true);
nameField.add(new EnableBehaviour(this::isItemPanelEnabled));
midpointForm.add(nameField);
DropDownChoicePanel<QName> type = new DropDownChoicePanel<>(ID_TYPE, new PropertyModel<>(getModel(), "type"), Model.ofList(getSupportedTargetList()), new QNameObjectTypeChoiceRenderer(), true);
type.setOutputMarkupId(true);
type.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
@Override
public boolean isEnabled() {
return getSupportedTargetList().size() > 1 && isItemPanelEnabled();
}
});
type.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
type.getBaseFormComponent().add(new AjaxFormComponentUpdatingBehavior("change") {
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
ObjectReferenceType ref = nameField.getAutoCompleteConverter(ObjectReferenceType.class, null).convertToObject(nameField.getBaseFormComponent().getValue(), WebComponentUtil.getCurrentLocale());
updateModel(ref, midpointForm, target);
target.add(oidField);
target.add(ReferenceValueSearchPopupPanel.this);
}
});
midpointForm.add(type);
WebMarkupContainer relationContainer = new WebMarkupContainer(ID_RELATION_CONTAINER);
midpointForm.add(relationContainer);
relationContainer.add(new VisibleBehaviour(() -> getAllowedRelations().size() > 0));
List<QName> allowedRelations = new ArrayList<>(getAllowedRelations());
DropDownChoicePanel<QName> relation = new DropDownChoicePanel<>(ID_RELATION, new PropertyModel<>(getModel(), "relation"), Model.ofList(allowedRelations), new QNameObjectTypeChoiceRenderer(), true);
relation.setOutputMarkupId(true);
relation.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;
@Override
public boolean isEnabled() {
return getAllowedRelations().size() > 1 && isItemPanelEnabled();
}
});
relation.getBaseFormComponent().add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
relationContainer.add(relation);
AjaxButton selectObject = new AjaxButton(ID_SELECT_OBJECT_BUTTON, createStringResource("ReferenceValueSearchPopupPanel.selectObject")) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
List<QName> supportedTypes = getSupportedTargetList();
if (CollectionUtils.isEmpty(supportedTypes)) {
supportedTypes = WebComponentUtil.createObjectTypeList();
}
ObjectBrowserPanel<O> objectBrowserPanel = new ObjectBrowserPanel<>(getPageBase().getMainPopupBodyId(), null, supportedTypes, false, getPageBase(), null) {
private static final long serialVersionUID = 1L;
@Override
protected void onSelectPerformed(AjaxRequestTarget target, O object) {
getPageBase().hideMainPopup(target);
if (ReferenceValueSearchPopupPanel.this.getModel().getObject() == null) {
ReferenceValueSearchPopupPanel.this.getModel().setObject(new ObjectReferenceType());
}
ReferenceValueSearchPopupPanel.this.getModelObject().setOid(object.getOid());
ReferenceValueSearchPopupPanel.this.getModelObject().setTargetName(object.getName());
ReferenceValueSearchPopupPanel.this.getModelObject().setType(object.asPrismObject().getComplexTypeDefinition().getTypeName());
target.add(oidField);
target.add(nameField);
target.add(type);
}
};
getPageBase().showMainPopup(objectBrowserPanel, target);
}
};
selectObject.add(new VisibleBehaviour(() -> getPageBase().getMainPopup().getContentComponent() == null));
midpointForm.add(selectObject);
}
use of com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteReferenceRenderer in project midpoint by Evolveum.
the class AutoCompleteReferencePanelFactory method createPanel.
@Override
public org.apache.wicket.Component createPanel(PrismReferencePanelContext<ObjectReferenceType> panelCtx) {
ReferenceAutocomplete panel = new ReferenceAutocomplete(panelCtx.getComponentId(), panelCtx.getRealValueModel(), new AutoCompleteReferenceRenderer(), panelCtx.getPageBase());
panel.setOutputMarkupId(true);
// ugly hack to be aligned with prism-property-label
panel.add(AttributeAppender.append("style", "padding-top:5px"));
return panel;
}
Aggregations