use of org.activityinfo.shared.dto.AttributeDTO 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.AttributeDTO in project activityinfo by bedatadriven.
the class ItemDetail method create.
static ItemDetail create(RenderContext ctx, Map.Entry<String, Object> entry) {
ItemDetail d = new ItemDetail();
Map<String, Object> state = ctx.getState();
SchemaDTO schema = ctx.getSchema();
String key = entry.getKey();
final Object oldValue = state.get(key);
final Object newValue = entry.getValue();
state.put(key, newValue);
final StringBuilder sb = new StringBuilder();
// basic
if (key.equals("date1")) {
addValues(sb, I18N.CONSTANTS.startDate(), oldValue, newValue);
} else if (key.equals("date2")) {
addValues(sb, I18N.CONSTANTS.endDate(), oldValue, newValue);
} else if (key.equals("comments")) {
addValues(sb, I18N.CONSTANTS.comments(), oldValue, newValue);
} else if (key.equals("locationId")) {
// schema loookups
String oldName = null;
if (oldValue != null) {
oldName = ctx.getLocation(toInt(oldValue)).getName();
}
String newName = ctx.getLocation(toInt(newValue)).getName();
addValues(sb, I18N.CONSTANTS.location(), oldName, newName);
} else if (key.equals("projectId")) {
String oldName = null;
if (oldValue != null) {
oldName = schema.getProjectById(toInt(oldValue)).getName();
}
String newName = schema.getProjectById(toInt(newValue)).getName();
addValues(sb, I18N.CONSTANTS.project(), oldName, newName);
} else if (key.equals("partnerId")) {
String oldName = null;
if (oldValue != null) {
oldName = schema.getPartnerById(toInt(oldValue)).getName();
}
String newName = schema.getPartnerById(toInt(newValue)).getName();
addValues(sb, I18N.CONSTANTS.partner(), oldName, newName);
} else if (key.startsWith(IndicatorDTO.PROPERTY_PREFIX)) {
// custom
int id = IndicatorDTO.indicatorIdForPropertyName(key);
IndicatorDTO dto = schema.getIndicatorById(id);
String name = dto.getName();
Month m = IndicatorDTO.monthForPropertyName(key);
if (m != null) {
name = I18N.MESSAGES.siteHistoryIndicatorName(name, m.toLocalDate().atMidnightInMyTimezone());
}
addValues(sb, name, oldValue, newValue, dto.getUnits());
} else if (key.startsWith(AttributeDTO.PROPERTY_PREFIX)) {
int id = AttributeDTO.idForPropertyName(key);
AttributeDTO dto = schema.getAttributeById(id);
if (Boolean.parseBoolean(newValue.toString())) {
sb.append(I18N.MESSAGES.siteHistoryAttrAdd(dto.getName()));
} else {
sb.append(I18N.MESSAGES.siteHistoryAttrRemove(dto.getName()));
}
} else {
// fallback
addValues(sb, key, oldValue, newValue);
}
d.stringValue = sb.toString();
return d;
}
use of org.activityinfo.shared.dto.AttributeDTO 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.AttributeDTO in project activityinfo by bedatadriven.
the class AttributeGroupFilterDialog method show.
public void show(Filter baseFilter, final Filter currentFilter, SelectionCallback<Set<Integer>> callback) {
this.callback = callback;
show();
Set<Integer> ids = currentFilter.getRestrictions(DimensionType.Attribute);
store.removeAll();
store.add(group.getAttributes());
for (AttributeDTO attr : store.getModels()) {
if (ids.contains(attr.getId())) {
listView.setChecked(attr, true);
}
}
}
use of org.activityinfo.shared.dto.AttributeDTO in project activityinfo by bedatadriven.
the class DesignPresenter method fillStore.
private void fillStore(UIConstants messages) {
for (ActivityDTO activity : db.getActivities()) {
ActivityDTO activityNode = new ActivityDTO(activity);
treeStore.add(activityNode, false);
AttributeGroupFolder attributeFolder = new AttributeGroupFolder(messages.attributes());
treeStore.add(activityNode, attributeFolder, false);
for (AttributeGroupDTO group : activity.getAttributeGroups()) {
if (group != null) {
AttributeGroupDTO groupNode = new AttributeGroupDTO(group);
treeStore.add(attributeFolder, groupNode, false);
for (AttributeDTO attribute : group.getAttributes()) {
AttributeDTO attributeNode = new AttributeDTO(attribute);
treeStore.add(groupNode, attributeNode, false);
}
}
}
IndicatorFolder indicatorFolder = new IndicatorFolder(messages.indicators());
treeStore.add(activityNode, indicatorFolder, false);
for (IndicatorDTO indicator : activity.getIndicators()) {
IndicatorDTO indicatorNode = new IndicatorDTO(indicator);
treeStore.add(indicatorFolder, indicatorNode, false);
}
}
}
Aggregations