Search in sources :

Example 1 with IUiThreadAccess

use of org.jowidgets.api.threads.IUiThreadAccess 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 IUiThreadAccess

use of org.jowidgets.api.threads.IUiThreadAccess 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 IUiThreadAccess

use of org.jowidgets.api.threads.IUiThreadAccess in project jo-client-platform by jo-source.

the class AbstractRemoteLoginService method createLoginInterceptor.

@Override
public ILoginInterceptor createLoginInterceptor() {
    final ILoginInterceptor original = new RemotingBasicAuthenticationLoginInterceptor(getAuthorizationProviderServiceId());
    return new ILoginInterceptor() {

        @Override
        public void login(final ILoginResultCallback resultCallback, final String username, final String password, final IUiThreadAccess uiThreadAccess) {
            final ILoginResultCallback decoratedCallback = new ILoginResultCallback() {

                @Override
                public void addCancelListener(final ILoginCancelListener cancelListener) {
                    resultCallback.addCancelListener(cancelListener);
                }

                @Override
                public void granted() {
                    afterLoginSuccess();
                    resultCallback.granted();
                }

                @Override
                public void denied(final String reason) {
                    afterLoginFailed(reason);
                    resultCallback.denied(reason);
                }
            };
            original.login(decoratedCallback, username, password, uiThreadAccess);
        }
    };
}
Also used : ILoginResultCallback(org.jowidgets.api.login.ILoginResultCallback) RemotingBasicAuthenticationLoginInterceptor(org.jowidgets.cap.tools.starter.client.remoting.RemotingBasicAuthenticationLoginInterceptor) ILoginCancelListener(org.jowidgets.api.login.ILoginCancelListener) IUiThreadAccess(org.jowidgets.api.threads.IUiThreadAccess) ILoginInterceptor(org.jowidgets.api.login.ILoginInterceptor)

Example 4 with IUiThreadAccess

use of org.jowidgets.api.threads.IUiThreadAccess in project jo-client-platform by jo-source.

the class ParentSelectionListener method loadScheduled.

private void loadScheduled() {
    if (listenerDelay > 0) {
        childModel.clear();
    }
    if (schedule != null) {
        schedule.cancel(false);
    }
    final IUiThreadAccess uiThreadAccess = Toolkit.getUiThreadAccess();
    final Runnable runnable = new Runnable() {

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

                @Override
                public void run() {
                    schedule = null;
                    load();
                }
            });
        }
    };
    schedule = getExecutorService().schedule(runnable, listenerDelay, TimeUnit.MILLISECONDS);
}
Also used : IUiThreadAccess(org.jowidgets.api.threads.IUiThreadAccess)

Example 5 with IUiThreadAccess

use of org.jowidgets.api.threads.IUiThreadAccess 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

IUiThreadAccess (org.jowidgets.api.threads.IUiThreadAccess)6 IExecutionCallbackListener (org.jowidgets.cap.common.api.execution.IExecutionCallbackListener)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 LinkedList (java.util.LinkedList)1 ILoginCancelListener (org.jowidgets.api.login.ILoginCancelListener)1 ILoginInterceptor (org.jowidgets.api.login.ILoginInterceptor)1 ILoginResultCallback (org.jowidgets.api.login.ILoginResultCallback)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 RemotingBasicAuthenticationLoginInterceptor (org.jowidgets.cap.tools.starter.client.remoting.RemotingBasicAuthenticationLoginInterceptor)1 IBeanKeyFactory (org.jowidgets.cap.ui.api.bean.IBeanKeyFactory)1 IBeanProxy (org.jowidgets.cap.ui.api.bean.IBeanProxy)1