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 boolean hasChanged() { for (ItemWrapper item : getItems()) { if (item.hasChanged()) { return true; } } return false; }
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 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()); }
private boolean hasEmptyPlaceholder( ItemWrapper<? extends Item, ? extends ItemDefinition> property) { for (ValueWrapper value : property.getValues()) { value.normalize(property.getItemDefinition().getPrismContext()); if (ValueStatus.ADDED.equals(value.getStatus()) && !value.hasValueChanged()) { return true; } } return false; }
private int countNonDeletedValues( ItemWrapper<? extends Item, ? extends ItemDefinition> property) { int count = 0; for (ValueWrapper value : property.getValues()) { value.normalize(property.getItemDefinition().getPrismContext()); if (ValueStatus.DELETED.equals(value.getStatus())) { continue; } count++; } return count; }
public void revive(PrismContext prismContext) throws SchemaException { if (container != null) { container.revive(prismContext); } if (containerDefinition != null) { containerDefinition.revive(prismContext); } if (properties != null) { for (ItemWrapper itemWrapper : properties) { itemWrapper.revive(prismContext); } } }
private List<ValueWrapper> getUsableValues( ItemWrapper<? extends Item, ? extends ItemDefinition> property) { List<ValueWrapper> values = new ArrayList<>(); for (ValueWrapper value : property.getValues()) { value.normalize(property.getItemDefinition().getPrismContext()); if (ValueStatus.DELETED.equals(value.getStatus())) { continue; } values.add(value); } return values; }
boolean isItemVisible(ItemWrapper item) { ItemDefinition def = item.getItemDefinition(); if (def.isIgnored() || def.isOperational()) { return false; } if (def instanceof PrismPropertyDefinition && skipProperty((PrismPropertyDefinition) def)) { return false; } // we decide not according to status of this container, but according to // the status of the whole object if (objectWrapper.getStatus() == ContainerStatus.ADDING) { return def.canAdd(); } // otherwise, object.getStatus() is MODIFYING if (def.canModify()) { return showEmpty(item); } else { if (def.canRead()) { return showEmpty(item); } return false; } }
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()); }
private boolean showEmpty(ItemWrapper item) { ObjectWrapper objectWrapper = getObject(); List<ValueWrapper> valueWrappers = item.getValues(); boolean isEmpty; if (valueWrappers == null) { isEmpty = true; } else { isEmpty = valueWrappers.isEmpty(); } if (!isEmpty && valueWrappers.size() == 1) { ValueWrapper value = valueWrappers.get(0); if (ValueStatus.ADDED.equals(value.getStatus())) { isEmpty = true; } } return objectWrapper.isShowEmpty() || !isEmpty; }
private ContainerStatus getContainerStatus(ItemWrapper propertyWrapper) { final ObjectWrapper objectWrapper = propertyWrapper.getContainer().getObject(); return objectWrapper != null ? objectWrapper.getStatus() : ContainerStatus.MODIFYING; }