Search in sources :

Example 1 with IResultCallback

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

the class CsvExportExecutor method execute.

@Override
public void execute(final IExecutionContext executionContext, final List<IBeanProxy<BEAN_TYPE>> beans, final ICsvExportParameter parameter) throws Exception {
    final IExecutionTask executionTask = CapUiToolkit.executionTaskFactory().create(executionContext);
    final IExecutionTaskDialog executionTaskDialog = createExecutionTaskDialog(executionContext, executionTask);
    final IResultCallback<String> resultCallback = new ResultCallback(executionTaskDialog);
    final Runnable exportRunnable;
    if (parameter.getExportType() == ExportType.SELECTION) {
        final List<IBeanDto> beanDtos = createBeanDtos(beans, model.getPropertyNames());
        exportRunnable = new CsvExportSelectedRunnable(model, resultCallback, parameter, beanDtos, executionTask);
    } else {
        final List<IBeanDto> addedData = createBeanDtos(model.getAddedData(), model.getPropertyNames());
        exportRunnable = new CsvExportTableRunnable(model, addedData, resultCallback, parameter, executionTask);
    }
    executionTaskDialog.setVisible(true);
    executor.execute(exportRunnable);
}
Also used : AbstractUiResultCallback(org.jowidgets.cap.ui.tools.execution.AbstractUiResultCallback) IResultCallback(org.jowidgets.cap.common.api.execution.IResultCallback) IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) IExecutionTaskDialog(org.jowidgets.cap.ui.api.widgets.IExecutionTaskDialog) IExecutionTask(org.jowidgets.cap.ui.api.execution.IExecutionTask)

Example 2 with IResultCallback

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

the class AbstractCapServiceInvocationHandler method invoke.

@Override
public final Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
    final Class<?>[] parameterTypes = method.getParameterTypes();
    final IExecutionCallback executionCallback = getExecutionCallback(parameterTypes, args);
    final int resultCallbackIndex = getFirstMatchingIndex(IResultCallback.class, parameterTypes);
    if (resultCallbackIndex == -1) {
        if (executionCallback != null && executionCallback.isCanceled()) {
            throw new ServiceCanceledException();
        }
        return invokeSyncSignature(method, args, executionCallback);
    } else {
        @SuppressWarnings("unchecked") final IResultCallback<Object> resultCallback = (IResultCallback<Object>) args[resultCallbackIndex];
        if (executionCallback != null && executionCallback.isCanceled()) {
            resultCallback.exception(new ServiceCanceledException());
            return null;
        }
        return invokeAsyncSignature(method, args, resultCallbackIndex, resultCallback, executionCallback);
    }
}
Also used : IExecutionCallback(org.jowidgets.cap.common.api.execution.IExecutionCallback) ServiceCanceledException(org.jowidgets.cap.common.api.exception.ServiceCanceledException) IResultCallback(org.jowidgets.cap.common.api.execution.IResultCallback)

Example 3 with IResultCallback

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

the class RemoteMethodInvocationHandler method getFilteredArgs.

/**
 * Filter the callback arguments
 *
 * @param args The args to filter
 * @param parameterTypes
 * @return the filtered args
 */
@SuppressWarnings("unchecked")
private Object[] getFilteredArgs(final Object[] args, final Class<?>[] parameterTypes) {
    if (args != null) {
        final Object[] result = new Object[args.length];
        for (int i = 0; i < args.length; i++) {
            final Object object = args[i];
            if (object instanceof IResultCallback<?>) {
                result[i] = null;
            } else if (object instanceof IExecutionCallback) {
                result[i] = null;
            } else if (object instanceof InputStream) {
                result[i] = new InputStreamDummy();
            } else if (InputStream[].class.isAssignableFrom(parameterTypes[i])) {
                final InputStream[] inputStreams = (InputStream[]) object;
                if (inputStreams != null) {
                    final InputStreamDummy[] inputStreamDummies = new InputStreamDummy[inputStreams.length];
                    for (int j = 0; j < inputStreams.length; j++) {
                        if (inputStreams[j] != null) {
                            inputStreamDummies[j] = new InputStreamDummy();
                        } else {
                            inputStreamDummies[j] = null;
                        }
                    }
                    result[i] = inputStreamDummies;
                } else {
                    result[i] = null;
                }
            } else if (Iterable.class.isAssignableFrom(parameterTypes[i])) {
                final Iterable<?> iterable = (Iterable<?>) object;
                if (iterable != null && isIterableOfType(iterable, InputStream.class)) {
                    if (!Collection.class.isAssignableFrom(parameterTypes[i])) {
                        throw new IllegalArgumentException("Iterables that hold InputStreams must be Collections");
                    }
                    final Collection<InputStreamDummy> inputStreamDummies;
                    try {
                        inputStreamDummies = (Collection<InputStreamDummy>) iterable.getClass().newInstance();
                    } catch (final Exception e) {
                        throw new IllegalArgumentException("Collections that holds input streams must have a public default constructor", e);
                    }
                    for (final Object element : iterable) {
                        if (element instanceof InputStream) {
                            inputStreamDummies.add(new InputStreamDummy());
                        } else if (element != null) {
                            throw new IllegalArgumentException("Collections with mixed types must not contain InputStreams");
                        } else {
                            inputStreamDummies.add(null);
                        }
                    }
                    result[i] = inputStreamDummies;
                } else {
                    result[i] = object;
                }
            } else {
                result[i] = object;
            }
        }
        return result;
    } else {
        return new Object[0];
    }
}
Also used : InputStream(java.io.InputStream) InputStreamDummy(org.jowidgets.cap.remoting.common.InputStreamDummy) IExecutionCallback(org.jowidgets.cap.common.api.execution.IExecutionCallback) Collection(java.util.Collection) IResultCallback(org.jowidgets.cap.common.api.execution.IResultCallback)

Aggregations

IResultCallback (org.jowidgets.cap.common.api.execution.IResultCallback)3 IExecutionCallback (org.jowidgets.cap.common.api.execution.IExecutionCallback)2 InputStream (java.io.InputStream)1 Collection (java.util.Collection)1 IBeanDto (org.jowidgets.cap.common.api.bean.IBeanDto)1 ServiceCanceledException (org.jowidgets.cap.common.api.exception.ServiceCanceledException)1 InputStreamDummy (org.jowidgets.cap.remoting.common.InputStreamDummy)1 IExecutionTask (org.jowidgets.cap.ui.api.execution.IExecutionTask)1 IExecutionTaskDialog (org.jowidgets.cap.ui.api.widgets.IExecutionTaskDialog)1 AbstractUiResultCallback (org.jowidgets.cap.ui.tools.execution.AbstractUiResultCallback)1