Search in sources :

Example 1 with IExecutionTask

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

the class BeansStateTrackerImpl method cancelExecutions.

@Override
public void cancelExecutions() {
    final Set<IExecutionTask> tasks = new HashSet<IExecutionTask>();
    for (final IBeanProxy<BEAN_TYPE> bean : new HashSet<IBeanProxy<BEAN_TYPE>>(processingBeans)) {
        tasks.add(bean.getExecutionTask());
        bean.setExecutionTask(null);
    }
    processingBeans.clear();
    for (final IExecutionTask task : tasks) {
        if (task != null && !task.isCanceled() && !task.isFinshed()) {
            final Runnable runnable = new Runnable() {

                @Override
                public void run() {
                    task.cancel();
                }
            };
            final Thread thread = new Thread(runnable);
            thread.setDaemon(true);
            thread.start();
        }
    }
}
Also used : IExecutionTask(org.jowidgets.cap.ui.api.execution.IExecutionTask) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 2 with IExecutionTask

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

the class BeanCreatorCommand method createBean.

private void createBean(final IExecutionContext executionContext, final IBeanProxy<BEAN_TYPE> bean) {
    final IExecutionTask executionTask = CapUiToolkit.executionTaskFactory().create(executionContext);
    bean.setExecutionTask(executionTask);
    final IUiThreadAccess uiThreadAccess = Toolkit.getUiThreadAccess();
    executionTask.addExecutionCallbackListener(new IExecutionCallbackListener() {

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

                @Override
                public void run() {
                    bean.setExecutionTask(null);
                    model.removeBeans(Collections.singletonList(bean));
                    model.fireBeansChanged();
                    executionObservable.fireAfterExecutionCanceled(executionContext);
                }
            });
        }
    });
    model.addBean(bean);
    final IBeanData beanData = createBeanData(bean);
    final List<IBeanData> data = Collections.singletonList(beanData);
    executionObservable.fireAfterExecutionPrepared(executionContext);
    creatorService.create(new ResultCallback(executionContext, bean), parentBeanKeysProvider.get(), data, 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) IBeanData(org.jowidgets.cap.common.api.bean.IBeanData) IUiThreadAccess(org.jowidgets.api.threads.IUiThreadAccess)

Example 3 with IExecutionTask

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

the class BeanLinkCreatorCommand method linkBeans.

private void linkBeans(final IExecutionContext executionContext, final List<IBeanProxy<SOURCE_BEAN_TYPE>> selection, final IBeanLink<LINK_BEAN_TYPE, LINKABLE_BEAN_TYPE> beanLink) {
    final IExecutionTask executionTask = CapUiToolkit.executionTaskFactory().create(executionContext);
    final IUiThreadAccess uiThreadAccess = Toolkit.getUiThreadAccess();
    executionTask.addExecutionCallbackListener(new IExecutionCallbackListener() {

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

                @Override
                public void run() {
                    for (final IBeanProxy<SOURCE_BEAN_TYPE> bean : selection) {
                        bean.setExecutionTask(null);
                    }
                    executionObservable.fireAfterExecutionCanceled(executionContext);
                }
            });
        }
    });
    final ILinkCreationBuilder linkCreationBuilder = LinkCreation.builder();
    // add the source beans
    for (final IBeanProxy<SOURCE_BEAN_TYPE> sourceBean : selection) {
        if (sourceBean.isTransient()) {
            linkCreationBuilder.addTransientSourceBean(sourceBean.getBeanData());
        } else {
            linkCreationBuilder.addSourceBean(sourceBean.getBeanKey());
        }
    }
    // add the linkable beans
    for (final IBeanProxy<LINKABLE_BEAN_TYPE> linkableBean : beanLink.getLinkableBeans()) {
        if (linkableBean.isTransient()) {
            linkCreationBuilder.addTransientLinkableBean(linkableBean.getBeanData());
        } else {
            linkCreationBuilder.addLinkableBean(linkableBean.getBeanKey());
        }
    }
    // set the additional properties
    final IBeanProxy<LINK_BEAN_TYPE> linkBean = beanLink.getLinkBean();
    if (linkBean != null) {
        linkCreationBuilder.setAdditionalLinkProperties(linkBean.getBeanData());
    }
    final Set<ILinkCreation> linkCreations = Collections.singleton(linkCreationBuilder.build());
    executionObservable.fireAfterExecutionPrepared(executionContext);
    linkCreatorService.create(createResultCallback(selection, executionContext), linkCreations, executionTask);
}
Also used : IExecutionCallbackListener(org.jowidgets.cap.common.api.execution.IExecutionCallbackListener) IExecutionTask(org.jowidgets.cap.ui.api.execution.IExecutionTask) IUiThreadAccess(org.jowidgets.api.threads.IUiThreadAccess) ILinkCreation(org.jowidgets.cap.common.api.link.ILinkCreation) ILinkCreationBuilder(org.jowidgets.cap.common.api.link.ILinkCreationBuilder)

