Search in sources :

Example 76 with AsyncCallback

use of com.google.gwt.user.client.rpc.AsyncCallback in project activityinfo by bedatadriven.

the class AdminTreeProxy method load.

@Override
public void load(DataReader<List<AdminEntityDTO>> dataReader, final Object parent, final AsyncCallback<List<AdminEntityDTO>> callback) {
    if (filter == null) {
        callback.onSuccess(new ArrayList<AdminEntityDTO>());
        return;
    }
    service.execute(new GetSchema(), new AsyncCallback<SchemaDTO>() {

        @Override
        public void onFailure(Throwable caught) {
            GWT.log("Failed to load admin entities", caught);
        }

        @Override
        public void onSuccess(SchemaDTO schema) {
            final Set<CountryDTO> countries = findCountries(schema);
            if (CollectionUtil.isEmpty(countries)) {
                callback.onSuccess(new ArrayList<AdminEntityDTO>());
                return;
            }
            initLevelsWithChildren(countries);
            GetAdminEntities request = new GetAdminEntities(toIdSet(countries), filter);
            if (parent != null) {
                assert parent instanceof AdminEntityDTO : "expecting AdminEntityDTO";
                request.setParentId(((AdminEntityDTO) parent).getId());
            }
            service.execute(request, new AsyncCallback<AdminEntityResult>() {

                @Override
                public void onFailure(Throwable caught) {
                    callback.onFailure(caught);
                }

                @Override
                public void onSuccess(AdminEntityResult result) {
                    prepareData(countries, result.getData());
                    callback.onSuccess(result.getData());
                }
            });
        }
    });
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) AdminEntityDTO(org.activityinfo.shared.dto.AdminEntityDTO) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) AdminEntityResult(org.activityinfo.shared.command.result.AdminEntityResult) ArrayList(java.util.ArrayList) GetAdminEntities(org.activityinfo.shared.command.GetAdminEntities) GetSchema(org.activityinfo.shared.command.GetSchema) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO)

Example 77 with AsyncCallback

use of com.google.gwt.user.client.rpc.AsyncCallback in project activityinfo by bedatadriven.

the class AttributeGroupFilterWidgets method draw.

public void draw(final Filter filter) {
    final Filter value = new Filter(filter);
    value.clearRestrictions(DIMENSION_TYPE);
    // prevents executing the same command needlessly
    if (prevFilter == null || !prevFilter.equals(filter)) {
        prevFilter = filter;
        Log.debug("AttributeGroupFilterWidgets called for filter " + filter);
        // retrieve all attributegroups for the current filter
        service.execute(new GetAttributeGroupsDimension(value), new AsyncCallback<AttributeGroupResult>() {

            @Override
            public void onFailure(Throwable caught) {
                GWT.log("Failed to load attributes", caught);
            }

            @Override
            public void onSuccess(final AttributeGroupResult attributeGroupResult) {
                // if the result is indeed different from the last time, (re)draw the widgets
                if (prevResult == null || !prevResult.equals(attributeGroupResult)) {
                    prevResult = attributeGroupResult;
                    Log.debug("AttributeGroupFilterWidgets drawing widgets for result: " + attributeGroupResult);
                    service.execute(new GetSchema(), new AsyncCallback<SchemaDTO>() {

                        @Override
                        public void onFailure(Throwable caught) {
                            GWT.log("Failed to load schema", caught);
                        }

                        @Override
                        public void onSuccess(final SchemaDTO schema) {
                            // clean up old widgets
                            for (AttributeGroupFilterWidget widget : widgets) {
                                panel.remove(widget);
                            }
                            duplicates.clear();
                            // decorate resultlist from schema
                            List<AttributeGroupDTO> pivotData = attributeGroupResult.getData();
                            groups = new ArrayList<AttributeGroupDTO>();
                            if (CollectionUtil.isNotEmpty(pivotData)) {
                                for (AttributeGroupDTO pivotGroup : pivotData) {
                                    AttributeGroupDTO schemaGroup = schema.getAttributeGroupById(pivotGroup.getId());
                                    if (schemaGroup != null) {
                                        groups.add(schemaGroup);
                                    }
                                }
                            }
                            // create new widgets, one for each attributegroup.
                            // remember the old selection
                            List<Integer> selection = getSelectedIds();
                            widgets = new ArrayList<AttributeGroupFilterWidget>();
                            for (AttributeGroupDTO group : groups) {
                                // create
                                AttributeGroupFilterWidget widget = new AttributeGroupFilterWidget(group);
                                // set old selection
                                widget.setSelection(selection);
                                // what to do when value changes
                                if (valueChangeHandler != null) {
                                    widget.addValueChangeHandler(valueChangeHandler);
                                }
                                // already been added
                                if (isNoDuplicate(widget)) {
                                    widgets.add(widget);
                                    panel.add(widget);
                                } else {
                                    // otherwise add to collection of duplicates
                                    duplicates.put(group.getName().toLowerCase(), widget);
                                }
                            }
                            if (drawCallback != null) {
                                drawCallback.onSuccess(null);
                            }
                        }
                    });
                }
            }
        });
    }
}
Also used : AttributeGroupDTO(org.activityinfo.shared.dto.AttributeGroupDTO) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) AttributeGroupResult(org.activityinfo.shared.command.result.AttributeGroupResult) Filter(org.activityinfo.shared.command.Filter) GetAttributeGroupsDimension(org.activityinfo.shared.command.GetAttributeGroupsDimension) GetSchema(org.activityinfo.shared.command.GetSchema)

