final Form<ConnInstanceTO> connectorPropForm = new Form<ConnInstanceTO>("connectorPropForm");
connectorPropForm.setModel(new CompoundPropertyModel<ConnInstanceTO>(connInstanceTO));
connectorPropForm.setOutputMarkupId(true);
propertiesContainer.add(connectorPropForm);
final AjaxTextFieldPanel displayName = new AjaxTextFieldPanel(
"displayName", "display name", new PropertyModel<String>(connInstanceTO, "displayName"));
displayName.setOutputMarkupId(true);
displayName.addRequiredLabel();
connectorForm.add(displayName);
final AjaxDropDownChoicePanel<String> location =
new AjaxDropDownChoicePanel<String>("location", "location",
new Model<String>(bundleTO == null ? null : bundleTO.getLocation()));
((DropDownChoice) location.getField()).setNullValid(true);
location.setStyleSheet("long_dynamicsize");
location.setChoices(new ArrayList<String>(mapConnBundleTOs.keySet()));
location.setRequired(true);
location.addRequiredLabel();
location.setOutputMarkupId(true);
location.setEnabled(connInstanceTO.getId() == 0);
location.getField().setOutputMarkupId(true);
connectorForm.add(location);
final AjaxDropDownChoicePanel<String> connectorName =
new AjaxDropDownChoicePanel<String>("connectorName", "connectorName",
new Model<String>(bundleTO == null ? null : bundleTO.getBundleName()));
((DropDownChoice) connectorName.getField()).setNullValid(true);
connectorName.setStyleSheet("long_dynamicsize");
connectorName.setChoices(bundleTO == null
? new ArrayList<String>()
: new ArrayList<String>(mapConnBundleTOs.get(connInstanceTO.getLocation()).keySet()));
connectorName.setRequired(true);
connectorName.addRequiredLabel();
connectorName.setEnabled(connInstanceTO.getLocation() != null);
connectorName.setOutputMarkupId(true);
connectorName.setEnabled(connInstanceTO.getId() == 0);
connectorName.getField().setOutputMarkupId(true);
connectorForm.add(connectorName);
final AjaxDropDownChoicePanel<String> version =
new AjaxDropDownChoicePanel<String>("version", "version",
new Model<String>(bundleTO == null ? null : bundleTO.getVersion()));
version.setStyleSheet("long_dynamicsize");
version.setChoices(bundleTO == null
? new ArrayList<String>()
: new ArrayList<String>(mapConnBundleTOs.get(connInstanceTO.getLocation()).
get(connInstanceTO.getBundleName()).keySet()));
version.setRequired(true);
version.addRequiredLabel();
version.setEnabled(connInstanceTO.getBundleName() != null);
version.setOutputMarkupId(true);
version.addRequiredLabel();
version.getField().setOutputMarkupId(true);
connectorForm.add(version);
final AjaxTextFieldPanel connRequestTimeout = new AjaxTextFieldPanel(
"connRequestTimeout",
"connRequestTimeout",
new PropertyModel<String>(connInstanceTO, "connRequestTimeout"));
connectorForm.add(connRequestTimeout);
// form - first tab - onchange()
location.getField().add(new AjaxFormComponentUpdatingBehavior("onchange") {
private static final long serialVersionUID = -1107858522700306810L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
((DropDownChoice) location.getField()).setNullValid(false);
connInstanceTO.setLocation(location.getModelObject());
target.add(location);
connectorName.setChoices(new ArrayList<String>(
mapConnBundleTOs.get(location.getModelObject()).keySet()));
connectorName.setEnabled(true);
connectorName.getField().setModelValue(null);
target.add(connectorName);
version.setChoices(new ArrayList<String>());
version.getField().setModelValue(null);
version.setEnabled(false);
target.add(version);
properties.clear();
target.add(propertiesContainer);
}
});
connectorName.getField().add(new AjaxFormComponentUpdatingBehavior("onchange") {
private static final long serialVersionUID = -1107858522700306810L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
((DropDownChoice) connectorName.getField()).setNullValid(false);
connInstanceTO.setBundleName(connectorName.getModelObject());
target.add(connectorName);
List<String> versions = new ArrayList<String>(
mapConnBundleTOs.get(location.getModelObject()).get(connectorName.getModelObject()).keySet());
version.setChoices(versions);
version.setEnabled(true);
if (versions.size() == 1) {
selectVersion(target, connInstanceTO, version, versions.get(0));
version.getField().setModelObject(versions.get(0));
} else {
version.getField().setModelValue(null);
properties.clear();
target.add(propertiesContainer);
}
target.add(version);
}
});
version.getField().add(new AjaxFormComponentUpdatingBehavior("onchange") {
private static final long serialVersionUID = -1107858522700306810L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
selectVersion(target, connInstanceTO, version, version.getModelObject());
}
});
// form - second tab (properties)
final ListView<ConnConfProperty> connPropView = new AltListView<ConnConfProperty>(
"connectorProperties", new PropertyModel<List<ConnConfProperty>>(this, "properties")) {
private static final long serialVersionUID = 9101744072914090143L;
@Override
protected void populateItem(final ListItem<ConnConfProperty> item) {
final ConnConfProperty property = item.getModelObject();
final Label label = new Label("connPropAttrSchema", property.getSchema().getDisplayName() == null
|| property.getSchema().getDisplayName().isEmpty()
? property.getSchema().getName()
: property.getSchema().getDisplayName());
item.add(label);
final FieldPanel field;
boolean required = false;
boolean isArray = false;
if (property.getSchema().isConfidential()
|| GUARDED_STRING.equalsIgnoreCase(property.getSchema().getType())
|| GUARDED_BYTE_ARRAY.equalsIgnoreCase(property.getSchema().getType())) {
field = new AjaxPasswordFieldPanel("panel",
label.getDefaultModelObjectAsString(), new Model<String>());
((PasswordTextField) field.getField()).setResetPassword(false);
required = property.getSchema().isRequired();
} else {
Class<?> propertySchemaClass;
try {
propertySchemaClass =
ClassUtils.forName(property.getSchema().getType(), ClassUtils.getDefaultClassLoader());
} catch (Exception e) {
LOG.error("Error parsing attribute type", e);
propertySchemaClass = String.class;
}
if (ArrayUtils.contains(NUMBER, propertySchemaClass)) {
field = new AjaxNumberFieldPanel("panel",
label.getDefaultModelObjectAsString(), new Model<Number>(),
ClassUtils.resolvePrimitiveIfNecessary(propertySchemaClass));
required = property.getSchema().isRequired();
} else if (Boolean.class.equals(propertySchemaClass) || boolean.class.equals(propertySchemaClass)) {
field = new AjaxCheckBoxPanel("panel",
label.getDefaultModelObjectAsString(), new Model<Boolean>());
} else {
field = new AjaxTextFieldPanel("panel",
label.getDefaultModelObjectAsString(), new Model<String>());
required = property.getSchema().isRequired();
}