Search in sources :

Example 1 with ILinkCreationBuilder

use of org.jowidgets.cap.common.api.link.ILinkCreationBuilder 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)

Aggregations

IUiThreadAccess (org.jowidgets.api.threads.IUiThreadAccess)1 IExecutionCallbackListener (org.jowidgets.cap.common.api.execution.IExecutionCallbackListener)1 ILinkCreation (org.jowidgets.cap.common.api.link.ILinkCreation)1 ILinkCreationBuilder (org.jowidgets.cap.common.api.link.ILinkCreationBuilder)1 IExecutionTask (org.jowidgets.cap.ui.api.execution.IExecutionTask)1