Search in sources :

Example 1 with BatchResult

use of org.activityinfo.legacy.shared.command.result.BatchResult in project activityinfo by bedatadriven.

the class DbUserEditorActions method save.

public void save(final NavigationCallback callback) {
    BatchCommand batch = new BatchCommand();
    for (Record record : store.getModifiedRecords()) {
        batch.add(new UpdateUserPermissions(db.getId(), (UserPermissionDTO) record.getModel()));
    }
    dispatcher.execute(batch, new MaskingAsyncMonitor(panel, I18N.CONSTANTS.saving()), new AsyncCallback<BatchResult>() {

        @Override
        public void onFailure(Throwable caught) {
            // handled by monitor
            if (callback != null) {
                callback.onDecided(false);
            }
        }

        @Override
        public void onSuccess(BatchResult result) {
            store.commitChanges();
            panel.setModified(false);
            if (callback != null) {
                callback.onDecided(true);
            }
        }
    });
}
Also used : UpdateUserPermissions(org.activityinfo.legacy.shared.command.UpdateUserPermissions) MaskingAsyncMonitor(org.activityinfo.ui.client.dispatch.monitor.MaskingAsyncMonitor) BatchCommand(org.activityinfo.legacy.shared.command.BatchCommand) Record(com.extjs.gxt.ui.client.store.Record) BatchResult(org.activityinfo.legacy.shared.command.result.BatchResult) UserPermissionDTO(org.activityinfo.legacy.shared.model.UserPermissionDTO)

Example 2 with BatchResult

use of org.activityinfo.legacy.shared.command.result.BatchResult in project activityinfo by bedatadriven.

the class DbEditor method deleteEntity.

private void deleteEntity(EntityDTO selectedEntity) {
    BatchCommand batchCommand = unsavedChanges();
    batchCommand.add(new Delete(selectedEntity));
    service.execute(batchCommand, new MaskingAsyncMonitor(container, I18N.CONSTANTS.saving()), new AsyncCallback<BatchResult>() {

        @Override
        public void onFailure(Throwable caught) {
        // Failure case handled by MaskingAsyncMonitor
        }

        @Override
        public void onSuccess(BatchResult result) {
            treeStore.commitChanges();
            treeStore.remove(selectedEntity);
            eventBus.fireEvent(AppEvents.SCHEMA_CHANGED);
        }
    });
}
Also used : MaskingAsyncMonitor(org.activityinfo.ui.client.dispatch.monitor.MaskingAsyncMonitor) BatchResult(org.activityinfo.legacy.shared.command.result.BatchResult)

Example 3 with BatchResult

use of org.activityinfo.legacy.shared.command.result.BatchResult in project activityinfo by bedatadriven.

the class AbstractEditorGridPresenter method requestToNavigateAway.

/*
     * The user has chosen to navigate away from this page We will automatically
     * try to save any unsaved changes, but if it fails, we give the user a
     * choice between retrying and and discarding changes
     */
@Override
public void requestToNavigateAway(PageState place, final NavigationCallback callback) {
    if (getModifiedRecords().size() == 0) {
        callback.onDecided(true);
    } else {
        final SavePromptMessageBox box = new SavePromptMessageBox();
        box.show(new SaveChangesCallback() {

            @Override
            public void save(AsyncMonitor monitor) {
                service.execute(createSaveCommand(), view.getSavingMonitor(), new SuccessCallback<BatchResult>() {

                    @Override
                    public void onSuccess(BatchResult result) {
                        box.hide();
                        getStore().commitChanges();
                        callback.onDecided(true);
                    }
                });
            }

            @Override
            public void cancel() {
                box.hide();
                callback.onDecided(false);
            }

            @Override
            public void discard() {
                box.hide();
                callback.onDecided(true);
            }
        });
    }
}
Also used : SuccessCallback(org.activityinfo.ui.client.dispatch.callback.SuccessCallback) SavePromptMessageBox(org.activityinfo.ui.client.page.common.dialog.SavePromptMessageBox) SaveChangesCallback(org.activityinfo.ui.client.page.common.dialog.SaveChangesCallback) BatchResult(org.activityinfo.legacy.shared.command.result.BatchResult) AsyncMonitor(org.activityinfo.ui.client.dispatch.AsyncMonitor)

Example 4 with BatchResult

use of org.activityinfo.legacy.shared.command.result.BatchResult in project activityinfo by bedatadriven.

the class ShareReportDialog method show.

