Search in sources :

Example 11 with IBeanProxy

use of org.jowidgets.cap.ui.api.bean.IBeanProxy in project jo-client-platform by jo-source.

the class BeanListExecutionHelper method updateBeans.

private void updateBeans(final List<IBeanProxy<BEAN_TYPE>> executedBeans, final List<IBeanDto> result) {
    // put the resulting beans into a map for faster access later
    final Map<Object, IBeanDto> resultMap = new LinkedHashMap<Object, IBeanDto>();
    for (final IBeanDto beanDto : result) {
        resultMap.put(beanDto.getId(), beanDto);
    }
    // update the executed beans with the beans get as result from the service
    final List<IBeanProxy<BEAN_TYPE>> beansToDelete = new LinkedList<IBeanProxy<BEAN_TYPE>>();
    for (final IBeanProxy<BEAN_TYPE> bean : executedBeans) {
        final IBeanDto updatedBean = resultMap.remove(bean.getId());
        if (updatedBean != null) {
            bean.update(updatedBean);
        } else {
            beansToDelete.add(bean);
        }
    }
    // remove the beans from the model that was not returned by the service
    if (!beansToDelete.isEmpty()) {
        listModel.removeBeans(beansToDelete);
    }
    // add the beans to the model that was created by the service
    for (final IBeanDto beanDto : resultMap.values()) {
        listModel.addBeanDto(beanDto);
    }
}
Also used : IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap) IBeanProxy(org.jowidgets.cap.ui.api.bean.IBeanProxy)

Example 12 with IBeanProxy

use of org.jowidgets.cap.ui.api.bean.IBeanProxy in project jo-client-platform by jo-source.

the class BeanListSaveDelegate method update.

private void update(final Runnable finishedCallback) {
    final Set<IBeanProxy<BEAN_TYPE>> modifiedBeans = beansStateTracker.getMasterBeansToUpdate();
    if (!EmptyCheck.isEmpty(modifiedBeans)) {
        if (updaterService == null) {
            throw new IllegalStateException("No updater service set. Can not update modified beans");
        }
        final BeanListExecutionHelper<BEAN_TYPE> executionHelper = new BeanListExecutionHelper<BEAN_TYPE>(SAVE_FAILED.get(), listModel, modifiedBeans, beanExecutionPolicy, exceptionConverter, false, fireBeansChanged);
        final List<List<IBeanProxy<BEAN_TYPE>>> preparedExecutions = executionHelper.prepareExecutions(false, executionContext);
        final CountDownRunnable countDownRunnable = new CountDownRunnable(finishedCallback, preparedExecutions.size());
        for (final List<IBeanProxy<BEAN_TYPE>> preparedBeans : preparedExecutions) {
            if (preparedBeans.size() > 0) {
                final IExecutionTask executionTask = preparedBeans.get(0).getExecutionTask();
                if (executionTask != null) {
                    executionTask.setDescription(SAVE.get());
                    final List<IBeanModification> modifications = new LinkedList<IBeanModification>();
                    for (final IBeanProxy<?> bean : preparedBeans) {
                        modifications.addAll(bean.getModifications());
                    }
                    final IResultCallback<List<IBeanDto>> helperCallback = executionHelper.createResultCallback(preparedBeans, countDownRunnable);
                    updaterService.update(helperCallback, modifications, executionTask);
                }
            }
        }
    } else {
        finishedCallback.run();
    }
}
Also used : IExecutionTask(org.jowidgets.cap.ui.api.execution.IExecutionTask) LinkedList(java.util.LinkedList) IBeanProxy(org.jowidgets.cap.ui.api.bean.IBeanProxy) LinkedList(java.util.LinkedList) List(java.util.List) IBeanModification(org.jowidgets.cap.common.api.bean.IBeanModification)

Example 13 with IBeanProxy

use of org.jowidgets.cap.ui.api.bean.IBeanProxy in project jo-client-platform by jo-source.

the class BeanProxyFactoryImpl method createProxies.

@Override
public List<IBeanProxy<BEAN_TYPE>> createProxies(final Collection<? extends IBeanDto> beanDtos, final IAttributeSet attributes) {
    Assert.paramNotNull(beanDtos, "beanDtos");
    Assert.paramNotNull(attributes, "attributes");
    final List<IBeanProxy<BEAN_TYPE>> result = new LinkedList<IBeanProxy<BEAN_TYPE>>();
    for (final IBeanDto beanDto : beanDtos) {
        result.add(createProxy(beanDto, attributes));
    }
    return result;
}
Also used : IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) LinkedList(java.util.LinkedList) IBeanProxy(org.jowidgets.cap.ui.api.bean.IBeanProxy)

Example 14 with IBeanProxy

use of org.jowidgets.cap.ui.api.bean.IBeanProxy in project jo-client-platform by jo-source.

the class BeanSelectionProviderEnabledChecker method getEnabledState.