Example 4 with IExecutionTask

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

the class BeanListExecutionHelper method prepareExecutions.

List<List<IBeanProxy<BEAN_TYPE>>> prepareExecutions(final boolean allowTransient, final IExecutionContext executionContext) {
    final List<List<IBeanProxy<BEAN_TYPE>>> result = new LinkedList<List<IBeanProxy<BEAN_TYPE>>>();
    if (BeanExecutionPolicy.BATCH == beanExecutionPolicy) {
        final IExecutionTask executionTask = createExecutionTask(executionContext);
        final List<IBeanProxy<BEAN_TYPE>> subList = new LinkedList<IBeanProxy<BEAN_TYPE>>();
        result.add(subList);
        for (final IBeanProxy<BEAN_TYPE> bean : beans) {
            if (bean.getExecutionTask() == null && !bean.isDummy() && !bean.isLastRowDummy() && (allowTransient || !bean.isTransient())) {
                bean.setExecutionTask(executionTask);
                subList.add(bean);
            }
        }
    } else {
        for (final IBeanProxy<BEAN_TYPE> bean : beans) {
            final List<IBeanProxy<BEAN_TYPE>> subList = new LinkedList<IBeanProxy<BEAN_TYPE>>();
            result.add(subList);
            if (bean.getExecutionTask() == null && !bean.isDummy() && (allowTransient || !bean.isTransient())) {
                final IExecutionTask executionTask = createExecutionTask(executionContext);
                bean.setExecutionTask(executionTask);
                subList.add(bean);
            }
        }
    }
    if (fireBeansChanged) {
        listModel.fireBeansChanged();
    }
    return result;
}
Also used : IExecutionTask(org.jowidgets.cap.ui.api.execution.IExecutionTask) List(java.util.List) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList) IBeanProxy(org.jowidgets.cap.ui.api.bean.IBeanProxy)

Example 5 with IExecutionTask

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

the class BeanListExecutionHelper method onExecption.

void onExecption(final List<IBeanProxy<BEAN_TYPE>> executedBeans, final Throwable exception) {
    int beanIndex = 0;
    for (final IBeanProxy<BEAN_TYPE> bean : executedBeans) {
        final IExecutionTask executionTask = bean.getExecutionTask();
        final boolean canceled = (exception instanceof ServiceCanceledException) || (executionTask != null && executionTask.isCanceled());
        if (!canceled) {
            bean.addMessage(exceptionConverter.convert(shortErrorMessage, executedBeans, beanIndex++, bean, exception));
        }
        bean.setExecutionTask(null);
    }
    if (fireBeansChanged) {
        listModel.fireBeansChanged();
    }
}
Also used : IExecutionTask(org.jowidgets.cap.ui.api.execution.IExecutionTask) ServiceCanceledException(org.jowidgets.cap.common.api.exception.ServiceCanceledException)

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