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