use of com.google.gwt.user.client.rpc.AsyncCallback in project activityinfo by bedatadriven.
the class GetActivityFormsHandler method execute.
@Override
public void execute(GetActivityForms command, final ExecutionContext context, final AsyncCallback<ActivityFormResults> callback) {
composeQuery(command.getFilter()).execute(context.getTransaction(), new SqlResultCallback() {
@Override
public void onSuccess(SqlTransaction tx, final SqlResultSet results) {
context.execute(new GetSchema(), new AsyncCallback<SchemaDTO>() {
@Override
public void onFailure(Throwable caught) {
callback.onFailure(caught);
}
@Override
public void onSuccess(SchemaDTO schema) {
LOGGER.log(Level.INFO, "Forms matching filter: " + results.getRows().size());
final List<Promise<ActivityFormDTO>> pending = new ArrayList<>();
for (SqlResultSetRow row : results.getRows()) {
int activityId = row.getInt("activityId");
boolean visible = (schema.getActivityById(activityId) != null);
if (visible) {
pending.add(fetchForm(context, activityId));
}
}
LOGGER.log(Level.INFO, "Forms pending: " + pending.size());
Promise.waitAll(pending).then(new Function<Void, ActivityFormResults>() {
@Nullable
@Override
public ActivityFormResults apply(@Nullable Void aVoid) {
LOGGER.log(Level.INFO, "Form loading completed.");
List<ActivityFormDTO> forms = new ArrayList<>();
for (Promise<ActivityFormDTO> pendingForm : pending) {
forms.add(pendingForm.get());
}
return new ActivityFormResults(forms);
}
}).then(callback);
}
});
}
});
}
use of com.google.gwt.user.client.rpc.AsyncCallback in project activityinfo by bedatadriven.
the class RemoteDispatcherTest method makeCallbackThatExpectsNonNullSuccess.
private AsyncCallback makeCallbackThatExpectsNonNullSuccess() {
AsyncCallback callback = createMock(AsyncCallback.class);
callback.onSuccess(notNull());
replay(callback);
return callback;
}
use of com.google.gwt.user.client.rpc.AsyncCallback in project activityinfo by bedatadriven.
the class RemoteDispatcherTest method makeCallbackThatExpectsFailure.
private AsyncCallback makeCallbackThatExpectsFailure() {
AsyncCallback callback = createMock(AsyncCallback.class);
callback.onFailure(isA(Throwable.class));
replay(callback);
return callback;
}
use of com.google.gwt.user.client.rpc.AsyncCallback in project activityinfo by bedatadriven.
the class RemoteDispatcherTest method commandExceptionsShouldBeCalledBackWithFailure.
@Test
public void commandExceptionsShouldBeCalledBackWithFailure() {
expectRemoteCall(new GetSchema());
// remote call succeeded,
andCallbackWihSuccess(new CommandException());
// command failed
replay(service);
AsyncCallback callback = makeCallbackThatExpectsFailure();
dispatcher.execute(new GetSchema(), callback);
processPendingCommands();
verify(service, callback);
}
use of com.google.gwt.user.client.rpc.AsyncCallback in project activityinfo by bedatadriven.
the class ReportGridPanel method delete.
private void delete() {
final ReportMetadataDTO report = grid.getSelectionModel().getSelectedItem();
MessageBox.confirm(I18N.CONSTANTS.delete(), I18N.MESSAGES.confirmDeleteReport(report.getTitle()), new Listener<MessageBoxEvent>() {
@Override
public void handleEvent(MessageBoxEvent be) {
if (be.getButtonClicked().getItemId().equals(Dialog.YES)) {
dispatcher.execute(new DeleteReport(report.getId()), new MaskingAsyncMonitor(ReportGridPanel.this, I18N.CONSTANTS.delete()), new AsyncCallback<VoidResult>() {
@Override
public void onFailure(Throwable caught) {
// handled by monitor
}
@Override
public void onSuccess(VoidResult result) {
grid.getStore().remove(report);
}
});
}
}
});
}
Aggregations