Search in sources :

Example 1 with AbstractUiResultCallback

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

the class BeanLinkCreatorCommand method createResultCallback.

private IResultCallback<List<IBeanDto>> createResultCallback(final List<IBeanProxy<SOURCE_BEAN_TYPE>> selection, final IExecutionContext executionContext) {
    return new AbstractUiResultCallback<List<IBeanDto>>() {

        @Override
        protected void finishedUi(final List<IBeanDto> result) {
            for (final IBeanProxy<SOURCE_BEAN_TYPE> bean : selection) {
                bean.setExecutionTask(null);
            }
            if (linkedModel != null) {
                if (Cardinality.LESS_OR_EQUAL_ONE.equals(linkedCardinality)) {
                    linkedModel.removeAllBeans();
                }
                for (final IBeanDto resultBean : result) {
                    linkedModel.addBeanDto(resultBean);
                }
            }
            executionObservable.fireAfterExecutionSuccess(executionContext, result);
        }

        @Override
        protected void exceptionUi(final Throwable exception) {
            int beanIndex = 0;
            for (final IBeanProxy<SOURCE_BEAN_TYPE> bean : selection) {
                bean.setExecutionTask(null);
                if (!(exception instanceof ServiceCanceledException)) {
                    bean.addMessage(exceptionConverter.convert(getShortErrorMessage(), selection, beanIndex++, bean, exception));
                }
            }
            executionObservable.fireAfterExecutionError(executionContext, exception);
        }

        private String getShortErrorMessage() {
            final String actionText = executionContext.getAction().getText().replaceAll("\\.", "").trim();
            return MessageReplacer.replace(SHORT_ERROR.get(), actionText);
        }
    };
}
Also used : AbstractUiResultCallback(org.jowidgets.cap.ui.tools.execution.AbstractUiResultCallback) IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) List(java.util.List) LinkedList(java.util.LinkedList) ServiceCanceledException(org.jowidgets.cap.common.api.exception.ServiceCanceledException) IBeanLinkPanelBluePrint(org.jowidgets.cap.ui.api.widgets.IBeanLinkPanelBluePrint) IBeanLinkDialogBluePrint(org.jowidgets.cap.ui.api.widgets.IBeanLinkDialogBluePrint) IBeanTableBluePrint(org.jowidgets.cap.ui.api.widgets.IBeanTableBluePrint) IBeanFormBluePrint(org.jowidgets.cap.ui.api.widgets.IBeanFormBluePrint)

Example 2 with AbstractUiResultCallback

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

the class PasteLinkCommand method createResultCallback.

private IResultCallback<List<IBeanDto>> createResultCallback(final List<IBeanProxy<SOURCE_BEAN_TYPE>> selection, final IExecutionContext executionContext) {
    return new AbstractUiResultCallback<List<IBeanDto>>() {

        @Override
        protected void finishedUi(final List<IBeanDto> result) {
            for (final IBeanProxy<SOURCE_BEAN_TYPE> bean : selection) {
                bean.setExecutionTask(null);
            }
            if (linkedModel != null) {
                if (Cardinality.LESS_OR_EQUAL_ONE.equals(linkedCardinality)) {
                    linkedModel.removeAllBeans();
                }
                for (final IBeanDto resultBean : result) {
                    linkedModel.addBeanDto(resultBean);
                }
            }
            executionObservable.fireAfterExecutionSuccess(executionContext, result);
        }

        @Override
        protected void exceptionUi(final Throwable exception) {
            int beanIndex = 0;
            for (final IBeanProxy<SOURCE_BEAN_TYPE> bean : selection) {
                bean.setExecutionTask(null);
                if (!(exception instanceof ServiceCanceledException)) {
                    bean.addMessage(exceptionConverter.convert(getShortErrorMessage(), selection, beanIndex++, bean, exception));
                }
            }
            executionObservable.fireAfterExecutionError(executionContext, exception);
        }

        private String getShortErrorMessage() {
            final String actionText = executionContext.getAction().getText().replaceAll("\\.", "").trim();
            return MessageReplacer.replace(SHORT_ERROR.get(), actionText);
        }
    };
}
Also used : AbstractUiResultCallback(org.jowidgets.cap.ui.tools.execution.AbstractUiResultCallback) IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) LinkedList(java.util.LinkedList) List(java.util.List) ServiceCanceledException(org.jowidgets.cap.common.api.exception.ServiceCanceledException)

Aggregations

LinkedList (java.util.LinkedList)2 List (java.util.List)2 IBeanDto (org.jowidgets.cap.common.api.bean.IBeanDto)2 ServiceCanceledException (org.jowidgets.cap.common.api.exception.ServiceCanceledException)2 AbstractUiResultCallback (org.jowidgets.cap.ui.tools.execution.AbstractUiResultCallback)2 IBeanFormBluePrint (org.jowidgets.cap.ui.api.widgets.IBeanFormBluePrint)1 IBeanLinkDialogBluePrint (org.jowidgets.cap.ui.api.widgets.IBeanLinkDialogBluePrint)1 IBeanLinkPanelBluePrint (org.jowidgets.cap.ui.api.widgets.IBeanLinkPanelBluePrint)1 IBeanTableBluePrint (org.jowidgets.cap.ui.api.widgets.IBeanTableBluePrint)1