use of org.apache.syncope.client.console.wicket.markup.html.form.AjaxCheckBoxPanel in project syncope by apache.
the class BeanPanel method buildSinglePanel.
@SuppressWarnings({ "unchecked", "rawtypes" })
private FieldPanel buildSinglePanel(final Serializable bean, final Class<?> type, final String fieldName, final String id) {
FieldPanel result = null;
PropertyModel model = new PropertyModel(bean, fieldName);
if (ClassUtils.isAssignable(Boolean.class, type)) {
result = new AjaxCheckBoxPanel(id, fieldName, model);
} else if (ClassUtils.isAssignable(Number.class, type)) {
result = new AjaxSpinnerFieldPanel.Builder<>().build(id, fieldName, (Class<Number>) ClassUtils.resolvePrimitiveIfNecessary(type), model);
} else if (Date.class.equals(type)) {
result = new AjaxDateTimeFieldPanel(id, fieldName, model, SyncopeConstants.DEFAULT_DATE_PATTERN);
} else if (type.isEnum()) {
result = new AjaxDropDownChoicePanel(id, fieldName, model).setChoices(Arrays.asList(type.getEnumConstants()));
}
// treat as String if nothing matched above
if (result == null) {
result = new AjaxTextFieldPanel(id, fieldName, model);
}
result.hideLabel();
return result;
}
use of org.apache.syncope.client.console.wicket.markup.html.form.AjaxCheckBoxPanel in project syncope by apache.
the class ConnConfPropertyListView method populateItem.
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void populateItem(final ListItem<ConnConfProperty> item) {
final ConnConfProperty property = item.getModelObject();
final String label = StringUtils.isBlank(property.getSchema().getDisplayName()) ? property.getSchema().getName() : property.getSchema().getDisplayName();
final FieldPanel<? extends Serializable> field;
boolean required = false;
boolean isArray = false;
if (property.getSchema().isConfidential() || Constants.GUARDED_STRING.equalsIgnoreCase(property.getSchema().getType()) || Constants.GUARDED_BYTE_ARRAY.equalsIgnoreCase(property.getSchema().getType())) {
field = new AjaxPasswordFieldPanel("panel", label, new Model<>(), false);
((PasswordTextField) field.getField()).setResetPassword(false);
required = property.getSchema().isRequired();
} else {
Class<?> propertySchemaClass;
try {
propertySchemaClass = ClassUtils.getClass(property.getSchema().getType());
if (ClassUtils.isPrimitiveOrWrapper(propertySchemaClass)) {
propertySchemaClass = org.apache.commons.lang3.ClassUtils.primitiveToWrapper(propertySchemaClass);
}
} catch (ClassNotFoundException e) {
LOG.error("Error parsing attribute type", e);
propertySchemaClass = String.class;
}
if (ClassUtils.isAssignable(Number.class, propertySchemaClass)) {
@SuppressWarnings("unchecked") Class<Number> numberClass = (Class<Number>) propertySchemaClass;
field = new AjaxSpinnerFieldPanel.Builder<>().build("panel", label, numberClass, new Model<>());
required = property.getSchema().isRequired();
} else if (ClassUtils.isAssignable(Boolean.class, propertySchemaClass)) {
field = new AjaxCheckBoxPanel("panel", label, new Model<>());
} else {
field = new AjaxTextFieldPanel("panel", label, new Model<>());
required = property.getSchema().isRequired();
}
if (propertySchemaClass.isArray()) {
isArray = true;
}
}
field.setIndex(item.getIndex());
field.setTitle(property.getSchema().getHelpMessage(), true);
final AbstractFieldPanel<? extends Serializable> fieldPanel;
if (isArray) {
final MultiFieldPanel multiFieldPanel = new MultiFieldPanel.Builder(new PropertyModel<>(property, "values")).setEventTemplate(true).build("panel", label, field);
item.add(multiFieldPanel);
fieldPanel = multiFieldPanel;
} else {
setNewFieldModel(field, property.getValues());
item.add(field);
fieldPanel = field;
}
if (required) {
fieldPanel.addRequiredLabel();
}
if (withOverridable) {
fieldPanel.showExternAction(addCheckboxToggle(property));
}
}
use of org.apache.syncope.client.console.wicket.markup.html.form.AjaxCheckBoxPanel in project syncope by apache.
the class PlainAttrs method getFieldPanel.
@SuppressWarnings({ "rawtypes", "unchecked" })
protected FieldPanel getFieldPanel(final PlainSchemaTO schemaTO) {
final boolean required;
final boolean readOnly;
final AttrSchemaType type;
final boolean jexlHelp;
if (mode == AjaxWizard.Mode.TEMPLATE) {
required = false;
readOnly = false;
type = AttrSchemaType.String;
jexlHelp = true;
} else {
required = schemaTO.getMandatoryCondition().equalsIgnoreCase("true");
readOnly = schemaTO.isReadonly();
type = schemaTO.getType();
jexlHelp = false;
}
FieldPanel panel;
switch(type) {
case Boolean:
panel = new AjaxCheckBoxPanel("panel", schemaTO.getKey(), new Model<>(), true);
panel.setRequired(required);
break;
case Date:
String dataPattern = schemaTO.getConversionPattern() == null ? SyncopeConstants.DEFAULT_DATE_PATTERN : schemaTO.getConversionPattern();
if (dataPattern.contains("H")) {
panel = new AjaxDateTimeFieldPanel("panel", schemaTO.getKey(), new Model<>(), dataPattern);
} else {
panel = new AjaxDateFieldPanel("panel", schemaTO.getKey(), new Model<>(), dataPattern);
}
if (required) {
panel.addRequiredLabel();
}
break;
case Enum:
panel = new AjaxDropDownChoicePanel<>("panel", schemaTO.getKey(), new Model<>(), true);
((AjaxDropDownChoicePanel<String>) panel).setChoices(SchemaUtils.getEnumeratedValues(schemaTO));
if (StringUtils.isNotBlank(schemaTO.getEnumerationKeys())) {
((AjaxDropDownChoicePanel) panel).setChoiceRenderer(new IChoiceRenderer<String>() {
private static final long serialVersionUID = -3724971416312135885L;
private final Map<String, String> valueMap = SchemaUtils.getEnumeratedKeyValues(schemaTO);
@Override
public String getDisplayValue(final String value) {
return valueMap.get(value) == null ? value : valueMap.get(value);
}
@Override
public String getIdValue(final String value, final int i) {
return value;
}
@Override
public String getObject(final String id, final IModel<? extends List<? extends String>> choices) {
return id;
}
});
}
if (required) {
panel.addRequiredLabel();
}
break;
case Long:
panel = new AjaxSpinnerFieldPanel.Builder<Long>().enableOnChange().build("panel", schemaTO.getKey(), Long.class, new Model<Long>());
if (required) {
panel.addRequiredLabel();
}
break;
case Double:
panel = new AjaxSpinnerFieldPanel.Builder<Double>().enableOnChange().step(0.1).build("panel", schemaTO.getKey(), Double.class, new Model<Double>());
if (required) {
panel.addRequiredLabel();
}
break;
case Binary:
final PageReference pageReference = getPageReference();
panel = new BinaryFieldPanel("panel", schemaTO.getKey(), new Model<>(), schemaTO.getMimeType(), fileKey) {
private static final long serialVersionUID = -3268213909514986831L;
@Override
protected PageReference getPageReference() {
return pageReference;
}
};
if (required) {
panel.addRequiredLabel();
}
break;
case Encrypted:
panel = new EncryptedFieldPanel("panel", schemaTO.getKey(), new Model<>(), true);
if (required) {
panel.addRequiredLabel();
}
break;
default:
panel = new AjaxTextFieldPanel("panel", schemaTO.getKey(), new Model<>(), true);
if (jexlHelp) {
AjaxTextFieldPanel.class.cast(panel).enableJexlHelp();
}
if (required) {
panel.addRequiredLabel();
}
}
panel.setReadOnly(readOnly);
return panel;
}
Aggregations