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);
}
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);
}
}
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];
}
}
Aggregations