@Override
    public Field createField(Item item, Object propertyId, Component uiContext) {
      Field f;
      if (UserEditProfileData.LOCALE_PROPERTY.equals(propertyId)) {
        return this.localeSelect;
      } else if (UserEditProfileData.ROLE_PROPERTY.equals(propertyId)) {
        return this.roleSelect;
      } else {
        // Use the super class to create a suitable field base on the
        // property type.
        f = super.createField(item, propertyId, uiContext);
        f.addStyleName("gaemvnrepo-form-input");
      }

      if (UserEditProfileData.LOGIN_PROPERTY.equals(propertyId)) {
        TextField tf = (TextField) f;
        tf.setRequired(true);
        tf.setRequiredError(ApplicationData.getMessage("UserEditView.required.login"));
        tf.addValidator(
            new StringLengthValidator(
                ApplicationData.getMessage("UserEditView.invalid.login"), 3, 25, false));
      } else if (UserEditProfileData.EMAIL_PROPERTY.equals(propertyId)) {
        TextField tf = (TextField) f;
        tf.setRequired(true);
        tf.setRequiredError(ApplicationData.getMessage("UserEditView.required.email"));
        tf.addValidator(
            new EmailValidator(ApplicationData.getMessage("UserEditView.invalid.email")));
      }

      return f;
    }
 @Override
 public void discard() throws SourceException {
   super.discard();
   for (Field<?> eachField : fields.values()) {
     eachField.discard();
   }
 }
Exemple #3
0
 public FieldQuery<F> commit() {
   for (Field<?> f : this) {
     // TODO transactionality
     f.commit();
   }
   return createQuery();
 }
Exemple #4
0
 public FieldQuery<F> discard() {
   for (Field<?> f : this) {
     // TODO transactionality
     f.discard();
   }
   return createQuery();
 }
  @Override
  public boolean commitAndValidate() {
    boolean isValid = true;

    for (IUploadComponent upload : uploadFields) {
      if (!upload.isValid()) {
        isValid = false;
      }
    }

    for (Field inputField : inputFields) {
      // remove older component errors first
      if (inputField instanceof AbstractComponent) {
        ((AbstractComponent) inputField).setComponentError(null);
      }
      try {
        // Commit user input to data source
        inputField.commit();
      } catch (EmptyValueException e) {
        isValid = false;
        // set component error if empty is not allowed
        if (inputField instanceof AbstractComponent) {
          ((AbstractComponent) inputField).setComponentError(ERROR_EMPTY);
        }
      } catch (InvalidValueException e) {
        // component error is set automatically
        isValid = false;
      }
    }

    return isValid;
  }
 public Field defaultHandle(Item item, Object propertyId, Component uiContext) {
   Field field = super.createField(item, propertyId, uiContext);
   field.setCaption(captions.get(String.valueOf(propertyId)));
   if (field instanceof TextField) {
     ((TextField) field).setNullRepresentation("");
   }
   return field;
 }
 boolean isDirty() {
   for (Field<?> eachField : fields.values()) {
     if (eachField.isModified()) {
       return true;
     }
   }
   return false;
 }
Exemple #8
0
 public <W> FieldQuery<Field<W>> hasValueType(final Class<W> valueType) {
   Set<Field<W>> result = set();
   for (Field<?> f : this) {
     if (valueType.isAssignableFrom(f.getType())) {
       result.add((Field<W>) f);
     }
   }
   return new FieldQuery<Field<W>>(result);
 }
