use of org.activityinfo.legacy.shared.model.PartnerDTO in project activityinfo by bedatadriven.
the class DbPartnerEditor method showAddDialog.
private void showAddDialog() {
PartnerDTO newPartner = new PartnerDTO();
showEditDialog(newPartner);
}
use of org.activityinfo.legacy.shared.model.PartnerDTO in project activityinfo by bedatadriven.
the class DbTargetEditor method onEdit.
@Override
protected void onEdit(final TargetDTO dto) {
this.view.showAddDialog(dto, db, true, 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) {
Log.error("Failed to edit target. " + caught.getMessage(), caught);
}
@Override
public void onSuccess(VoidResult result) {
if (record.get("partnerId") != null) {
PartnerDTO partner = db.getPartnerById((Integer) record.get("partnerId"));
dto.setPartner(partner);
} else {
dto.setPartner(null);
}
if (record.get("projectId") != null) {
ProjectDTO project = db.getProjectById((Integer) record.get("projectId"));
dto.setProject(project);
} else {
dto.setProject(null);
}
store.commitChanges();
eventBus.fireEvent(AppEvents.SCHEMA_CHANGED);
dlg.hide();
}
});
}
});
}
use of org.activityinfo.legacy.shared.model.PartnerDTO in project activityinfo by bedatadriven.
the class DbTargetEditor method onAdd.
@Override
protected void onAdd() {
final TargetDTO newTarget = new TargetDTO();
this.view.showAddDialog(newTarget, db, false, 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());
if (newTarget.get("partnerId") != null) {
PartnerDTO partner = db.getPartnerById((Integer) newTarget.get("partnerId"));
newTarget.setPartner(partner);
}
if (newTarget.get("projectId") != null) {
ProjectDTO project = db.getProjectById((Integer) newTarget.get("projectId"));
newTarget.setProject(project);
}
store.add(newTarget);
store.commitChanges();
eventBus.fireEvent(AppEvents.SCHEMA_CHANGED);
dlg.hide();
}
});
}
});
}
use of org.activityinfo.legacy.shared.model.PartnerDTO in project activityinfo by bedatadriven.
the class DbTargetGrid method createColumnModel.
protected ColumnModel createColumnModel() {
List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
ColumnConfig projectColumn = new ColumnConfig("projectId", messages.project(), 150);
projectColumn.setRenderer(new GridCellRenderer() {
@Override
public SafeHtml render(ModelData modelData, String s, ColumnData columnData, int i, int i1, ListStore listStore, Grid grid) {
SafeHtmlBuilder sb = new SafeHtmlBuilder();
Integer id = modelData.get(s);
if (id != null) {
ProjectDTO project = db.getProjectById(id);
if (project != null) {
sb.appendEscaped(project.getName());
}
}
return sb.toSafeHtml();
}
});
ColumnConfig partnerColumn = new ColumnConfig("partnerId", messages.partner(), 150);
partnerColumn.setRenderer(new GridCellRenderer() {
@Override
public SafeHtml render(ModelData modelData, String s, ColumnData columnData, int i, int i1, ListStore listStore, Grid grid) {
SafeHtmlBuilder sb = new SafeHtmlBuilder();
Integer id = modelData.get(s);
if (id != null) {
PartnerDTO partner = db.getPartnerById(id);
if (partner != null) {
sb.appendEscaped(partner.getName());
}
}
return sb.toSafeHtml();
}
});
columns.add(new ColumnConfig("name", messages.name(), 150));
columns.add(projectColumn);
columns.add(partnerColumn);
columns.add(new TimePeriodColumn("timePeriod", messages.timePeriod(), 300));
return new ColumnModel(columns);
}
use of org.activityinfo.legacy.shared.model.PartnerDTO in project activityinfo by bedatadriven.
the class GetPartnersDimensionHandler method execute.
@Override
public void execute(GetPartnersDimension cmd, ExecutionContext context, final AsyncCallback<PartnerResult> callback) {
final Dimension dimension = new Dimension(DimensionType.Partner);
PivotSites query = new PivotSites();
query.setFilter(cmd.getFilter());
query.setDimensions(dimension);
query.setValueType(ValueType.TOTAL_SITES);
if (query.isTooBroad()) {
callback.onSuccess(new PartnerResult());
return;
}
context.execute(query, new AsyncCallback<PivotSites.PivotResult>() {
@Override
public void onSuccess(PivotSites.PivotResult result) {
Set<PartnerDTO> partners = new HashSet<PartnerDTO>();
for (Bucket bucket : result.getBuckets()) {
EntityCategory category = (EntityCategory) bucket.getCategory(dimension);
if (category == null) {
Log.debug("Partner is null: " + bucket.toString());
} else {
PartnerDTO partner = new PartnerDTO();
partner.setId(category.getId());
partner.setName(category.getLabel());
partners.add(partner);
}
}
// sort partners by name (fallback on id)
List<PartnerDTO> list = new ArrayList<PartnerDTO>(partners);
Collections.sort(list, new Comparator<PartnerDTO>() {
@Override
public int compare(PartnerDTO p1, PartnerDTO p2) {
int result = p1.getName().compareToIgnoreCase(p2.getName());
if (result != 0) {
return result;
} else {
return ((Integer) p1.getId()).compareTo(p2.getId());
}
}
});
callback.onSuccess(new PartnerResult(list));
}
@Override
public void onFailure(Throwable caught) {
callback.onFailure(caught);
}
});
}
Aggregations