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