private boolean isAddButtonVisible() {
    ValueWrapper valueWrapper = model.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;
    }

    return isAccessible(definition, propertyWrapper.getContainer().getObject().getStatus());
  }
  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));
  }
  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));
  }
 public ItemWrapper findPropertyWrapper(QName name) {
   Validate.notNull(name, "QName must not be null.");
   for (ItemWrapper wrapper : getItems()) {
     if (name.equals(wrapper.getItem().getElementName())) {
       return wrapper;
     }
   }
   return null;
 }
  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());
  }
Exemple #6
0
  private ObjectDelta createAddingObjectDelta() throws SchemaException {
    PrismObject object = this.object.clone();

    List<ContainerWrapper> containers = getContainers();
    // sort containers by path size
    Collections.sort(containers, new PathSizeComparator());

    for (ContainerWrapper containerWrapper : getContainers()) {

      if (containerWrapper.getItemDefinition().getName().equals(ShadowType.F_ASSOCIATION)) {
        PrismContainer associationContainer =
            object.findOrCreateContainer(ShadowType.F_ASSOCIATION);
        List<AssociationWrapper> associationItemWrappers =
            (List<AssociationWrapper>) containerWrapper.getItems();
        for (AssociationWrapper associationItemWrapper : associationItemWrappers) {
          List<ValueWrapper> assocValueWrappers = associationItemWrapper.getValues();
          for (ValueWrapper assocValueWrapper : assocValueWrappers) {
            PrismContainerValue<ShadowAssociationType> assocValue =
                (PrismContainerValue<ShadowAssociationType>) assocValueWrapper.getValue();
            associationContainer.add(assocValue.clone());
          }
        }
        continue;
      }

      if (!containerWrapper.hasChanged()) {
        continue;
      }

      PrismContainer container = containerWrapper.getItem();
      ItemPath path = containerWrapper.getPath();
      if (containerWrapper.getPath() != null) {
        container = container.clone();
        if (path.size() > 1) {
          ItemPath parentPath = path.allExceptLast();
          PrismContainer parent = object.findOrCreateContainer(parentPath);
          parent.add(container);
        } else {
          PrismContainer existing = object.findContainer(container.getElementName());
          if (existing == null) {
            object.add(container);
          } else {
            continue;
          }
        }
      } else {
        container = object;
      }

      for (ItemWrapper propertyWrapper : (List<ItemWrapper>) containerWrapper.getItems()) {
        if (!propertyWrapper.hasChanged()) {
          continue;
        }

        Item property = propertyWrapper.getItem().clone();
        if (container.findProperty(property.getElementName()) != null) {
          continue;
        }
        for (ValueWrapper valueWrapper : propertyWrapper.getValues()) {
          valueWrapper.normalize(object.getPrismContext());
          if (!valueWrapper.hasValueChanged()
              || ValueStatus.DELETED.equals(valueWrapper.getStatus())) {
            continue;
          }

          if (property.hasRealValue(valueWrapper.getValue())) {
            continue;
          }

          PrismValue cloned = clone(valueWrapper.getValue());
          if (cloned != null) {
            property.add(cloned);
          }
        }

        if (!property.isEmpty()) {
          container.add(property);
        }
      }
    }

    // cleanup empty containers
    cleanupEmptyContainers(object);

    ObjectDelta delta = ObjectDelta.createAddDelta(object);

    // returning container to previous order
    Collections.sort(containers, new ItemWrapperComparator());

    if (InternalsConfig.consistencyChecks) {
      delta.checkConsistence(true, true, true, ConsistencyCheckScope.THOROUGH);
    }

    return delta;
  }