Search in sources :

Example 46 with AsyncCallback

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);
                }
            });
        }
    });
}
Also used : ActivityFormDTO(org.activityinfo.legacy.shared.model.ActivityFormDTO) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) ArrayList(java.util.ArrayList) SqlTransaction(com.bedatadriven.rebar.sql.client.SqlTransaction) ActivityFormResults(org.activityinfo.legacy.shared.command.result.ActivityFormResults) SqlResultSetRow(com.bedatadriven.rebar.sql.client.SqlResultSetRow) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) Promise(org.activityinfo.promise.Promise) Function(com.google.common.base.Function) SqlResultSet(com.bedatadriven.rebar.sql.client.SqlResultSet) SqlResultCallback(com.bedatadriven.rebar.sql.client.SqlResultCallback) Nullable(javax.annotation.Nullable)

Example 47 with AsyncCallback

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;
}
Also used : AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback)

Example 48 with AsyncCallback

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;
}
Also used : AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback)

Example 49 with AsyncCallback

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);
}
Also used : AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) CommandException(org.activityinfo.legacy.shared.exception.CommandException) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) Test(org.junit.Test)

Example 50 with AsyncCallback

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);
                    }
                });
            }
        }
    });
}
Also used : VoidResult(org.activityinfo.legacy.shared.command.result.VoidResult) MaskingAsyncMonitor(org.activityinfo.ui.client.dispatch.monitor.MaskingAsyncMonitor) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) DeleteReport(org.activityinfo.legacy.shared.command.DeleteReport) ReportMetadataDTO(org.activityinfo.legacy.shared.model.ReportMetadataDTO)

Aggregations

AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)85 Test (org.junit.Test)13 GetSchema (org.activityinfo.shared.command.GetSchema)9 GetSchema (org.activityinfo.legacy.shared.command.GetSchema)8 SchemaDTO (org.activityinfo.shared.dto.SchemaDTO)8 FormDialogCallback (org.activityinfo.client.page.common.dialog.FormDialogCallback)7 SchemaDTO (org.activityinfo.legacy.shared.model.SchemaDTO)6 FormDialogCallback (org.activityinfo.ui.client.page.common.dialog.FormDialogCallback)6 CallbackGroup (com.google.gerrit.client.rpc.CallbackGroup)4 FormDialogTether (org.activityinfo.client.page.common.dialog.FormDialogTether)4 ProjectDTO (org.activityinfo.legacy.shared.model.ProjectDTO)4 VoidResult (org.activityinfo.shared.command.result.VoidResult)4 FormDialogTether (org.activityinfo.ui.client.page.common.dialog.FormDialogTether)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 Set (java.util.Set)3 GetActivityForm (org.activityinfo.legacy.shared.command.GetActivityForm)3 VoidResult (org.activityinfo.legacy.shared.command.result.VoidResult)3 CreateResult (org.activityinfo.shared.command.result.CreateResult)3 ProjectDTO (org.activityinfo.shared.dto.ProjectDTO)3