@Override
public IEnabledState getEnabledState() {
    // TODO MG enabled checks must be done better performance
    if (BeanSelectionPolicy.SINGLE_SELECTION == beanSelectionPolicy && lastSelection.size() != 1) {
        return SINGLE_SELECTION_STATE.get();
    } else if (BeanSelectionPolicy.MULTI_SELECTION == beanSelectionPolicy && lastSelection.size() < 1) {
        return MULTI_SELECTION_STATE.get();
    } else if (BeanSelectionPolicy.NO_SELECTION == beanSelectionPolicy && lastSelection.size() > 0) {
        return NO_SELECTION_STATE.get();
    }
    for (final IEnabledChecker enabledChecker : enabledCheckers) {
        final IEnabledState result = enabledChecker.getEnabledState();
        if (!result.isEnabled()) {
            return result;
        }
    }
    if (!ignoreSelectedBeansState) {
        for (final IBeanProxy bean : lastSelection) {
            if (bean == null) {
                return UNLOADED_DATA_STATE.get();
            }
            if (bean.isDummy() || bean.isLastRowDummy()) {
                return EnabledState.DISABLED;
            }
            final IBeanMessage worstMessage = bean.getFirstWorstMessage();
            final IBeanMessage worstMandatoryMessage = bean.getFirstWorstMandatoryMessage();
            if (bean.getExecutionTask() != null) {
                return IS_IN_PROGRESS_STATE.get();
            } else if (BeanMessageStatePolicy.NO_MESSAGE == beanMessageStatePolicy && worstMessage != null) {
                return UNHANDLED_MESSAGES_STATE.get();
            } else if (BeanMessageStatePolicy.NO_MESSAGE_MANDATORY == beanMessageStatePolicy && worstMandatoryMessage != null) {
                return UNHANDLED_MESSAGES_STATE.get();
            } else if (BeanModificationStatePolicy.NO_MODIFICATION == beanModificationStatePolicy && bean.hasModifications() && !bean.isTransient()) {
                return UNSAVED_DATA_STATE.get();
            } else if (BeanMessageStatePolicy.NO_WARNING_OR_ERROR == beanMessageStatePolicy && worstMessage != null && worstMessage.getType().equalOrWorse(BeanMessageType.WARNING)) {
                return UNHANDLED_MESSAGES_STATE.get();
            } else if (BeanMessageStatePolicy.NO_WARNING_OR_ERROR_MANDATORY == beanMessageStatePolicy && worstMandatoryMessage != null && worstMandatoryMessage.getType().equalOrWorse(BeanMessageType.WARNING)) {
                return UNHANDLED_MESSAGES_STATE.get();
            } else if (BeanMessageStatePolicy.NO_ERROR == beanMessageStatePolicy && worstMessage != null && worstMessage.getType() == BeanMessageType.ERROR) {
                return UNHANDLED_MESSAGES_STATE.get();
            } else if (BeanMessageStatePolicy.NO_ERROR_MANDATORY == beanMessageStatePolicy && worstMandatoryMessage != null && worstMandatoryMessage.getType() == BeanMessageType.ERROR) {
                return UNHANDLED_MESSAGES_STATE.get();
            }
            for (final IExecutableChecker executableChecker : executableCheckers) {
                final IExecutableState result = executableChecker.getExecutableState(bean.getBean());
                if (!result.isExecutable()) {
                    return EnabledState.disabled(result.getReason());
                }
            }
        }
    }
    return EnabledState.ENABLED;
}
Also used : IEnabledState(org.jowidgets.api.command.IEnabledState) IEnabledChecker(org.jowidgets.api.command.IEnabledChecker) IBeanMessage(org.jowidgets.cap.ui.api.bean.IBeanMessage) IExecutableChecker(org.jowidgets.cap.common.api.execution.IExecutableChecker) IExecutableState(org.jowidgets.cap.common.api.execution.IExecutableState) IBeanProxy(org.jowidgets.cap.ui.api.bean.IBeanProxy)

Example 15 with IBeanProxy

use of org.jowidgets.cap.ui.api.bean.IBeanProxy in project jo-client-platform by jo-source.

the class BeanTableModelImpl method getParentBeanKeys.

@Override
public List<IBeanKey> getParentBeanKeys() {
    if (parent == null) {
        return null;
    }
    final IBeanSelection<Object> beanSelection = parent.getBeanSelection();
    List<IBeanProxy<Object>> selection = beanSelection.getSelection();
    if (EmptyCheck.isEmpty(selection)) {
        return null;
    } else if (linkType == LinkType.SELECTION_FIRST) {
        selection = selection.subList(0, 1);
    }
    final List<IBeanKey> beanKeys = new LinkedList<IBeanKey>();
    for (final IBeanProxy<Object> proxy : selection) {
        if (proxy != null && !proxy.isDummy() && !proxy.isTransient() && !proxy.isLastRowDummy()) {
            beanKeys.add(new BeanKey(proxy.getId(), proxy.getVersion()));
        }
    }
    return beanKeys;
}
Also used : BeanKey(org.jowidgets.cap.common.tools.bean.BeanKey) IBeanKey(org.jowidgets.cap.common.api.bean.IBeanKey) IBeanKey(org.jowidgets.cap.common.api.bean.IBeanKey) LinkedList(java.util.LinkedList) IBeanProxy(org.jowidgets.cap.ui.api.bean.IBeanProxy)

Aggregations

IBeanProxy (org.jowidgets.cap.ui.api.bean.IBeanProxy)25 LinkedList (java.util.LinkedList)13 IBeanDto (org.jowidgets.cap.common.api.bean.IBeanDto)7 TableCellBluePrint (org.jowidgets.tools.model.table.TableCellBluePrint)6 List (java.util.List)5 IBeanKey (org.jowidgets.cap.common.api.bean.IBeanKey)5 IExecutionTask (org.jowidgets.cap.ui.api.execution.IExecutionTask)5 ArrayList (java.util.ArrayList)3 BeanKey (org.jowidgets.cap.common.tools.bean.BeanKey)3 IBeanRelationNodeModel (org.jowidgets.cap.ui.api.tree.IBeanRelationNodeModel)3 ITreeNode (org.jowidgets.api.widgets.ITreeNode)2 IBeanKeyFactory (org.jowidgets.cap.ui.api.bean.IBeanKeyFactory)2 ITableCellPopupEvent (org.jowidgets.common.widgets.controller.ITableCellPopupEvent)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 IEnabledChecker (org.jowidgets.api.command.IEnabledChecker)1 IEnabledState (org.jowidgets.api.command.IEnabledState)1 IDisposeListener (org.jowidgets.api.controller.IDisposeListener)1