Example 78 with AsyncCallback

use of com.google.gwt.user.client.rpc.AsyncCallback in project activityinfo by bedatadriven.

the class DesignPresenter method createEntity.

private void createEntity(final ModelData parent, final EntityDTO newEntity) {
    view.showNewForm(newEntity, new FormDialogCallback() {

        @Override
        public void onValidated(final FormDialogTether tether) {
            service.execute(new CreateEntity(newEntity), tether, new AsyncCallback<CreateResult>() {

                @Override
                public void onFailure(Throwable caught) {
                    GWT.log(caught.getMessage());
                }

                @Override
                public void onSuccess(CreateResult result) {
                    // todo add
                    newEntity.set("id", result.getNewId());
                    if (parent == null) {
                        treeStore.add(newEntity, false);
                    } else {
                        treeStore.add(parent, newEntity, false);
                    }
                    if (newEntity instanceof ActivityDTO) {
                        treeStore.add(newEntity, new AttributeGroupFolder(messages.attributes()), false);
                        treeStore.add(newEntity, new IndicatorFolder(messages.indicators()), false);
                    }
                    tether.hide();
                    eventBus.fireEvent(AppEvents.SCHEMA_CHANGED);
                }
            });
        }
    });
}
Also used : CreateEntity(org.activityinfo.shared.command.CreateEntity) FormDialogCallback(org.activityinfo.client.page.common.dialog.FormDialogCallback) CreateResult(org.activityinfo.shared.command.result.CreateResult) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) FormDialogTether(org.activityinfo.client.page.common.dialog.FormDialogTether) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO)

Example 79 with AsyncCallback

use of com.google.gwt.user.client.rpc.AsyncCallback in project activityinfo by bedatadriven.

the class DbProjectEditor method onAdd.

@Override
protected void onAdd() {
    final ProjectDTO newProject = new ProjectDTO();
    this.view.showAddDialog(newProject, new FormDialogCallback() {

        @Override
        public void onValidated(final FormDialogTether dlg) {
            service.execute(new AddProject(db.getId(), newProject), dlg, new AsyncCallback<CreateResult>() {

                @Override
                public void onFailure(Throwable caught) {
                    if (caught instanceof DuplicatePartnerException) {
                        MessageBox.alert(I18N.CONSTANTS.error(), I18N.CONSTANTS.errorOnServer(), null);
                    } else {
                        MessageBox.alert(I18N.CONSTANTS.error(), I18N.CONSTANTS.errorOnServer(), null);
                    }
                }

                @Override
                public void onSuccess(CreateResult result) {
                    newProject.setId(result.getNewId());
                    store.add(newProject);
                    db.getProjects().add(newProject);
                    eventBus.fireEvent(AppEvents.SCHEMA_CHANGED);
                    dlg.hide();
                }
            });
        }
    });
}
Also used : ProjectDTO(org.activityinfo.shared.dto.ProjectDTO) FormDialogCallback(org.activityinfo.client.page.common.dialog.FormDialogCallback) CreateResult(org.activityinfo.shared.command.result.CreateResult) AddProject(org.activityinfo.shared.command.AddProject) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) DuplicatePartnerException(org.activityinfo.shared.exception.DuplicatePartnerException) FormDialogTether(org.activityinfo.client.page.common.dialog.FormDialogTether)

Example 80 with AsyncCallback

use of com.google.gwt.user.client.rpc.AsyncCallback in project activityinfo by bedatadriven.

the class DbTargetEditor method onEdit.

@Override
protected void onEdit(final TargetDTO dto) {
    this.view.showAddDialog(dto, db, new FormDialogCallback() {

        @Override
        public void onValidated(final FormDialogTether dlg) {
            final Record record = store.getRecord(dto);
            service.execute(new UpdateEntity(dto, getChangedProperties(record)), dlg, new AsyncCallback<VoidResult>() {

                @Override
                public void onFailure(Throwable caught) {
                }

                @Override
                public void onSuccess(VoidResult result) {
                    PartnerDTO partner = db.getPartnerById((Integer) record.get("partnerId"));
                    dto.setPartner(partner);
                    ProjectDTO project = db.getProjectById((Integer) record.get("projectId"));
                    dto.setProject(project);
                    store.commitChanges();
                    eventBus.fireEvent(AppEvents.SCHEMA_CHANGED);
                    dlg.hide();
                }
            });
        }
    });
}
Also used : ProjectDTO(org.activityinfo.shared.dto.ProjectDTO) FormDialogCallback(org.activityinfo.client.page.common.dialog.FormDialogCallback) UpdateEntity(org.activityinfo.shared.command.UpdateEntity) VoidResult(org.activityinfo.shared.command.result.VoidResult) PartnerDTO(org.activityinfo.shared.dto.PartnerDTO) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) FormDialogTether(org.activityinfo.client.page.common.dialog.FormDialogTether) Record(com.extjs.gxt.ui.client.store.Record)

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