Search in sources :

Example 1 with IDeleterService

use of org.jowidgets.cap.common.api.service.IDeleterService in project jo-client-platform by jo-source.

the class BeanRelationTreeImpl method createDeleterAction.

private IAction createDeleterAction(final IBeanRelationNodeModel<Object, Object> relationNodeModel) {
    if (!defaultDeleterAction) {
        return null;
    }
    final IEntityService entityService = ServiceProvider.getService(IEntityService.ID);
    if (entityService != null) {
        final ICapActionFactory actionFactory = CapUiToolkit.actionFactory();
        final Object childEntityId = relationNodeModel.getChildEntityId();
        final IBeanServicesProvider beanServices = entityService.getBeanServices(childEntityId);
        if (beanServices != null) {
            final IDeleterService deleterService = beanServices.deleterService();
            if (deleterService != null) {
                IDeleterActionBuilder<Object> builder = actionFactory.deleterActionBuilder(relationNodeModel);
                builder.setDeleterService(deleterService);
                builder.setMultiSelectionPolicy(false);
                if (autoKeyBinding) {
                    builder.setAccelerator(VirtualKey.DELETE, Modifier.ALT);
                } else {
                    builder.setAccelerator(null);
                }
                final IBeanDtoDescriptor descriptor = entityService.getDescriptor(childEntityId);
                if (descriptor != null) {
                    builder.setEntityLabelPlural(descriptor.getLabelPlural().get());
                    builder.setEntityLabelSingular(descriptor.getLabelSingular().get());
                    final Object icon = descriptor.getDeleteIconDescriptor();
                    if (icon != null) {
                        final IImageConstant imageConstant = ImageResolver.resolve(icon);
                        if (imageConstant != null) {
                            builder.setIcon(imageConstant);
                        }
                    }
                }
                if (menuInterceptor != null) {
                    builder = menuInterceptor.deleterActionBuilder(relationNodeModel, builder);
                }
                if (builder != null) {
                    return builder.build();
                }
            }
        }
    }
    return null;
}
Also used : IImageConstant(org.jowidgets.common.image.IImageConstant) IBeanServicesProvider(org.jowidgets.cap.common.api.service.IBeanServicesProvider) IDeleterService(org.jowidgets.cap.common.api.service.IDeleterService) IEntityService(org.jowidgets.cap.common.api.service.IEntityService) IBeanDtoDescriptor(org.jowidgets.cap.common.api.bean.IBeanDtoDescriptor) ICapActionFactory(org.jowidgets.cap.ui.api.command.ICapActionFactory)

Example 2 with IDeleterService

use of org.jowidgets.cap.common.api.service.IDeleterService in project jo-client-platform by jo-source.

the class JpaEntityService method createServicesProvider.

private <T extends IBean> IBeanServicesProvider createServicesProvider(final Class<? extends IBean> beanInterface, final Class<T> beanType, final IBeanDtoDescriptor descriptor) {
    final IBeanServicesProviderBuilder builder = CapServiceToolkit.beanServicesProviderBuilder(SpringServiceProvider.getInstance(), IEntityService.ID, beanType, beanInterface);
    final List<String> propertyNames = new LinkedList<String>();
    for (final IProperty property : descriptor.getProperties()) {
        propertyNames.add(property.getName());
    }
    final IJpaServiceFactory serviceFactory = JpaServiceToolkit.serviceFactory();
    final TransactionProxyFactory tpf = new TransactionProxyFactory(transactionManager);
    final ICreatorService creatorService = serviceFactory.creatorService(beanType, propertyNames);
    builder.setCreatorService(tpf.createProxy(creatorService, "create"));
    final IDeleterService deleterService = serviceFactory.deleterService(beanType);
    builder.setDeleterService(tpf.createProxy(deleterService, "delete"));
    // TODO: MvR -> Check genericity...
    final ICriteriaQueryCreatorBuilder<Void> queryBuilder = JpaQueryToolkit.criteriaQueryCreatorBuilder(beanType);
    if (ParentLinkHelper.hasParent(beanType)) {
        queryBuilder.setParentPropertyName("parent");
    }
    final IReaderService<Void> readerService = serviceFactory.readerService(beanType, queryBuilder.build(), propertyNames);
    builder.setReaderService(readerService);
    final IBeanAccess<T> beanAccess = serviceFactory.beanAccess(beanType);
    builder.setRefreshService(CapServiceToolkit.refreshServiceBuilder(beanAccess).setBeanDtoFactory(propertyNames).build());
    final IUpdaterService updaterService = CapServiceToolkit.updaterServiceBuilder(beanAccess).setBeanDtoFactoryAndBeanModifier(propertyNames).build();
    builder.setUpdaterService(tpf.createProxy(updaterService, "update"));
    return builder.build();
}
Also used : TransactionProxyFactory(org.jowidgets.cap.service.spring.TransactionProxyFactory) IUpdaterService(org.jowidgets.cap.common.api.service.IUpdaterService) LinkedList(java.util.LinkedList) IBeanServicesProviderBuilder(org.jowidgets.cap.service.api.entity.IBeanServicesProviderBuilder) IProperty(org.jowidgets.cap.common.api.bean.IProperty) IDeleterService(org.jowidgets.cap.common.api.service.IDeleterService) ICreatorService(org.jowidgets.cap.common.api.service.ICreatorService) IJpaServiceFactory(org.jowidgets.cap.service.jpa.api.IJpaServiceFactory)

Example 3 with IDeleterService

use of org.jowidgets.cap.common.api.service.IDeleterService in project jo-client-platform by jo-source.

the class DeleterActionBuilder method setDeleterService.

@Override
public DeleterActionBuilder<BEAN_TYPE> setDeleterService(final IServiceId<IDeleterService> deleterServiceId) {
    checkExhausted();
    Assert.paramNotNull(deleterServiceId, "deleterServiceId");
    final IDeleterService service = ServiceProvider.getService(deleterServiceId);
    if (service == null) {
        throw new IllegalArgumentException("No deleter service found for the id '" + deleterServiceId + "'.");
    }
    return setDeleterService(service);
}
Also used : IDeleterService(org.jowidgets.cap.common.api.service.IDeleterService)

Aggregations

IDeleterService (org.jowidgets.cap.common.api.service.IDeleterService)3 LinkedList (java.util.LinkedList)1 IBeanDtoDescriptor (org.jowidgets.cap.common.api.bean.IBeanDtoDescriptor)1 IProperty (org.jowidgets.cap.common.api.bean.IProperty)1 IBeanServicesProvider (org.jowidgets.cap.common.api.service.IBeanServicesProvider)1 ICreatorService (org.jowidgets.cap.common.api.service.ICreatorService)1 IEntityService (org.jowidgets.cap.common.api.service.IEntityService)1 IUpdaterService (org.jowidgets.cap.common.api.service.IUpdaterService)1 IBeanServicesProviderBuilder (org.jowidgets.cap.service.api.entity.IBeanServicesProviderBuilder)1 IJpaServiceFactory (org.jowidgets.cap.service.jpa.api.IJpaServiceFactory)1 TransactionProxyFactory (org.jowidgets.cap.service.spring.TransactionProxyFactory)1 ICapActionFactory (org.jowidgets.cap.ui.api.command.ICapActionFactory)1 IImageConstant (org.jowidgets.common.image.IImageConstant)1