Exemplo n.º 1
0
 /**
  * Applies the changes made to the edited value into the model. If the {@link #property} is
  * <code>null</code>, a new <code>PropertyAdater</code> will be created, otherwise it will be
  * updated.
  */
 void apply() {
   if (propertyAdapter == null) {
     Property property = (Property) subject();
     propertyAdapter = property.addProperty(name, value);
   } else {
     propertyAdapter.setName(name);
     propertyAdapter.setValue(value);
   }
 }
Exemplo n.º 2
0
    /**
     * Validates the given value and update the enable state of the OK button.
     *
     * @param propertyName Either {@link PropertyEditorView.VALUE_PROPERTY} or {@link
     *     PropertyEditorView.NAME_PROPERTY}
     */
    private void validate(String propertyName) {
      String valueErrorKey = (virtualProperty.value.length() == 0) ? "_EMPTY_VALUE" : null;
      String nameErrorKey = null;

      // A name is required
      if (virtualProperty.name.length() == 0) {
        nameErrorKey = "_EMPTY_NAME";
      }
      // Loop through the existing PropertyAdapters and check if one
      // already exists with the specified name, at the exception of the
      // edited one (during editing and not creation)
      else {
        Property property = (Property) subject();

        for (Iterator iter = property.properties(); iter.hasNext(); ) {
          PropertyAdapter propertyAdapter = (PropertyAdapter) iter.next();

          if ((propertyAdapter != virtualProperty.propertyAdapter)
              && propertyAdapter.getName().equalsIgnoreCase(virtualProperty.name)) {
            nameErrorKey = "_INVALID_NAME";
            break;
          }
        }
      }

      // Create the key
      String errorKey = "LOGIN_PROPERTY_EDITOR";

      if (nameErrorKey != null) errorKey += nameErrorKey;

      if (valueErrorKey != null) errorKey += valueErrorKey;

      // Update the UI
      if ((nameErrorKey == null) && (valueErrorKey == null)) {
        clearErrorMessage();
        getOKAction().setEnabled(true);
      } else {
        setErrorMessage(resourceRepository().getString(errorKey));
        getOKAction().setEnabled(false);
      }
    }