コード例 #1
0
  @Override
  @SuppressWarnings({"unchecked", "rawtypes"})
  protected void populateItem(final ListItem<ConnConfProperty> item) {
    final ConnConfProperty property = item.getModelObject();

    final Label label =
        new Label(
            "connPropAttrSchema",
            StringUtils.isBlank(property.getSchema().getDisplayName())
                ? property.getSchema().getName()
                : property.getSchema().getDisplayName());
    item.add(label);

    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.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());
        if (ClassUtils.isPrimitiveOrWrapper(propertySchemaClass)) {
          propertySchemaClass =
              org.apache.commons.lang3.ClassUtils.primitiveToWrapper(propertySchemaClass);
        }
      } catch (Exception e) {
        LOG.error("Error parsing attribute type", e);
        propertySchemaClass = String.class;
      }

      if (ClassUtils.isAssignable(Number.class, propertySchemaClass)) {
        @SuppressWarnings("unchecked")
        final Class<Number> numberClass = (Class<Number>) propertySchemaClass;
        field =
            new SpinnerFieldPanel<Number>(
                "panel",
                label.getDefaultModelObjectAsString(),
                numberClass,
                new Model<Number>(),
                null,
                null);

        required = property.getSchema().isRequired();
      } else if (ClassUtils.isAssignable(Boolean.class, propertySchemaClass)) {
        field =
            new AjaxCheckBoxPanel(
                "panel", label.getDefaultModelObjectAsString(), new Model<Boolean>());
      } else {
        field =
            new AjaxTextFieldPanel(
                "panel", label.getDefaultModelObjectAsString(), new Model<String>());

        required = property.getSchema().isRequired();
      }

      if (propertySchemaClass.isArray()) {
        isArray = true;
      }
    }

    field.setTitle(property.getSchema().getHelpMessage());

    if (required) {
      field.addRequiredLabel();
    }

    if (isArray) {
      if (property.getValues().isEmpty()) {
        property.getValues().add(null);
      }

      final MultiFieldPanel multiFieldPanel =
          new MultiFieldPanel("panel", new PropertyModel<List<String>>(property, "values"), field);
      item.add(multiFieldPanel);
    } else {
      setNewFieldModel(field, property.getValues());
      item.add(field);
    }

    if (withOverridable) {
      item.add(
          new AjaxCheckBoxPanel(
              "connPropAttrOverridable",
              "connPropAttrOverridable",
              new PropertyModel<Boolean>(property, "overridable")));
    }

    configuration.add(property);
  }
コード例 #2
0
 @SuppressWarnings({"unchecked", "rawtypes"})
 private void setNewFieldModel(final FieldPanel field, final List<Object> values) {
   field.setNewModel(values);
 }