Search in sources :

Example 1 with IBeanKeyFactory

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

the class BeanDeleterCommand method execute.

@Override
public void execute(final IExecutionContext executionContext) throws Exception {
    if (!executionObservable.fireBeforeExecution(executionContext)) {
        return;
    }
    final IBeanSelection<BEAN_TYPE> beanSelection = model.getBeanSelection();
    if (beanSelection == null || beanSelection.getSelection().size() == 0) {
        Toolkit.getMessagePane().showWarning(executionContext, NOTHING_SELECTED.get());
        return;
    }
    if (deletionConfirmDialog) {
        if (!showDeletionConfirmDialog(executionContext, beanSelection)) {
            executionObservable.fireAfterExecutionCanceled(executionContext);
            return;
        }
    }
    final IBeanKeyFactory beanKeyFactory = CapUiToolkit.beanKeyFactory();
    final IExecutionTask executionTask = CapUiToolkit.executionTaskFactory().create(executionContext);
    final List<IBeanKey> beanKeys = new LinkedList<IBeanKey>();
    final List<IBeanProxy<BEAN_TYPE>> beans = new LinkedList<IBeanProxy<BEAN_TYPE>>();
    final List<IBeanProxy<BEAN_TYPE>> transientBeans = new LinkedList<IBeanProxy<BEAN_TYPE>>();
    for (final IBeanProxy<BEAN_TYPE> bean : beanSelection.getSelection()) {
        if (bean != null && bean.isTransient()) {
            transientBeans.add(bean);
        } else if (bean != null && !bean.isDummy() && !bean.isLastRowDummy()) {
            bean.setExecutionTask(executionTask);
            beanKeys.add(beanKeyFactory.createKey(bean));
            beans.add(bean);
        }
    }
    final IUiThreadAccess uiThreadAccess = Toolkit.getUiThreadAccess();
    executionTask.addExecutionCallbackListener(new IExecutionCallbackListener() {

        @Override
        public void canceled() {
            uiThreadAccess.invokeLater(new Runnable() {

                @Override
                public void run() {
                    for (final IBeanProxy<BEAN_TYPE> bean : beans) {
                        bean.setExecutionTask(null);
                    }
                    model.fireBeansChanged();
                    executionObservable.fireAfterExecutionCanceled(executionContext);
                }
            });
        }
    });
    if (autoSelection) {
        final ArrayList<Integer> selection = model.getSelection();
        if (!EmptyCheck.isEmpty(selection)) {
            final int newSelectionIndex = selection.get(selection.size() - 1) + 1;
            if (newSelectionIndex >= 0 && newSelectionIndex < model.getSize()) {
                model.setSelection(Collections.singletonList(newSelectionIndex));
            }
        }
    }
    if (!transientBeans.isEmpty()) {
        model.removeBeans(transientBeans);
    }
    model.fireBeansChanged();
    executionObservable.fireAfterExecutionPrepared(executionContext);
    if (!beanKeys.isEmpty()) {
        deleterService.delete(new ResultCallback(executionContext, beans), beanKeys, executionTask);
    }
}
Also used : IExecutionCallbackListener(org.jowidgets.cap.common.api.execution.IExecutionCallbackListener) AbstractUiResultCallback(org.jowidgets.cap.ui.tools.execution.AbstractUiResultCallback) IExecutionTask(org.jowidgets.cap.ui.api.execution.IExecutionTask) IUiThreadAccess(org.jowidgets.api.threads.IUiThreadAccess) LinkedList(java.util.LinkedList) IBeanProxy(org.jowidgets.cap.ui.api.bean.IBeanProxy) IBeanKey(org.jowidgets.cap.common.api.bean.IBeanKey) IBeanKeyFactory(org.jowidgets.cap.ui.api.bean.IBeanKeyFactory)

Example 2 with IBeanKeyFactory

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

the class BeanListRefreshDelegate method refresh.

void refresh(final Collection<IBeanProxy<BEAN_TYPE>> beans) {
    if (refreshService != null) {
        final BeanListExecutionHelper<BEAN_TYPE> executionHelper = new BeanListExecutionHelper<BEAN_TYPE>(REFRESH_FAILED.get(), listModel, beans, beanExecutionPolicy, exceptionConverter, false, true);
        for (final List<IBeanProxy<BEAN_TYPE>> preparedBeans : executionHelper.prepareExecutions(false)) {
            if (preparedBeans.size() > 0) {
                final IExecutionTask executionTask = preparedBeans.get(0).getExecutionTask();
                if (executionTask != null) {
                    executionTask.setDescription(REFRESH.get());
                    final IBeanKeyFactory beanKeyFactory = CapUiToolkit.beanKeyFactory();
                    final List<IBeanKey> beanKeys = beanKeyFactory.createKeys(preparedBeans);
                    final IResultCallback<List<IBeanDto>> helperCallback = executionHelper.createResultCallback(preparedBeans);
                    refreshService.refresh(helperCallback, beanKeys, executionTask);
                }
            }
        }
    }
}
Also used : IBeanKey(org.jowidgets.cap.common.api.bean.IBeanKey) IExecutionTask(org.jowidgets.cap.ui.api.execution.IExecutionTask) List(java.util.List) IBeanProxy(org.jowidgets.cap.ui.api.bean.IBeanProxy) IBeanKeyFactory(org.jowidgets.cap.ui.api.bean.IBeanKeyFactory)

Aggregations

IBeanKey (org.jowidgets.cap.common.api.bean.IBeanKey)2 IBeanKeyFactory (org.jowidgets.cap.ui.api.bean.IBeanKeyFactory)2 IBeanProxy (org.jowidgets.cap.ui.api.bean.IBeanProxy)2 IExecutionTask (org.jowidgets.cap.ui.api.execution.IExecutionTask)2 LinkedList (java.util.LinkedList)1 List (java.util.List)1 IUiThreadAccess (org.jowidgets.api.threads.IUiThreadAccess)1 IExecutionCallbackListener (org.jowidgets.cap.common.api.execution.IExecutionCallbackListener)1 AbstractUiResultCallback (org.jowidgets.cap.ui.tools.execution.AbstractUiResultCallback)1