Search in sources :

Example 1 with IExecutionCallbackListener

use of org.jowidgets.cap.common.api.execution.IExecutionCallbackListener 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 2 with IExecutionCallbackListener

use of org.jowidgets.cap.common.api.execution.IExecutionCallbackListener 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 3 with IExecutionCallbackListener

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

the class CsvExporter method startExportBeans.

private void startExportBeans(final IBeanProvider beanProvider, final Integer totalCount, final IExecutionCallback executionCallback) throws Exception {
    final File file = new File(parameter.getFilename());
    final FileOutputStream fos = new FileOutputStream(file);
    final PrintStream ps = new PrintStream(fos, true, parameter.getEncoding());
    executionCallback.addExecutionCallbackListener(new IExecutionCallbackListener() {

        @Override
        public void canceled() {
            try {
                closeStream(ps);
            } catch (final Exception e) {
            }
        }
    });
    writeHeader(ps);
    exportBeans(beanProvider, ps, 0, totalCount, executionCallback);
}
Also used : IExecutionCallbackListener(org.jowidgets.cap.common.api.execution.IExecutionCallbackListener) PrintStream(java.io.PrintStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 4 with IExecutionCallbackListener

use of org.jowidgets.cap.common.api.execution.IExecutionCallbackListener 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 5 with IExecutionCallbackListener

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

the class PasteLinkCommand method linkBeans.

private void linkBeans(final IExecutionContext executionContext, final List<IBeanProxy<SOURCE_BEAN_TYPE>> selection) {
    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 Collection<ILinkCreation> linkCreations = linkProvider.get();
    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)

Aggregations

IExecutionCallbackListener (org.jowidgets.cap.common.api.execution.IExecutionCallbackListener)5 IUiThreadAccess (org.jowidgets.api.threads.IUiThreadAccess)4 IExecutionTask (org.jowidgets.cap.ui.api.execution.IExecutionTask)4 ILinkCreation (org.jowidgets.cap.common.api.link.ILinkCreation)2 AbstractUiResultCallback (org.jowidgets.cap.ui.tools.execution.AbstractUiResultCallback)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 PrintStream (java.io.PrintStream)1 LinkedList (java.util.LinkedList)1 IBeanData (org.jowidgets.cap.common.api.bean.IBeanData)1 IBeanKey (org.jowidgets.cap.common.api.bean.IBeanKey)1 ILinkCreationBuilder (org.jowidgets.cap.common.api.link.ILinkCreationBuilder)1 IBeanKeyFactory (org.jowidgets.cap.ui.api.bean.IBeanKeyFactory)1 IBeanProxy (org.jowidgets.cap.ui.api.bean.IBeanProxy)1