final PageReference pageRef) {
this.reportletConf = reportletConf;
this.pageRef = pageRef;
Form form = new Form("form");
add(form);
propertiesContainer = new WebMarkupContainer("container");
propertiesContainer.setOutputMarkupId(true);
form.add(propertiesContainer);
name = new AjaxTextFieldPanel("name", "name", this.reportletConf == null
? new Model()
: new PropertyModel<String>(this.reportletConf, "name"));
name.setOutputMarkupId(true);
name.addRequiredLabel();
form.add(name);
final AjaxDropDownChoicePanel<String> reportletClass = new AjaxDropDownChoicePanel<String>("reportletClass",
"reportletClass", new IModel<String>() {
private static final long serialVersionUID = -2316468110411802130L;
@Override
public String getObject() {
return ReportletConfModalPage.this.reportletConf == null
? null
: ReportletConfModalPage.this.reportletConf.getClass().getName();
}
@Override
public void setObject(final String object) {
try {
Class<?> reportletClass = Class.forName(object);
ReportletConfModalPage.this.reportletConf = (AbstractReportletConf) reportletClass.newInstance();
propertiesContainer.replace(buildPropView());
} catch (Exception e) {
LOG.error("Cannot find or initialize {}", object, e);
}
}
@Override
public void detach() {
}
});
reportletClass.setStyleSheet("long_dynamicsize");
reportletClass.setChoices(restClient.getReportletConfClasses());
((DropDownChoice) reportletClass.getField()).setNullValid(true);
reportletClass.addRequiredLabel();
reportletClass.getField().add(new AjaxFormComponentUpdatingBehavior("onchange") {
private static final long serialVersionUID = 5538299138211283825L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
((DropDownChoice) reportletClass.getField()).setNullValid(false);
target.add(reportletClass.getField());
target.add(propertiesContainer);
}
});
form.add(reportletClass);
propertiesContainer.add(buildPropView());
final AjaxButton submit = new AjaxButton("apply", new ResourceModel("apply")) {
private static final long serialVersionUID = -958724007591692537L;
@Override
protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
final BeanWrapper wrapper = PropertyAccessorFactory
.forBeanPropertyAccess(ReportletConfModalPage.this.reportletConf);
wrapper.setPropertyValue("name", name.getField().getInput());
// Iterate over properties in order to find UserSearchPanel instances and manually update
// this.reportletConf with select search criteria - this is needed because UserSearchPanel
// does not comply with usual Wicket model paradigm.
for (Iterator<Component> itor = ReportletConfModalPage.this.propView.visitChildren(); itor.hasNext();) {
Component component = itor.next();
if (component instanceof UserSearchPanel) {
// using component.getDefaultModelObjectAsString() to fetch field name (set above)
wrapper.setPropertyValue(component.getDefaultModelObjectAsString(),
((UserSearchPanel) component).buildSearchCond());
}
}
((ReportModalPage) pageRef.getPage())
.setModalReportletConf(ReportletConfModalPage.this.reportletConf);
window.close(target);
}
@Override
protected void onError(final AjaxRequestTarget target, final Form<?> form) {
target.add(feedbackPanel);
}
};
form.add(submit);
final AjaxButton cancel = new ClearIndicatingAjaxButton("cancel", new ResourceModel("cancel"), pageRef) {
private static final long serialVersionUID = -958724007591692537L;
@Override
protected void onSubmitInternal(final AjaxRequestTarget target, final Form<?> form) {
window.close(target);
}
};
cancel.setDefaultFormProcessing(false);
form.add(cancel);
}