use of org.activityinfo.shared.dto.AttributeGroupDTO in project activityinfo by bedatadriven.
the class ColumnBindingFactory method forActivity.
public static List<ColumnBinding> forActivity(ActivityDTO activity) {
List<ColumnBinding> bindings = Lists.newArrayList();
bindings.add(Ignore.INSTANCE);
bindings.add(new DateBinding());
for (AdminLevelDTO level : activity.getAdminLevels()) {
bindings.add(new AdminBinding(level));
}
if (!activity.getLocationType().isAdminLevel()) {
bindings.add(new LocationNameBinding(activity.getLocationType()));
}
for (IndicatorDTO indicator : activity.getIndicators()) {
bindings.add(new IndicatorBinding(indicator));
}
for (AttributeGroupDTO attributeGroup : activity.getAttributeGroups()) {
bindings.add(new AttributeBinding(attributeGroup));
}
bindings.add(new CommentsBinding());
return bindings;
}
use of org.activityinfo.shared.dto.AttributeGroupDTO in project activityinfo by bedatadriven.
the class DesignView method initNewMenu.
protected void initNewMenu(Menu menu, SelectionListener<MenuEvent> listener) {
MenuItem newActivity = new MenuItem(I18N.CONSTANTS.newActivity(), IconImageBundle.ICONS.activity(), listener);
newActivity.setItemId("Activity");
menu.add(newActivity);
final MenuItem newAttributeGroup = new MenuItem(I18N.CONSTANTS.newAttributeGroup(), IconImageBundle.ICONS.attributeGroup(), listener);
newAttributeGroup.setItemId("AttributeGroup");
menu.add(newAttributeGroup);
final MenuItem newAttribute = new MenuItem(I18N.CONSTANTS.newAttribute(), IconImageBundle.ICONS.attribute(), listener);
newAttribute.setItemId("Attribute");
menu.add(newAttribute);
final MenuItem newIndicator = new MenuItem(I18N.CONSTANTS.newIndicator(), IconImageBundle.ICONS.indicator(), listener);
newIndicator.setItemId("Indicator");
menu.add(newIndicator);
menu.addListener(Events.BeforeShow, new Listener<BaseEvent>() {
@Override
public void handleEvent(BaseEvent be) {
ModelData sel = getSelection();
newAttributeGroup.setEnabled(sel != null);
newAttribute.setEnabled(sel instanceof AttributeGroupDTO || sel instanceof AttributeDTO);
newIndicator.setEnabled(sel != null);
}
});
}
use of org.activityinfo.shared.dto.AttributeGroupDTO in project activityinfo by bedatadriven.
the class SiteExporter method createHeaders.
private void createHeaders(ActivityDTO activity, HSSFSheet sheet) {
// / The HEADER rows
Row headerRow1 = sheet.createRow(0);
Row headerRow2 = sheet.createRow(1);
headerRow2.setHeightInPoints(HEADER_CELL_HEIGHT);
// Create a title cell with the complete database + activity name
Cell titleCell = headerRow1.createCell(0);
titleCell.setCellValue(creationHelper.createRichTextString(activity.getDatabase().getName() + " - " + activity.getName()));
titleCell.setCellStyle(titleStyle);
int column = 0;
createHeaderCell(headerRow2, column++, "Date1", CellStyle.ALIGN_RIGHT);
createHeaderCell(headerRow2, column++, "Date2", CellStyle.ALIGN_RIGHT);
createHeaderCell(headerRow2, column, "Partner");
sheet.setColumnWidth(column, characters(PARTNER_COLUMN_WIDTH));
column++;
createHeaderCell(headerRow2, column, activity.getLocationType().getName());
sheet.setColumnWidth(column, characters(LOCATION_COLUMN_WIDTH));
column++;
createHeaderCell(headerRow2, column++, "Axe");
indicators = new ArrayList<Integer>(activity.getIndicators().size());
if (activity.getReportingFrequency() == ActivityDTO.REPORT_ONCE) {
for (IndicatorGroup group : activity.groupIndicators()) {
if (group.getName() != null) {
// create a merged cell on the top row spanning all members
// of the group
createHeaderCell(headerRow1, column, group.getName());
sheet.addMergedRegion(new CellRangeAddress(0, 0, column, column + group.getIndicators().size() - 1));
}
for (IndicatorDTO indicator : group.getIndicators()) {
indicators.add(indicator.getId());
createHeaderCell(headerRow2, column, indicator.getName(), indicatorHeaderStyle);
sheet.setColumnWidth(column, characters(INDICATOR_COLUMN_WIDTH));
column++;
}
}
}
attributes = new ArrayList<Integer>();
for (AttributeGroupDTO group : activity.getAttributeGroups()) {
if (group.getAttributes().size() != 0) {
createHeaderCell(headerRow1, column, group.getName(), CellStyle.ALIGN_CENTER);
sheet.addMergedRegion(new CellRangeAddress(0, 0, column, column + group.getAttributes().size() - 1));
for (AttributeDTO attrib : group.getAttributes()) {
attributes.add(attrib.getId());
createHeaderCell(headerRow2, column, attrib.getName(), attribHeaderStyle);
sheet.setColumnWidth(column, characters(ATTRIBUTE_COLUMN_WIDTH));
column++;
}
}
}
levels = new ArrayList<Integer>();
for (AdminLevelDTO level : activity.getAdminLevels()) {
createHeaderCell(headerRow2, column++, "Code " + level.getName());
createHeaderCell(headerRow2, column++, level.getName());
levels.add(level.getId());
}
int latColumn = column++;
int lngColumn = column++;
createHeaderCell(headerRow2, latColumn, I18N.CONSTANTS.longitude(), CellStyle.ALIGN_RIGHT);
createHeaderCell(headerRow2, lngColumn, I18N.CONSTANTS.latitude(), CellStyle.ALIGN_RIGHT);
sheet.setColumnWidth(lngColumn, characters(COORD_COLUMN_WIDTH));
sheet.setColumnWidth(latColumn, characters(COORD_COLUMN_WIDTH));
createHeaderCell(headerRow2, column++, I18N.CONSTANTS.comments());
}
use of org.activityinfo.shared.dto.AttributeGroupDTO in project activityinfo by bedatadriven.
the class FormSubmissionResource method createSite.
private void createSite(SiteFormData data, SchemaDTO schemaDTO, ActivityDTO activity) {
final SiteDTO site = new SiteDTO();
site.setId(new KeyGenerator().generateInt());
site.setActivityId(data.getActivity());
if (activity.getReportingFrequency() == ActivityDTO.REPORT_ONCE) {
site.setReportingPeriodId(new KeyGenerator().generateInt());
}
// set activitymodel
if (activity.getReportingFrequency() == ActivityDTO.REPORT_ONCE) {
site.setDate1(data.getDate1());
site.setDate2(data.getDate2());
}
site.setPartner(schemaDTO.getPartnerById(data.getPartner()));
// set comments
site.setComments(data.getComments());
// set attributes
for (FormAttributeGroup formAttributeGroup : data.getAttributegroups()) {
AttributeGroupDTO attributeGroup = activity.getAttributeGroupById(formAttributeGroup.getId());
for (Integer attributeId : attributeGroup.getAttributeIds()) {
site.setAttributeValue(attributeId, formAttributeGroup.isSelected(attributeId));
}
}
// set indicators
if (activity.getReportingFrequency() == ActivityDTO.REPORT_ONCE) {
for (FormIndicator formIndicator : data.getIndicators()) {
site.setIndicatorValue(formIndicator.getId(), formIndicator.getDoubleValue());
}
}
// create command(s)
CreateSite cmd = new CreateSite(site);
cmd.setNestedCommand(createCreateLocationCommand(data, schemaDTO, activity));
// save
CreateResult createResult = dispatcher.execute(cmd);
// create sitehistory entry
siteHistoryProcessor.process(cmd, getUser().getId(), createResult.getNewId());
}
use of org.activityinfo.shared.dto.AttributeGroupDTO in project activityinfo by bedatadriven.
the class GetAttributeGroupsDimensionHandler method execute.
@Override
public void execute(GetAttributeGroupsDimension cmd, final ExecutionContext context, final AsyncCallback<AttributeGroupResult> callback) {
// if the filter doesn't contain any activity, database or indicator values, just return an empty list
if (!cmd.getFilter().isRestricted(DimensionType.Database) && !cmd.getFilter().isRestricted(DimensionType.Activity) && !cmd.getFilter().isRestricted(DimensionType.Indicator)) {
callback.onSuccess(new AttributeGroupResult());
return;
}
final Dimension dimension = new Dimension(DimensionType.AttributeGroup);
final PivotSites query = new PivotSites();
query.setFilter(cmd.getFilter());
query.setDimensions(dimension);
query.setValueType(ValueType.DIMENSION);
context.execute(query, new AsyncCallback<PivotSites.PivotResult>() {
@Override
public void onSuccess(PivotSites.PivotResult result) {
final List<AttributeGroupDTO> list = new ArrayList<AttributeGroupDTO>();
// populate the resultlist
for (Bucket bucket : result.getBuckets()) {
EntityCategory category = (EntityCategory) bucket.getCategory(dimension);
if (category != null) {
AttributeGroupDTO attributeGroup = new AttributeGroupDTO();
attributeGroup.setId(category.getId());
attributeGroup.setName(category.getLabel());
list.add(attributeGroup);
}
}
// sort the groups in the list by name (fallback on id)
Collections.sort(list, new Comparator<AttributeGroupDTO>() {
@Override
public int compare(AttributeGroupDTO g1, AttributeGroupDTO g2) {
int result = g1.getName().compareToIgnoreCase(g2.getName());
if (result != 0) {
return result;
} else {
return ((Integer) g1.getId()).compareTo(g2.getId());
}
}
});
callback.onSuccess(new AttributeGroupResult(list));
}
@Override
public void onFailure(Throwable caught) {
callback.onFailure(caught);
}
});
}
Aggregations