Example #1
0
  private Panel createInputComponent(String id, IModel<String> labelModel, Form form) {
    ValueWrapper valueWrapper = valueWrapperModel.getObject();
    ObjectWrapper objectWrapper = null;
    if (valueWrapper.getItem().getContainer() != null) {
      objectWrapper = valueWrapper.getItem().getContainer().getObject();
    }
    Item property = valueWrapper.getItem().getItem();
    boolean required = property.getDefinition().getMinOccurs() > 0;

    Panel component = createTypedInputComponent(id);

    if (component instanceof InputPanel) {
      InputPanel inputPanel = (InputPanel) component;
      // adding valid from/to date range validator, if necessary
      ItemPath activation = new ItemPath(UserType.F_ACTIVATION);
      if (ActivationType.F_VALID_FROM.equals(property.getElementName())) {
        DateValidator validator = getActivationRangeValidator(form, activation);
        validator.setDateFrom((DateTimeField) inputPanel.getBaseFormComponent());
      } else if (ActivationType.F_VALID_TO.equals(property.getElementName())) {
        DateValidator validator = getActivationRangeValidator(form, activation);
        validator.setDateTo((DateTimeField) inputPanel.getBaseFormComponent());
      }

      final List<FormComponent> formComponents = inputPanel.getFormComponents();
      for (FormComponent formComponent : formComponents) {
        formComponent.setLabel(labelModel);
        formComponent.setRequired(required);

        if (formComponent instanceof TextField) {
          formComponent.add(new AttributeModifier("size", "42"));
        }
        formComponent.add(
            new AjaxFormComponentUpdatingBehavior("blur") {

              @Override
              protected void onUpdate(AjaxRequestTarget target) {}
            });

        // Validation occurs when submitting the form
        //            if (form != null) {
        //                AjaxFormValidatingBehavior validator = new
        // AjaxFormValidatingBehavior(form, "Blur");
        //
        //                formComponent.add(validator);
        //            }
      }
    }
    if (component == null) {
      throw new RuntimeException(
          "Cannot create input component for item "
              + property
              + " ("
              + valueWrapper
              + ") in "
              + objectWrapper);
    }
    return component;
  }
Example #2
0
  private boolean isAddButtonVisible() {
    Component inputPanel = this.get(ID_VALUE_CONTAINER).get(ID_INPUT);
    ValueWrapper valueWrapper = valueWrapperModel.getObject();

    if (valueWrapper.isReadonly()) {
      return false;
    }

    ItemWrapper propertyWrapper = valueWrapper.getItem();
    Item property = propertyWrapper.getItem();

    ItemDefinition definition = property.getDefinition();
    int max = definition.getMaxOccurs();
    List<ValueWrapper> usableValues = getUsableValues(propertyWrapper);
    if (usableValues.indexOf(valueWrapper) != usableValues.size() - 1) {
      return false;
    }

    if (max == -1) {
      return true;
    }

    if (countNonDeletedValues(propertyWrapper) >= max) {
      return false;
    }

    if (propertyWrapper.getContainer() == null) {
      return true; // TODO
    }
    return isAccessible(definition, getContainerStatus(propertyWrapper));
  }
Example #3
0
  private boolean isRemoveButtonVisible() {
    ValueWrapper valueWrapper = valueWrapperModel.getObject();

    if (valueWrapper.isReadonly()) {
      return false;
    }
    Component inputPanel = this.get(ID_VALUE_CONTAINER).get(ID_INPUT);
    if (inputPanel instanceof ValueChoosePanel
        || inputPanel instanceof AssociationValueChoicePanel) {
      return true;
    }

    ItemWrapper propertyWrapper = valueWrapper.getItem();
    ItemDefinition definition = propertyWrapper.getItem().getDefinition();
    int min = definition.getMinOccurs();

    int count = countNonDeletedValues(propertyWrapper);
    if (count <= 1 || count <= min) {
      return false;
    }

    if (propertyWrapper.getContainer() == null) {
      return true; // TODO
    }

    return isAccessible(definition, getContainerStatus(propertyWrapper));
  }
Example #4
0
 private void addValue(AjaxRequestTarget target) {
   Component inputPanel = this.get(ID_VALUE_CONTAINER).get(ID_INPUT);
   ValueWrapper wrapper = valueWrapperModel.getObject();
   ItemWrapper propertyWrapper = wrapper.getItem();
   LOGGER.debug("Adding value of {}", propertyWrapper);
   propertyWrapper.addValue();
   ListView parent = findParent(ListView.class);
   target.add(parent.getParent());
 }
Example #5
0
  private void removeValue(AjaxRequestTarget target) {
    ValueWrapper wrapper = valueWrapperModel.getObject();
    ItemWrapper propertyWrapper = wrapper.getItem();
    LOGGER.debug("Removing value of {}", propertyWrapper);

    List<ValueWrapper> values = propertyWrapper.getValues();
    Component inputPanel = this.get(ID_VALUE_CONTAINER).get(ID_INPUT);

    switch (wrapper.getStatus()) {
      case ADDED:
        values.remove(wrapper);
        break;
      case DELETED:
        error("Couldn't delete already deleted item: " + wrapper.toString());
        target.add(((PageBase) getPage()).getFeedbackPanel());
      case NOT_CHANGED:
        if (inputPanel instanceof AssociationValueChoicePanel) {
          ((PropertyWrapper) propertyWrapper).setStatus(ValueStatus.DELETED);
        }
        wrapper.setStatus(ValueStatus.DELETED);
        break;
    }

    //        wrapper.getItem().getContainer().

    int count = countUsableValues(propertyWrapper);
    if (count == 0 && !hasEmptyPlaceholder(propertyWrapper)) {
      if (inputPanel instanceof ValueChoosePanel) {
        values.add(
            new ValueWrapper(propertyWrapper, new PrismReferenceValue(null), ValueStatus.ADDED));
      } else if (inputPanel instanceof AssociationValueChoicePanel) {
        Item item = propertyWrapper.getItem();
        ItemPath path = item.getPath();
        if (path != null) {}

        //                values.add(new ValueWrapper(propertyWrapper, new PrismPropertyValue(null),
        // ValueStatus.ADDED));
      } else {
        values.add(
            new ValueWrapper(propertyWrapper, new PrismPropertyValue(null), ValueStatus.ADDED));
      }
    }
    ListView parent = findParent(ListView.class);
    target.add(parent.getParent());
  }