Search in sources :

Example 1 with Promise

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;
}
Also used : Promise(org.activityinfo.promise.Promise) DialogHideEvent(com.sencha.gxt.widget.core.client.event.DialogHideEvent) PromptMessageBox(com.sencha.gxt.widget.core.client.box.PromptMessageBox)

Example 2 with Promise

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));
}
Also used : JobResult(org.activityinfo.model.job.JobResult) Promise(org.activityinfo.promise.Promise) UserDatabaseMeta(org.activityinfo.model.database.UserDatabaseMeta) TestingStorageProvider(org.activityinfo.store.testing.TestingStorageProvider) FormRecordUpdateBuilder(org.activityinfo.api.client.FormRecordUpdateBuilder) org.activityinfo.model.form(org.activityinfo.model.form) ResourceId(org.activityinfo.model.resource.ResourceId) NullFormSupervisor(org.activityinfo.store.query.shared.NullFormSupervisor) Analysis(org.activityinfo.model.analysis.Analysis) Optional(com.google.common.base.Optional) VersionedFormStorage(org.activityinfo.store.spi.VersionedFormStorage) NullFormScanCache(org.activityinfo.store.query.shared.NullFormScanCache) RecordLockSet(org.activityinfo.model.database.RecordLockSet) NewFormRecordBuilder(org.activityinfo.api.client.NewFormRecordBuilder) ActivityInfoClientAsync(org.activityinfo.api.client.ActivityInfoClientAsync) JobStatus(org.activityinfo.model.job.JobStatus) AnalysisUpdate(org.activityinfo.model.analysis.AnalysisUpdate) FormStorage(org.activityinfo.store.spi.FormStorage) List(java.util.List) ColumnSet(org.activityinfo.model.query.ColumnSet) QueryModel(org.activityinfo.model.query.QueryModel) RecordTransaction(org.activityinfo.model.resource.RecordTransaction) JobDescriptor(org.activityinfo.model.job.JobDescriptor) Maybe(org.activityinfo.promise.Maybe) ColumnSetBuilder(org.activityinfo.store.query.server.ColumnSetBuilder) FormTree(org.activityinfo.model.formTree.FormTree) VersionedFormStorage(org.activityinfo.store.spi.VersionedFormStorage) FormStorage(org.activityinfo.store.spi.FormStorage) VersionedFormStorage(org.activityinfo.store.spi.VersionedFormStorage)

Example 3 with Promise

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;
}
Also used : Promise(org.activityinfo.promise.Promise) GetLocations(org.activityinfo.legacy.shared.command.GetLocations) ArrayList(java.util.ArrayList) LocationResult(org.activityinfo.legacy.shared.command.result.LocationResult)

Example 4 with 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;
        }
    });
}
Also used : Promise(org.activityinfo.promise.Promise) FieldValue(org.activityinfo.model.type.FieldValue) FormField(org.activityinfo.model.form.FormField)

Example 5 with Promise

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));
}
Also used : Promise(org.activityinfo.promise.Promise) UpdateMonthlyReports(org.activityinfo.legacy.shared.command.UpdateMonthlyReports) ArrayList(java.util.ArrayList) KeyGenerator(org.activityinfo.model.legacy.KeyGenerator)

Aggregations

Promise (org.activityinfo.promise.Promise)21 SqlResultCallback (com.bedatadriven.rebar.sql.client.SqlResultCallback)10 SqlResultSet (com.bedatadriven.rebar.sql.client.SqlResultSet)10 SqlTransaction (com.bedatadriven.rebar.sql.client.SqlTransaction)10 SqlResultSetRow (com.bedatadriven.rebar.sql.client.SqlResultSetRow)6 SqlQuery (com.bedatadriven.rebar.sql.client.query.SqlQuery)4 ArrayList (java.util.ArrayList)4 Function (com.google.common.base.Function)2 List (java.util.List)2 Nullable (javax.annotation.Nullable)2 UpdateMonthlyReports (org.activityinfo.legacy.shared.command.UpdateMonthlyReports)2 FormClass (org.activityinfo.model.form.FormClass)2 FormField (org.activityinfo.model.form.FormField)2 FormInstance (org.activityinfo.model.form.FormInstance)2 ColumnSet (org.activityinfo.model.query.ColumnSet)2 QueryModel (org.activityinfo.model.query.QueryModel)2 ResourceId (org.activityinfo.model.resource.ResourceId)2 FieldValue (org.activityinfo.model.type.FieldValue)2 Record (com.extjs.gxt.ui.client.store.Record)1 Optional (com.google.common.base.Optional)1