Exemple #9
0
 /*
  * Override to get control over where fields are placed.
  */
 @Override
 protected void attachField(Object propertyId, Field field) {
   field.setCaption(null);
   if (propertyId.equals("annexNote")) {
     field.setWidth(100, UNITS_PERCENTAGE);
     ourLayout.addComponent(field, 1, 0);
     ourLayout.setColumnExpandRatio(1, 1.0F);
   }
 }
 private void enableField(Field<?> field, boolean enabled) {
   field.setEnabled(enabled);
   // we revert changes, when we disable the fields
   if (!enabled) {
     field.discard();
     // hide validation errors when disabled
     if (field instanceof AbstractComponent) {
       ((AbstractComponent) field).setComponentError(null);
     }
   }
 }
  /**
   * Creates a search field based on an attribute model
   *
   * @param entityModel the entity model of the entity to search for
   * @param attributeModel the attribute model the attribute model of the property that is bound to
   *     the field
   * @return
   */
  protected Field<?> constructField(EntityModel<T> entityModel, AttributeModel attributeModel) {
    Field<?> field = constructCustomField(entityModel, attributeModel);
    if (field == null) {
      EntityModel<?> em = getFieldEntityModel(attributeModel);
      field = getFieldFactory().constructField(attributeModel, getFieldFilters(), em);
    }

    if (field != null) {
      field.setSizeFull();
    }
    return field;
  }
  /** Removes all listeners from the bound fields and unbinds properties. */
  public void unbind() {
    // wrap in array list to avoid CME
    for (Field<?> field : new ArrayList<Field<?>>(getFields())) {
      field.removeValueChangeListener(this);
      if (field instanceof TextChangeNotifier) {
        final TextChangeNotifier abstractTextField = (TextChangeNotifier) field;
        abstractTextField.removeTextChangeListener(this);
      }

      unbind(field);
    }
    fieldsWithInitiallyDisabledValidation.clear();
  }
 /**
  * Sets the value of the current field component.
  *
  * @param value The value to set
  */
 public void setValue(Object value) {
   if (fieldComponent != null) {
     if (fieldComponent instanceof Field) {
       Field field = ((Field) fieldComponent);
       field.setValue(value);
       if (field instanceof Select) {
         ((Select) fieldComponent).select(value);
       }
     } else if (fieldComponent instanceof FilterContainer) {
       ((FilterContainer) fieldComponent).setValue(value);
     }
   }
 }
  /**
   * Configures fields for some better defaults, like property fields annotated with NotNull to be
   * "required" (kind of a special validator in Vaadin)
   */
  public void configureMaddonDefaults() {
    for (Object property : getBoundPropertyIds()) {
      final Field<?> field = getField(property);

      try {

        // Make @NotNull annotated fields "required"
        try {
          java.lang.reflect.Field declaredField = findDeclaredField(property, nonHiddenBeanType);
          final NotNull notNullAnnotation = declaredField.getAnnotation(NotNull.class);
          if (notNullAnnotation != null) {
            field.setRequired(true);
            Locale locale = getLocale();
            if (locale == null) {
              locale = Locale.getDefault();
            }
            String msg =
                getJavaxBeanValidatorFactory()
                    .getMessageInterpolator()
                    .interpolate(
                        notNullAnnotation.message(),
                        new MessageInterpolator.Context() {
                          public ConstraintDescriptor<?> getConstraintDescriptor() {
                            return null;
                          }

                          public Object getValidatedValue() {
                            return null;
                          }

                          public <T> T unwrap(Class<T> type) {
                            return null;
                          }
                        },
                        locale);
            getField(property).setRequiredError(msg);
          }
        } catch (NoSuchFieldException ex) {
          Logger.getLogger(MBeanFieldGroup.class.getName()).log(Level.FINE, null, ex);
        } catch (SecurityException ex) {
          Logger.getLogger(MBeanFieldGroup.class.getName()).log(Level.SEVERE, null, ex);
        }
      } catch (Throwable e) {
        if (e instanceof java.lang.ClassNotFoundException) {
          Logger.getLogger(MBeanFieldGroup.class.getName())
              .log(Level.FINE, "Validation API not available.");
        }
      }
    }
  }
    @Override
    protected Field createField(Object propertyId, String caption) {

      if (RelatedProjectsExt.PROPERTY_CALCULATED.equals(propertyId)) {
        final CheckBox field = new CheckBox(caption);
        field.setImmediate(true);
        field.addListener(
            new ValueChangeListener() {

              private static final long serialVersionUID = 3996507266934851419L;

              @Override
              public void valueChange(com.vaadin.data.Property.ValueChangeEvent event) {
                if (comboBox != null) {
                  comboBox.setEnabled(!field.booleanValue());
                }
              }
            });
        return field;
      } else if (RelatedProjectsExt.PROPERTY_RELATED_PROJECT.equals(propertyId)) {
        UUIDList ids = extension.getRelatedProjects();
        comboBox = new MultiComboBox(caption, ids);
        comboBox.setEnabled(!extension.getCalculated());
        return comboBox;
      }
      return null;
    }
 /**
  * Makes all fields "immediate" to trigger eager validation
  *
  * @param listener a listener that will be notified when a field in the group has been modified
  * @return the MBeanFieldGroup that can be used for further modifications or e.g. commit if
  *     buffered
  */
 public MBeanFieldGroup<T> withEagerValidation(FieldGroupListener<T> listener) {
   this.listener = listener;
   for (Field<?> field : getFields()) {
     ((AbstractComponent) field).setImmediate(true);
     field.addValueChangeListener(this);
     if (field instanceof EagerValidateable) {
       EagerValidateable ev = (EagerValidateable) field;
       ev.setEagerValidation(true);
     }
     if (field instanceof TextChangeNotifier) {
       final TextChangeNotifier abstractTextField = (TextChangeNotifier) field;
       abstractTextField.addTextChangeListener(this);
     }
   }
   return this;
 }
 /**
  * Invokes the validation of the current field component. Adds the error style on validation
  * exception.
  */
 public void validate() {
   try {
     if (fieldComponent instanceof Field) {
       ((Field) fieldComponent).validate();
     } else if (fieldComponent instanceof FilterContainer) {
       ((FilterContainer) fieldComponent).validate();
     }
   } catch (InvalidValueException e) {
     if (fieldComponent instanceof Field) {
       ((Field) fieldComponent).addStyleName("error");
       ((Field) fieldComponent).removeStyleName("error");
     } else if (fieldComponent instanceof FilterContainer) {
       ((FilterContainer) fieldComponent).addStyleName("error");
       ((FilterContainer) fieldComponent).removeStyleName("error");
     }
   }
 }
 /**
  * Adds a validator to the current field component.
  *
  * @param validator A Vaadin validator
  */
 public void addValidator(Validator validator) {
   if (fieldComponent != null) {
     if (fieldComponent instanceof Field) {
       ((Field) fieldComponent).addValidator(validator);
     } else if (fieldComponent instanceof FilterContainer) {
       ((FilterContainer) fieldComponent).addValidator(validator);
     }
   }
 }
  private DocumentFormImpl newForm() {
    recordForm =
        new DocumentFormImpl(recordVO) {
          @Override
          protected void saveButtonClick(RecordVO viewObject) throws ValidationException {
            presenter.saveButtonClicked();
          }

          @Override
          protected void cancelButtonClick(RecordVO viewObject) {
            presenter.cancelButtonClicked();
          }

          @Override
          public void reload() {
            recordForm = newForm();
            AddEditDocumentViewImpl.this.replaceComponent(this, recordForm);
          }

          @Override
          public void commit() {
            for (Field<?> field : fieldGroup.getFields()) {
              try {
                field.commit();
              } catch (SourceException | InvalidValueException e) {
              }
            }
          }
        };

    for (final Field<?> field : recordForm.getFields()) {
      if (field instanceof CustomDocumentField) {
        field.addValueChangeListener(
            new ValueChangeListener() {
              @Override
              public void valueChange(ValueChangeEvent event) {
                presenter.customFieldValueChanged((CustomDocumentField<?>) field);
              }
            });
      }
    }

    return recordForm;
  }
  /**
   * Constructs a filter group for searching on a single attribute
   *
   * @param entityModel the entity model
   * @param attributeModel the attribute model
   * @return
   */
  protected FilterGroup constructFilterGroup(
      EntityModel<T> entityModel, AttributeModel attributeModel) {
    Field<?> field = this.constructField(entityModel, attributeModel);
    if (field != null) {
      FilterType filterType = FilterType.BETWEEN;
      if (String.class.isAssignableFrom(attributeModel.getType())) {
        filterType = FilterType.LIKE;
      } else if (Boolean.class.isAssignableFrom(attributeModel.getType())
          || Boolean.TYPE.isAssignableFrom(attributeModel.getType())) {
        filterType = FilterType.BOOLEAN;
      } else if (attributeModel.getType().isEnum()) {
        filterType = FilterType.ENUM;
      } else if (AbstractEntity.class.isAssignableFrom(attributeModel.getType())
          || AttributeType.DETAIL.equals(attributeModel.getAttributeType())) {
        // search for an entity
        filterType = FilterType.ENTITY;
      } else if (attributeModel.isSearchForExactValue()) {
        filterType = FilterType.EQUAL;
      }

      Component comp = field;
      Field<?> auxField = null;
      if (FilterType.BETWEEN.equals(filterType)) {
        // in case of a between value, construct two fields for the
        // lower
        // and upper bounds
        String from = message("ocs.from");
        field.setCaption(attributeModel.getDisplayName() + " " + from);
        auxField = constructField(entityModel, attributeModel);
        String to = message("ocs.to");
        auxField.setCaption(attributeModel.getDisplayName() + " " + to);
        auxField.setVisible(true);
        HorizontalLayout layout = new DefaultHorizontalLayout();
        layout.setSizeFull();
        layout.addComponent(field);
        layout.addComponent(auxField);
        comp = layout;
      }
      return new FilterGroup(
          attributeModel, attributeModel.getPath(), filterType, comp, field, auxField);
    }
    return null;
  }
 public boolean validate() {
   try {
     binder_Revaloriza.commit();
     return true;
   } catch (CommitException ex) {
     Map<Field<?>, InvalidValueException> invalid_fields = ex.getInvalidFields();
     Iterator<Field<?>> it = invalid_fields.keySet().iterator();
     while (it.hasNext()) {
       Field<?> key = (Field<?>) it.next();
       mensajes.add(
           new BarMessage(
               key.getCaption(),
               invalid_fields.get(key).getMessage() == ""
                   ? Messages.EMPTY_MESSAGE
                   : invalid_fields.get(key).getMessage()));
     }
     return false;
   }
 }
  @Override
  protected void attachField(Object propertyId, Field field) {
    PhysicalAttributeConfirmActualsFieldSetComponent fieldSet =
        ((CollapsiblePhysicalAttributeConfirmActualsFormComponent) getComponentModel())
            .getFieldSetForField((String) propertyId);
    if (fieldSet != null) {
      PhysicalAttributeConfirmActualsFieldSetFieldComponent fieldComponent =
          fieldSet.getFieldSetField((String) propertyId);
      if (fieldComponent != null) {
        fields.put(field, fieldComponent);
        field.setWidth("100%");
        VaadinFormFieldAugmenter.augment(field, fieldComponent);
        if (this.getComponentModel().isReadOnly()) {
          field.setReadOnly(true);
        }
        VaadinCollapsiblePhysicalAttributeConfirmActualsFormSectionHeader header =
            headers.get(fieldSet);
        if (header == null) {
          header = addFormSection(fieldSet);
        }

        GridLayout gridLayout = (GridLayout) header.getLayout();
        Integer index = fieldIndexMap.get(fieldComponent);
        if (index == null) {
          index = getNextIndex(gridLayout);
          fieldIndexMap.put(fieldComponent, index);
        }
        allocateIndex(gridLayout, index);

        Label label = new Label(fieldComponent.getCaption());
        label.setStyleName("conx-confirm-actuals-field-caption");
        label.setWidth("100%");
        addCaptionLabel(gridLayout, index, label);

        if (fieldSet.isExpected(propertyId)) {
          field.setEnabled(false);
          field.setCaption(null);
          addExpectedField(gridLayout, index, field);
        } else if (fieldSet.isActual(propertyId)) {
          field.setCaption(null);
          addActualField(gridLayout, index, field);
        } else if (fieldSet.isActualUnit(propertyId)) {
          field.setCaption(null);
          addActualUnitField(gridLayout, index, field);
        } else if (fieldSet.isExpectedUnit(propertyId)) {
          field.setCaption(null);
          field.setEnabled(false);
          addExpectedUnitField(gridLayout, index, field);
        }
      }
    }
  }
  @Override
  public boolean saveForm() {
    LinkedList<SourceException> problems = null;

    // Only commit on valid state if so requested
    if (!isInvalidCommitted() && !isValid()) {
      validate();
    }

    Set<Field> fieldSet = fields.keySet();

    // Try to commit all
    for (Field field : fieldSet) {
      try {
        // Commit only non-readonly fields.
        if (!field.isReadOnly()) {
          field.commit();
        }
      } catch (final Buffered.SourceException e) {
        if (problems == null) {
          problems = new LinkedList<SourceException>();
        }
        problems.add(e);
      }
    }

    // No problems occurred
    if (problems == null) {
      this.alertPanel.setAlertType(AlertType.SUCCESS);
      this.alertPanel.setMessage(this.header.getTitle() + " was saved successfully.");
      this.alertPanel.setVisible(true);
      return true;
    } else {
      this.alertPanel.setAlertType(AlertType.ERROR);
      this.alertPanel.setMessage(problems.iterator().next().getMessage());
      this.alertPanel.setVisible(true);
      return false;
    }
  }
 @Override
 public boolean validateForm() {
   boolean firstErrorFound = false;
   Set<PhysicalAttributeConfirmActualsFieldSetComponent> formFieldHeaders = headers.keySet();
   for (PhysicalAttributeConfirmActualsFieldSetComponent fieldSet : formFieldHeaders) {
     headers.get(fieldSet).removeStyleName("conx-form-header-error");
   }
   Set<Field> formFields = fields.keySet();
   for (Field field : formFields) {
     VaadinCollapsiblePhysicalAttributeConfirmActualsFormSectionHeader formFieldHeader =
         getFieldHeader(field);
     if (formFieldHeader != null) {
       try {
         field.validate();
         field.removeStyleName("conx-form-field-error");
       } catch (InvalidValueException e) {
         field.addStyleName("conx-form-field-error");
         formFieldHeader.addStyleName("conx-form-header-error");
         if (!firstErrorFound) {
           this.alertPanel.setMessage(e.getMessage());
           this.alertPanel.setVisible(true);
           firstErrorFound = true;
         }
       }
     }
   }
   if (firstErrorFound) {
     //			this.verifyButton.setEnabled(false);
     return false;
   } else {
     this.alertPanel.setVisible(false);
     //			this.verifyButton.setEnabled(false);
     //			this.saveButton.setEnabled(true);
     this.alertPanel.setAlertType(AlertType.SUCCESS);
     this.alertPanel.setMessage(this.header.getTitle() + " is valid.");
     this.alertPanel.setVisible(true);
     return true;
   }
 }