public void show(final Report report) {
    if (report.getIndicators().isEmpty()) {
        MessageBox.alert(I18N.CONSTANTS.alert(), I18N.CONSTANTS.unableToShareReport(), null);
        return;
    }
    super.show();
    this.currentReport = report;
    // we need to combine the databases which already have visiblity with
    // those that could potentially be added
    BatchCommand batch = new BatchCommand();
    batch.add(new GetIndicators(currentReport.getIndicators()));
    batch.add(new GetReportVisibility(currentReport.getId()));
    dispatcher.execute(batch, new MaskingAsyncMonitor(grid, I18N.CONSTANTS.loading()), new SuccessCallback<BatchResult>() {

        @Override
        public void onSuccess(BatchResult batch) {
            populateGrid((IndicatorResult) batch.getResult(0), (ReportVisibilityResult) batch.getResult(1));
        }
    });
}
Also used : IndicatorResult(org.activityinfo.legacy.shared.command.result.IndicatorResult) ReportVisibilityResult(org.activityinfo.legacy.shared.command.result.ReportVisibilityResult) MaskingAsyncMonitor(org.activityinfo.ui.client.dispatch.monitor.MaskingAsyncMonitor) BatchResult(org.activityinfo.legacy.shared.command.result.BatchResult)

Example 5 with BatchResult

use of org.activityinfo.legacy.shared.command.result.BatchResult in project activityinfo by bedatadriven.

the class BatchCommandHandlerAsync method execute.

@Override
public void execute(BatchCommand batch, ExecutionContext context, final AsyncCallback<BatchResult> callback) {
    if (batch.getCommands().isEmpty()) {
        LOGGER.warning("Received empty batch command");
        callback.onSuccess(new BatchResult(Lists.<CommandResult>newArrayList()));
    } else {
        final ArrayList<CommandResult> results = new ArrayList<>();
        for (Command command : batch.getCommands()) {
            results.add(null);
        }
        final boolean[] finished = new boolean[batch.getCommands().size()];
        final List<Throwable> exceptions = Lists.newArrayList();
        for (int i = 0; i != batch.getCommands().size(); ++i) {
            final int commandIndex = i;
            context.execute(batch.getCommands().get(i), new AsyncCallback<CommandResult>() {

                @Override
                public void onFailure(Throwable caught) {
                    if (exceptions.isEmpty()) {
                        exceptions.add(caught);
                        callback.onFailure(caught);
                    }
                }

                @Override
                public void onSuccess(CommandResult result) {
                    results.set(commandIndex, result);
                    finished[commandIndex] = true;
                    if (all(finished)) {
                        callback.onSuccess(new BatchResult(results));
                    }
                }
            });
        }
    }
}
Also used : Command(org.activityinfo.legacy.shared.command.Command) BatchCommand(org.activityinfo.legacy.shared.command.BatchCommand) ArrayList(java.util.ArrayList) BatchResult(org.activityinfo.legacy.shared.command.result.BatchResult) CommandResult(org.activityinfo.legacy.shared.command.result.CommandResult)

Aggregations

BatchResult (org.activityinfo.legacy.shared.command.result.BatchResult)7 BatchCommand (org.activityinfo.legacy.shared.command.BatchCommand)4 MaskingAsyncMonitor (org.activityinfo.ui.client.dispatch.monitor.MaskingAsyncMonitor)3 ArrayList (java.util.ArrayList)2 Command (org.activityinfo.legacy.shared.command.Command)2 CommandResult (org.activityinfo.legacy.shared.command.result.CommandResult)2 Record (com.extjs.gxt.ui.client.store.Record)1 UpdateUserPermissions (org.activityinfo.legacy.shared.command.UpdateUserPermissions)1 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)1 IndicatorResult (org.activityinfo.legacy.shared.command.result.IndicatorResult)1 ReportVisibilityResult (org.activityinfo.legacy.shared.command.result.ReportVisibilityResult)1 UserPermissionDTO (org.activityinfo.legacy.shared.model.UserPermissionDTO)1 AsyncMonitor (org.activityinfo.ui.client.dispatch.AsyncMonitor)1 SuccessCallback (org.activityinfo.ui.client.dispatch.callback.SuccessCallback)1 SaveChangesCallback (org.activityinfo.ui.client.page.common.dialog.SaveChangesCallback)1 SavePromptMessageBox (org.activityinfo.ui.client.page.common.dialog.SavePromptMessageBox)1