/** * {@inheritDoc} */ @Override protected ModelCollectionPropertyConnector getModelConnector( Map<String, Object> context) { return (ModelCollectionPropertyConnector) super.getModelConnector(context); }
/** * {@inheritDoc} */ @Override protected IComponentDescriptor<?> getAddedElementDescriptor(Map<String, Object> context) { IComponentDescriptor<?> elementDescriptor = (IComponentDescriptor<?>) context .get(ELEMENT_DESCRIPTOR); if (elementDescriptor == null) { elementDescriptor = super.getAddedElementDescriptor(context); } return elementDescriptor; } }
ICollectionConnector collectionConnector = getModelConnector(context); if (collectionConnector == null) { return false; List<?> newComponents = getAddedComponents(context); if (newComponents != null && newComponents.size() > 0) { IComponentDescriptor<?> addedComponentDescriptor = getAddedElementDescriptor(context); Class<?> newComponentContract = addedComponentDescriptor.getComponentContract(); Object master = collectionConnector.getParentConnector().getConnectorValue(); ICollectionAccessor collectionAccessor = getAccessorFactory(context).createCollectionPropertyAccessor( collectionConnector.getId(), master.getClass() ((IModelDescriptorAware) collectionAccessor).setModelDescriptor(getModelDescriptor(context)); if (!isIgnoreSelection() && collectionAccessor instanceof IListAccessor) { if (getSelectedIndices(context) != null && getSelectedIndices(context).length > 0) { index = getSelectedIndices(context)[getSelectedIndices(context).length - 1]; for (int i = 0; i < newComponents.size(); i++) { Object addedComponent = newComponents.get(i); if (getInitializationMapping() != null) { getEntityFactory(context).applyInitializationMapping(addedComponent, addedComponentDescriptor, master, getInitializationMapping(), null); setActionParameter(newComponents, context); setSelectedModels(getViewPath(), newComponents, context);
@SuppressWarnings("unchecked") public boolean execute(IActionHandler actionHandler, Map<String, Object> context) { ICollectionConnector collectionConnector = getModelConnector(context); if (collectionConnector == null) { return false; List<?> newComponents = getAddedComponents(context); if (newComponents != null && newComponents.size() > 0) { Class newComponentContract = getModelDescriptor(context) .getCollectionDescriptor().getElementDescriptor() .getComponentContract(); Object master = collectionConnector.getParentConnector() .getConnectorValue(); ICollectionAccessor collectionAccessor = getAccessorFactory(context) .createCollectionPropertyAccessor( collectionConnector.getId(), ((IModelValueConnector) collectionConnector).getModelProvider() .getModelDescriptor().getComponentDescriptor() .getComponentContract(), newComponentContract); if (collectionAccessor instanceof IModelDescriptorAware) { ((IModelDescriptorAware) collectionAccessor) .setModelDescriptor(getModelDescriptor(context)); if (getSelectedIndices(context) != null && getSelectedIndices(context).length > 0) { index = getSelectedIndices(context)[getSelectedIndices(context).length - 1];
/** * Gets added element descriptor. * * @param context * the context * @return the added element descriptor */ protected IComponentDescriptor<?> getAddedElementDescriptor(Map<String, Object> context) { IComponentDescriptor<?> elementDescriptor; String collectionPropertyName = getModelDescriptor(context).getName(); Object master = getModelConnector(context).getModelProvider().getModel(); if (master instanceof IComponent) { // Component type should be refined depending on concrete master. See property translations for instance. elementDescriptor = ((ICollectionPropertyDescriptor<?>) getEntityFactory(context).getComponentDescriptor( ((IComponent) master).getComponentContract()).getPropertyDescriptor(collectionPropertyName)) .getReferencedDescriptor().getElementDescriptor(); } else { elementDescriptor = ((ICollectionPropertyDescriptor<?>) getModelDescriptor(context)).getReferencedDescriptor() .getElementDescriptor(); } return elementDescriptor; }