Search in sources :

Example 21 with CreateResult

use of org.activityinfo.shared.command.result.CreateResult 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 22 with CreateResult

use of org.activityinfo.shared.command.result.CreateResult 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 23 with CreateResult

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

the class DbTargetEditor method onAdd.

@Override
protected void onAdd() {
    final TargetDTO newTarget = new TargetDTO();
    this.view.showAddDialog(newTarget, db, new FormDialogCallback() {

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

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

                @Override
                public void onSuccess(CreateResult result) {
                    newTarget.setId(result.getNewId());
                    PartnerDTO partner = db.getPartnerById((Integer) newTarget.get("partnerId"));
                    newTarget.setPartner(partner);
                    ProjectDTO project = db.getProjectById((Integer) newTarget.get("projectId"));
                    newTarget.setProject(project);
                    store.add(newTarget);
                    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) CreateResult(org.activityinfo.shared.command.result.CreateResult) PartnerDTO(org.activityinfo.shared.dto.PartnerDTO) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) FormDialogTether(org.activityinfo.client.page.common.dialog.FormDialogTether) AddTarget(org.activityinfo.shared.command.AddTarget) TargetDTO(org.activityinfo.shared.dto.TargetDTO)

Example 24 with CreateResult

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

the class SiteDialog method saveNewSite.

private void saveNewSite() {
    final SiteDTO newSite = new SiteDTO();
    newSite.setId(new KeyGenerator().generateInt());
    newSite.setActivityId(activity.getId());
    if (activity.getReportingFrequency() == ActivityDTO.REPORT_ONCE) {
        newSite.setReportingPeriodId(new KeyGenerator().generateInt());
    }
    updateModel(newSite);
    dispatcher.execute(new CreateSite(newSite), new AsyncCallback<CreateResult>() {

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

        @Override
        public void onSuccess(CreateResult result) {
            hide();
            callback.onSaved(newSite);
        }
    });
}
Also used : CreateResult(org.activityinfo.shared.command.result.CreateResult) SiteDTO(org.activityinfo.shared.dto.SiteDTO) KeyGenerator(org.activityinfo.client.local.command.handler.KeyGenerator) CreateSite(org.activityinfo.shared.command.CreateSite)

Example 25 with CreateResult

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

the class ReportDesignPage method performCreate.

private void performCreate() {
    currentModel.setTitle(currentModel.getTitle() + " (" + I18N.CONSTANTS.copy() + ")");
    dispatcher.execute(new CreateReport(currentModel), new AsyncCallback<CreateResult>() {

        @Override
        public void onFailure(final Throwable caught) {
        }

        @Override
        public void onSuccess(final CreateResult created) {
            eventBus.fireEvent(new NavigationEvent(NavigationHandler.NAVIGATION_REQUESTED, new ReportDesignPageState(created.getNewId())));
        }
    });
}
Also used : NavigationEvent(org.activityinfo.client.event.NavigationEvent) CreateResult(org.activityinfo.shared.command.result.CreateResult) CreateReport(org.activityinfo.shared.command.CreateReport)

Aggregations

CreateResult (org.activityinfo.shared.command.result.CreateResult)36 Test (org.junit.Test)17 SchemaDTO (org.activityinfo.shared.dto.SchemaDTO)9 Date (java.util.Date)8 GetSchema (org.activityinfo.shared.command.GetSchema)8 PartnerDTO (org.activityinfo.shared.dto.PartnerDTO)8 CreateSite (org.activityinfo.shared.command.CreateSite)7 SiteDTO (org.activityinfo.shared.dto.SiteDTO)7 AddPartner (org.activityinfo.shared.command.AddPartner)6 ActivityDTO (org.activityinfo.shared.dto.ActivityDTO)6 ProjectDTO (org.activityinfo.shared.dto.ProjectDTO)6 OnDataSet (org.activityinfo.server.database.OnDataSet)5 UserDatabase (org.activityinfo.server.database.hibernate.entity.UserDatabase)5 CreateEntity (org.activityinfo.shared.command.CreateEntity)5 DuplicateCreateResult (org.activityinfo.shared.command.result.DuplicateCreateResult)5 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)4 FormDialogCallback (org.activityinfo.client.page.common.dialog.FormDialogCallback)4 FormDialogTether (org.activityinfo.client.page.common.dialog.FormDialogTether)4 Activity (org.activityinfo.server.database.hibernate.entity.Activity)4 AddTarget (org.activityinfo.shared.command.AddTarget)4