/** * Adds a new object in the projected collection. * <p> * {@inheritDoc} */ @Override public boolean execute(IActionHandler actionHandler, Map<String, Object> context) { BeanCollectionModule module = (BeanCollectionModule) getModule(context); List<Object> projectedCollection; if (module.getModuleObjects() == null) { projectedCollection = new ArrayList<>(); } else { projectedCollection = new ArrayList<>(module.getModuleObjects()); } Object newModuleObject = createNewModuleObject(actionHandler, context); projectedCollection.add(newModuleObject); module.setModuleObjects(projectedCollection); setSelectedModels(Collections.singleton(newModuleObject), context); return super.execute(actionHandler, context); }
/** * Adds a new object in the projected collection. * <p> * {@inheritDoc} */ @Override public boolean execute(IActionHandler actionHandler, Map<String, Object> context) { ICompositeValueConnector moduleConnector = getModuleConnector(context); BeanCollectionModule module = (BeanCollectionModule) moduleConnector .getConnectorValue(); Collection<Object> projectedCollection; if (module.getModuleObjects() == null) { projectedCollection = new ArrayList<Object>(); } else { projectedCollection = new ArrayList<Object>(module.getModuleObjects()); } Object newModuleObject = createNewModuleObject(actionHandler, context); projectedCollection.add(newModuleObject); module.setModuleObjects(projectedCollection); ICollectionConnector moduleObjectsConnector = getSourceModelConnector(context); if (moduleObjectsConnector == null) { moduleObjectsConnector = getModelConnector(context); } moduleObjectsConnector.setConnectorValue(projectedCollection); context.put(ActionContextConstants.SELECTED_INDICES, ConnectorHelper .getIndicesOf(moduleObjectsConnector, Collections .singleton(newModuleObject))); return super.execute(actionHandler, context); }
/** * Creates a new entity to add to the projected object collection. * * @param actionHandler * the action handler (generally the controller). * @param context * the action context. * @return the created entity. */ @SuppressWarnings("unchecked") protected Object createNewModuleObject(IActionHandler actionHandler, Map<String, Object> context) { IComponentDescriptor projectedComponentDescriptor = ((ICollectionDescriptorProvider<?>) getModelDescriptor(context)) .getCollectionDescriptor().getElementDescriptor(); return getEntityFactory(context).createEntityInstance( (Class<? extends IEntity>) projectedComponentDescriptor .getComponentContract()); } }
/** * Creates a new entity to add to the projected object collection. * * @param actionHandler * the action handler (generally the controller). * @param context * the action context. * @return the created entity. */ @SuppressWarnings({"unchecked", "UnusedParameters"}) protected Object createNewModuleObject(IActionHandler actionHandler, Map<String, Object> context) { IComponentDescriptor<? extends IEntity> projectedDesc = ((ICollectionDescriptorProvider<IEntity>) getModelDescriptor(context)) .getCollectionDescriptor().getElementDescriptor(); Class<? extends IEntity> componentContract = projectedDesc.getComponentContract(); return getEntityFactory(context).createEntityInstance( componentContract); } }