Search in sources :

Example 6 with IExecutionTask

use of org.jowidgets.cap.ui.api.execution.IExecutionTask 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 7 with IExecutionTask

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

the class BeanProxyImpl method getProgress.

private String getProgress() {
    String result = null;
    final IExecutionTask currentExecutionTask = executionTask;
    if (currentExecutionTask != null) {
        final int worked = currentExecutionTask.getWorked();
        final Integer total = currentExecutionTask.getTotalStepCount();
        if (total != null) {
            final double percent = (((double) worked) * 100) / total;
            result = "" + Math.round(percent) + "%";
        } else {
            result = "?";
        }
    }
    lastProgress = result;
    return result;
}
Also used : IExecutionTask(org.jowidgets.cap.ui.api.execution.IExecutionTask)

Example 8 with IExecutionTask

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

the class ExecutionTask method cancel.

@Override
public void cancel() {
    this.canceled = true;
    fireCanceled();
    for (final IExecutionTask subExecution : new LinkedList<IExecutionTask>(subExecutions)) {
        subExecution.cancel();
    }
}
Also used : IExecutionTask(org.jowidgets.cap.ui.api.execution.IExecutionTask) LinkedList(java.util.LinkedList)

Example 9 with IExecutionTask

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

the class ExecutionTaskFactory method create.

@Override
public IExecutionTask create(final IExecutionContext executionContext) {
    final ExecutionTask result = new ExecutionTask();
    result.addExecutionTaskListener(new ExecutionTaskMonitor(result, executionContext, Toolkit.getUiThreadAccess()));
    return result;
}
Also used : IExecutionTask(org.jowidgets.cap.ui.api.execution.IExecutionTask)

Example 10 with IExecutionTask

use of org.jowidgets.cap.ui.api.execution.IExecutionTask 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)

Aggregations

IExecutionTask (org.jowidgets.cap.ui.api.execution.IExecutionTask)16 LinkedList (java.util.LinkedList)5 IBeanProxy (org.jowidgets.cap.ui.api.bean.IBeanProxy)5 List (java.util.List)4 IUiThreadAccess (org.jowidgets.api.threads.IUiThreadAccess)4 IExecutionCallbackListener (org.jowidgets.cap.common.api.execution.IExecutionCallbackListener)4 AbstractUiResultCallback (org.jowidgets.cap.ui.tools.execution.AbstractUiResultCallback)3 IBeanData (org.jowidgets.cap.common.api.bean.IBeanData)2 IBeanKey (org.jowidgets.cap.common.api.bean.IBeanKey)2 ILinkCreation (org.jowidgets.cap.common.api.link.ILinkCreation)2 IBeanKeyFactory (org.jowidgets.cap.ui.api.bean.IBeanKeyFactory)2 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 IWindow (org.jowidgets.api.widgets.IWindow)1 IBeanDto (org.jowidgets.cap.common.api.bean.IBeanDto)1 IBeanModification (org.jowidgets.cap.common.api.bean.IBeanModification)1 ServiceCanceledException (org.jowidgets.cap.common.api.exception.ServiceCanceledException)1 IResultCallback (org.jowidgets.cap.common.api.execution.IResultCallback)1 ILinkCreationBuilder (org.jowidgets.cap.common.api.link.ILinkCreationBuilder)1 IExecutionTaskDialog (org.jowidgets.cap.ui.api.widgets.IExecutionTaskDialog)1