@SuppressWarnings("unchecked") protected void removeFromProperty(Object proxy, ICollectionPropertyDescriptor<?> propertyDescriptor, Object value) { String propertyName = propertyDescriptor.getName(); try { if (propertyProcessorsEnabled) { propertyDescriptor.preprocessRemover(proxy, collectionProperty, value); IRelationshipEndPropertyDescriptor reversePropertyDescriptor = propertyDescriptor.getReverseRelationEnd(); if (reversePropertyDescriptor != null) { if (reversePropertyDescriptor instanceof IReferencePropertyDescriptor<?>) { accessorFactory.createPropertyAccessor(reversePropertyDescriptor.getName(), propertyDescriptor.getReferencedDescriptor().getElementDescriptor().getComponentContract()).setValue( value, null); } else if (reversePropertyDescriptor instanceof ICollectionPropertyDescriptor<?>) { ICollectionAccessor collectionAccessor = accessorFactory.createCollectionPropertyAccessor( reversePropertyDescriptor.getName(), propertyDescriptor.getReferencedDescriptor().getElementDescriptor().getComponentContract(), ((ICollectionPropertyDescriptor<?>) reversePropertyDescriptor).getCollectionDescriptor() .getElementDescriptor() .getComponentContract()); if (collectionProperty.remove(value)) { if (EntityHelper.isInlineComponentReference( propertyDescriptor.getReferencedDescriptor().getElementDescriptor())) { if (value != null) { ((IComponent) value).setOwningComponent(null, null); doFirePropertyChange(proxy, propertyName, oldCollectionSnapshot, collectionProperty); if (propertyProcessorsEnabled) {
&& !propertyValue.isEmpty() && !List.class.isAssignableFrom(propertyDescriptor .getCollectionDescriptor().getCollectionInterface())) { List<String> orderingProperties = propertyDescriptor .getOrderingProperties(); if (orderingProperties != null && !orderingProperties.isEmpty()) { BeanComparator comparator = new BeanComparator(); List<IAccessor> orderingAccessors = new ArrayList<IAccessor>(); Class collectionElementContract = propertyDescriptor .getCollectionDescriptor().getElementDescriptor() .getComponentContract(); for (String orderingProperty : orderingProperties) {
/** * {@inheritDoc} */ @Override public void removeFromValue(Object target, Object value) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { Collection<Object> mapValue = getValue(target); // target instance must be tested to avoid triggering twice the property // processors if the map contains a non-map model. if (target instanceof Map<?, ?> && getModelDescriptor() != null) { getModelDescriptor().preprocessRemover(this, mapValue, value); } if (mapValue != null) { mapValue.remove(value); // to trigger a propertyChange. setValue(target, mapValue); } // target instance must be tested to avoid triggering twice the property // processors if the map contains a non-map model. if (target instanceof Map<?, ?> && getModelDescriptor() != null) { getModelDescriptor().postprocessRemover(this, mapValue, value); } }
protected Object getCollectionProperty(Object proxy, ICollectionPropertyDescriptor<? extends IComponent> propertyDescriptor) { String propertyName = propertyDescriptor.getName(); try { Object property = straightGetProperty(proxy, propertyName); if (property == null) { property = collectionFactory.createComponentCollection( propertyDescriptor.getReferencedDescriptor().getCollectionInterface()); storeProperty(propertyName, property); IComponent referent = propertyAsList.get(i); IComponent decorated = decorateReferent(referent, propertyDescriptor.getReferencedDescriptor().getElementDescriptor().getComponentDescriptor()); if (decorated != referent) { propertyAsList.set(i, decorated); propertyDescriptor.getReferencedDescriptor().getElementDescriptor())) { if (decorated != null) { decorated.setOwningComponent((IComponent) proxy, propertyDescriptor); for (IComponent referent : new THashSet<>(propertyAsSet)) { IComponent decorated = decorateReferent(referent, propertyDescriptor.getReferencedDescriptor().getElementDescriptor().getComponentDescriptor()); if (decorated != referent) { propertyAsSet.add(decorated); propertyDescriptor.getReferencedDescriptor().getElementDescriptor())) { if (decorated != null) { decorated.setOwningComponent((IComponent) proxy, propertyDescriptor);
@SuppressWarnings("unchecked") protected void addToProperty(Object proxy, ICollectionPropertyDescriptor<?> propertyDescriptor, int index, Object value) { String propertyName = propertyDescriptor.getName(); Collection<Object> collectionProperty = (Collection<Object>) straightGetProperty(proxy, propertyName); if (value instanceof IEntity && collectionProperty.contains(value)) { propertyDescriptor.preprocessAdder(proxy, collectionProperty, value); IRelationshipEndPropertyDescriptor reversePropertyDescriptor = propertyDescriptor.getReverseRelationEnd(); if (reversePropertyDescriptor != null) { if (reversePropertyDescriptor instanceof IReferencePropertyDescriptor<?>) { accessorFactory.createPropertyAccessor(reversePropertyDescriptor.getName(), propertyDescriptor.getReferencedDescriptor().getElementDescriptor().getComponentContract()).setValue( value, proxy); } else if (reversePropertyDescriptor instanceof ICollectionPropertyDescriptor<?>) { ICollectionAccessor collectionAccessor = accessorFactory.createCollectionPropertyAccessor( reversePropertyDescriptor.getName(), propertyDescriptor.getReferencedDescriptor().getElementDescriptor().getComponentContract(), ((ICollectionPropertyDescriptor<?>) reversePropertyDescriptor).getCollectionDescriptor() .getElementDescriptor() .getComponentContract()); propertyDescriptor.getReferencedDescriptor().getElementDescriptor())) { if (value != null) { ((IComponent) value).setOwningComponent((IComponent) proxy, propertyDescriptor); doFirePropertyChange(proxy, propertyName, oldCollectionSnapshot, collectionProperty); if (propertyProcessorsEnabled) { propertyDescriptor.postprocessAdder(proxy, collectionProperty, value);
ICollectionPropertyDescriptor<?> collectionDescriptor = collectionEntry.getValue(); Class<?> masterContract = null; if (collectionDescriptor.getReverseRelationEnd() instanceof IReferencePropertyDescriptor<?>) { masterContract = ((IReferencePropertyDescriptor<?>) collectionDescriptor.getReverseRelationEnd()) .getReferencedDescriptor().getComponentContract(); } else if (collectionDescriptor.getReverseRelationEnd() instanceof ICollectionPropertyDescriptor<?>) { masterContract = ((ICollectionPropertyDescriptor<?>) collectionDescriptor.getReverseRelationEnd()) .getReferencedDescriptor().getElementDescriptor().getComponentContract(); collectionDescriptor.getName(), masterContract, getComponentContract(clonedComponent)); if (collectionAccessor instanceof IModelDescriptorAware) { ((IModelDescriptorAware) collectionAccessor).setModelDescriptor(collectionDescriptor);
/** * {@inheritDoc} */ @Override protected Object getCollectionProperty(Object proxy, ICollectionPropertyDescriptor<? extends IComponent> propertyDescriptor) { getBackendController().initializePropertyIfNeeded((IComponent) proxy, propertyDescriptor.getName()); return super.getCollectionProperty(proxy, propertyDescriptor); }
/** * {@inheritDoc} */ public List<ISubViewDescriptor> getColumnViewDescriptors() { if (columnViewDescriptors == null) { ICollectionDescriptorProvider<?> modelDescriptor = ((ICollectionDescriptorProvider<?>) getModelDescriptor()); IComponentDescriptor<?> rowModelDescriptor = modelDescriptor .getCollectionDescriptor().getElementDescriptor(); List<String> modelRenderedProperties = rowModelDescriptor .getRenderedProperties(); if (modelDescriptor instanceof ICollectionPropertyDescriptor && ((ICollectionPropertyDescriptor<?>) modelDescriptor) .getReverseRelationEnd() != null) { modelRenderedProperties .remove(((ICollectionPropertyDescriptor<?>) modelDescriptor) .getReverseRelationEnd().getName()); } List<ISubViewDescriptor> defaultColumnViewDescriptors = new ArrayList<ISubViewDescriptor>(); for (String renderedProperty : modelRenderedProperties) { BasicSubviewDescriptor columnDescriptor = new BasicSubviewDescriptor(); columnDescriptor.setName(renderedProperty); columnDescriptor.setGrantedRoles(rowModelDescriptor .getPropertyDescriptor(renderedProperty).getGrantedRoles()); defaultColumnViewDescriptors.add(columnDescriptor); } return defaultColumnViewDescriptors; } return columnViewDescriptors; }
translationRestriction.add(createStringRestriction( ((ICollectionPropertyDescriptor<IPropertyTranslation>) componentDescriptor.getPropertyDescriptor( translationsPath)).getCollectionDescriptor().getElementDescriptor() .getPropertyDescriptor(IPropertyTranslation.TRANSLATED_VALUE), translationsAlias + "." + IPropertyTranslation.TRANSLATED_VALUE, propertyValue, componentDescriptor,
protected void storeCollectionProperty(Object proxy, ICollectionPropertyDescriptor<?> propertyDescriptor, Object oldPropertyValue, Object newPropertyValue) { String propertyName = propertyDescriptor.getName(); if (EntityHelper.isInlineComponentReference(propertyDescriptor.getReferencedDescriptor().getElementDescriptor())) { if (oldPropertyValue instanceof Collection<?> && isInitialized(oldPropertyValue)) { for (IComponent component : (Collection<IComponent>) oldPropertyValue) {
reversePropertyDescriptor.getName(), getComponentContract(((IComponent) propertyValue))) .getValue(propertyValue); ((ICollectionPropertyDescriptor<?>) reversePropertyDescriptor).preprocessRemover( propertyValue, reverseCollection, component); } else { if (((ICollectionPropertyDescriptor<?>) propertyDescriptor).isComposition()) { for (Object composedElement : new ArrayList<>((Collection<?>) propertyValue)) { if (composedElement instanceof IComponent) { if (((ICollectionPropertyDescriptor<?>) propertyDescriptor).getReverseRelationEnd() != null) { IPropertyDescriptor reversePropertyDescriptor = ((ICollectionPropertyDescriptor<?>) propertyDescriptor) .getReverseRelationEnd(); for (Object collectionElement : new ArrayList<>((Collection<?>) propertyValue)) { if (collectionElement instanceof IComponent && !clearedEntities.contains(collectionElement)) { reversePropertyDescriptor.getName(), getComponentContract((IComponent) collectionElement)).getValue(collectionElement); ((ICollectionPropertyDescriptor<?>) reversePropertyDescriptor).preprocessRemover( collectionElement, reverseCollection, component); } else {
@SuppressWarnings("rawtypes") private Map<String, IComponentDescriptor<?>> buildContractNameIdMap() { Map<String, IComponentDescriptor<?>> map = new HashMap<>(); Map<String, IComponentDescriptor> idToComponentDescriptors = componentApplicationContext.getBeansOfType( IComponentDescriptor.class, false, false); for (Map.Entry<String, IComponentDescriptor> descriptorEntry : idToComponentDescriptors.entrySet()) { IComponentDescriptor componentDescriptor = descriptorEntry.getValue(); if (componentDescriptor.getComponentContract() != null) { map.put(componentDescriptor.getComponentContract().getName(), componentDescriptor); if (componentDescriptor.isTranslatable()) { ICollectionPropertyDescriptor<?> collectionPropertyDescriptor = (ICollectionPropertyDescriptor<?>) componentDescriptor .getPropertyDescriptor(AbstractComponentDescriptor.getComponentTranslationsDescriptorTemplate().getName()); if (collectionPropertyDescriptor != null) { IComponentDescriptor<?> translationComponentDescriptor = collectionPropertyDescriptor .getReferencedDescriptor().getElementDescriptor(); if (translationComponentDescriptor.getComponentContract() != null) { map.put(translationComponentDescriptor.getComponentContract().getName(), translationComponentDescriptor); } } } } } map.put(BasicDescriptorDescriptor.INSTANCE.getName(), BasicDescriptorDescriptor.INSTANCE); return map; } }
break; case ADDER: ((ICollectionPropertyDescriptor<?>) propertyDescriptor).preprocessAdder(proxy, (Collection<Object>) computedPropertyValue, interceptedValue); break; case REMOVER: ((ICollectionPropertyDescriptor<?>) propertyDescriptor).preprocessRemover(proxy, (Collection<Object>) computedPropertyValue, interceptedValue); break; break; case ADDER: ((ICollectionPropertyDescriptor<?>) propertyDescriptor).postprocessAdder(proxy, (Collection<Object>) newComputedPropertyValue, args[args.length - 1]); break; case REMOVER: ((ICollectionPropertyDescriptor<?>) propertyDescriptor).postprocessRemover(proxy, (Collection<Object>) newComputedPropertyValue, args[args.length - 1]); break;
/** * {@inheritDoc} */ @Override protected void addToProperty(Object proxy, ICollectionPropertyDescriptor<?> propertyDescriptor, int index, Object value) { getBackendController().initializePropertyIfNeeded((IComponent) proxy, propertyDescriptor.getName()); super.addToProperty(proxy, propertyDescriptor, index, value); }
} else if (modelDescriptor instanceof ICollectionPropertyDescriptor) { IRelationshipEndPropertyDescriptor reverseDescriptor = ((ICollectionPropertyDescriptor<?>) modelDescriptor) .getReverseRelationEnd(); if (reverseDescriptor instanceof IComponentDescriptorProvider) { ((IModelGate) clonedGate)
/** * {@inheritDoc} */ public List<String> getRenderedChildProperties(String propertyName) { List<String> childProperties = null; if (renderedChildProperties != null) { childProperties = renderedChildProperties.get(propertyName); } if (childProperties == null) { IPropertyDescriptor childPropertyDescriptor = ((IComponentDescriptorProvider<?>) getModelDescriptor()) .getComponentDescriptor().getPropertyDescriptor(propertyName); if (childPropertyDescriptor instanceof ICollectionPropertyDescriptor) { return ((ICollectionDescriptor<?>) ((ICollectionPropertyDescriptor<?>) childPropertyDescriptor) .getCollectionDescriptor()).getElementDescriptor() .getRenderedProperties(); } else if (childPropertyDescriptor instanceof IReferencePropertyDescriptor) { return ((IReferencePropertyDescriptor<?>) childPropertyDescriptor) .getReferencedDescriptor().getRenderedProperties(); } } return childProperties; }
/** * Gets the new entity to add. It is created using the informations contained * in the context. * * @param context * the action context. * @return the entity to add to the collection. */ @Override @SuppressWarnings("unchecked") protected List<?> getAddedComponents(Map<String, Object> context) { IComponentDescriptor elementDescriptor = (IComponentDescriptor) context .get(ActionContextConstants.ELEMENT_DESCRIPTOR); if (elementDescriptor == null) { elementDescriptor = ((ICollectionPropertyDescriptor) getModelDescriptor(context)) .getReferencedDescriptor().getElementDescriptor(); } IEntity newEntity = getEntityFactory(context).createEntityInstance( (Class<? extends IEntity>) elementDescriptor.getComponentContract()); return Collections.singletonList(newEntity); } }
/** * {@inheritDoc} */ @Override protected void addToProperty(Object proxy, ICollectionPropertyDescriptor<?> propertyDescriptor, int index, Object value) { getBackendController().initializePropertyIfNeeded((IComponent) proxy, propertyDescriptor.getName()); super.addToProperty(proxy, propertyDescriptor, index, value); }
} else if (modelDescriptor instanceof ICollectionPropertyDescriptor) { IRelationshipEndPropertyDescriptor reverseDescriptor = ((ICollectionPropertyDescriptor<?>) modelDescriptor) .getReverseRelationEnd(); if (reverseDescriptor instanceof IComponentDescriptorProvider) { ((IModelGate) clonedGate)
translationRestriction.add(createStringRestriction( ((ICollectionPropertyDescriptor<IPropertyTranslation>) componentDescriptor.getPropertyDescriptor( translationsPath)).getCollectionDescriptor().getElementDescriptor() .getPropertyDescriptor(IPropertyTranslation.TRANSLATED_VALUE), translationsAlias + "." + IPropertyTranslation.TRANSLATED_VALUE, nlsValue, componentDescriptor,