Exemple #25
0
 public void buttonClick(ClickEvent event) {
   Field name = form.getField("name");
   Field prenom = form.getField("prenom");
   Field age = form.getField("age");
   name.setValue("");
   prenom.setValue("");
   age.setValue("");
 }
Exemple #26
0
 @Override
 protected Layout addFields(FieldGroup fieldGroup) {
   Layout l = super.addFields(fieldGroup);
   Field id = (Field) fieldGroup.getField("id");
   id.setRequired(true);
   id.setRequiredError(getApp().getMessage("errorMessage.req", id.getCaption()));
   String idValue = (String) fieldGroup.getItemDataSource().getItemProperty("id").getValue();
   // Hide prefix
   if (idValue != null) { // Means it is not a new sysconfig entry
     id.setReadOnly(false);
     idValue = prefix != null ? idValue.substring(prefix.length()) : idValue;
     id.setValue(idValue);
     id.setReadOnly(true);
   }
   return l;
 }
Exemple #27
0
 public FieldQuery<F> removeValidator(Validator v) {
   for (Field<?> f : this) {
     f.removeValidator(v);
   }
   return createQuery();
 }
Exemple #28
0
 public FieldQuery<F> setRequiredError(String error) {
   for (Field<?> f : this) {
     f.setRequiredError(error);
   }
   return createQuery();
 }
Exemple #29
0
 public FieldQuery<F> setBuffered(boolean buffered) {
   for (Field<?> f : this) {
     f.setBuffered(buffered);
   }
   return createQuery();
 }
Exemple #30
0
 public FieldQuery<F> setRequired(boolean required) {
   for (Field<?> f : this) {
     f.setRequired(required);
   }
   return createQuery();
 }