use of org.activityinfo.promise.Promise in project activityinfo by bedatadriven.
the class AnalysisView method ensureTitle.
private Promise<Void> ensureTitle() {
if (model.getWorking().isLoading()) {
return new Promise<>();
}
if (model.getWorking().get().getLabel().isPresent()) {
return Promise.done();
}
Promise<Void> result = new Promise<>();
PromptMessageBox box = new PromptMessageBox(I18N.CONSTANTS.save(), I18N.CONSTANTS.chooseReportTitle());
box.show();
box.addDialogHideHandler(new DialogHideEvent.DialogHideHandler() {
@Override
public void onDialogHide(DialogHideEvent event) {
if (event.getHideButton() == Dialog.PredefinedButton.OK) {
AnalysisView.this.model.updateTitle(box.getTextField().getValue());
result.resolve(null);
}
}
});
return result;
}
use of org.activityinfo.promise.Promise in project activityinfo by bedatadriven.
the class AsyncClientStub method getRecordVersionRange.
@Override
public Promise<FormSyncSet> getRecordVersionRange(String formId, long localVersion, long toVersion) {
if (!connected) {
return offlineResult();
}
Optional<FormStorage> form = storageProvider.getForm(ResourceId.valueOf(formId));
if (!form.isPresent()) {
return Promise.rejected(new RuntimeException("No such form"));
}
VersionedFormStorage formStorage = (VersionedFormStorage) form.get();
return Promise.resolved(formStorage.getVersionRange(localVersion, toVersion, resourceId -> true));
}
use of org.activityinfo.promise.Promise in project activityinfo by bedatadriven.
the class LocationFilterPanel method applyInternalValue.
private Promise<LocationResult> applyInternalValue() {
Promise<LocationResult> promise = new Promise<>();
promise.then(new Function<LocationResult, Object>() {
@Override
public Object apply(LocationResult input) {
filterToolBar.setApplyFilterEnabled(false);
filterToolBar.setRemoveFilterEnabled(value.isRestricted(DimensionType.Location));
store.removeAll();
store.add(input.getData());
return null;
}
});
dispatcher.execute(new GetLocations(new ArrayList<>(value.getRestrictions(DimensionType.Location))), promise);
return promise;
}
use of org.activityinfo.promise.Promise in project activityinfo by bedatadriven.
the class SimpleFormPanel method setValue.
public Promise<Void> setValue(FormInstance instance) {
model.setWorkingRootInstance(instance);
List<Promise<Void>> tasks = Lists.newArrayList();
for (FieldContainer container : widgetCreator.getContainers().values()) {
FormField field = container.getField();
FieldValue value = model.getWorkingRootInstance().get(field.getId(), field.getType());
if (value != null && value.getTypeClass() == field.getType().getTypeClass()) {
tasks.add(container.getFieldWidget().setValue(value));
} else {
container.getFieldWidget().clearValue();
}
container.setValid();
}
return Promise.waitAll(tasks).then(new Function<Void, Void>() {
@Override
public Void apply(Void input) {
// invoke relevance handler once values are set
relevanceHandler.onValueChange();
return null;
}
});
}
use of org.activityinfo.promise.Promise in project activityinfo by bedatadriven.
the class UpdateMonthlyReportsAsync method executeUpdates.
private Promise<VoidResult> executeUpdates(SqlTransaction tx, UpdateMonthlyReports command, Map<Month, Integer> periodMap) {
KeyGenerator generator = new KeyGenerator();
List<Promise<Void>> pendingUpdates = new ArrayList<>();
for (UpdateMonthlyReports.Change change : command.getChanges()) {
Integer periodId = periodMap.get(change.getMonth());
if (periodId == null) {
periodId = generator.generateInt();
periodMap.put(change.getMonth(), periodId);
pendingUpdates.add(insertPeriod(tx, command.getSiteId(), periodId, change.getMonth()));
}
pendingUpdates.add(deleteValue(tx, periodId, change.getIndicatorId()));
if (change.getValue() != null) {
pendingUpdates.add(insertValue(tx, periodId, change.getIndicatorId(), change.getValue()));
}
}
return Promise.waitAll(pendingUpdates).then(Functions.<VoidResult>constant(null));
}
Aggregations