Search in sources :

Example 1 with AttributeDTO

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);
        }
    });
}
Also used : AttributeDTO(org.activityinfo.shared.dto.AttributeDTO) ModelData(com.extjs.gxt.ui.client.data.ModelData) AttributeGroupDTO(org.activityinfo.shared.dto.AttributeGroupDTO) BaseEvent(com.extjs.gxt.ui.client.event.BaseEvent) SeparatorMenuItem(com.extjs.gxt.ui.client.widget.menu.SeparatorMenuItem) MenuItem(com.extjs.gxt.ui.client.widget.menu.MenuItem)

Example 2 with AttributeDTO

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;
}
Also used : AttributeDTO(org.activityinfo.shared.dto.AttributeDTO) Month(org.activityinfo.shared.command.Month) IndicatorDTO(org.activityinfo.shared.dto.IndicatorDTO) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO)

Example 3 with AttributeDTO

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());
}
Also used : AttributeDTO(org.activityinfo.shared.dto.AttributeDTO) IndicatorDTO(org.activityinfo.shared.dto.IndicatorDTO) AttributeGroupDTO(org.activityinfo.shared.dto.AttributeGroupDTO) IndicatorGroup(org.activityinfo.shared.dto.IndicatorGroup) AdminLevelDTO(org.activityinfo.shared.dto.AdminLevelDTO) Row(org.apache.poi.ss.usermodel.Row) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) Cell(org.apache.poi.ss.usermodel.Cell)

Example 4 with AttributeDTO

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);
        }
    }
}
Also used : AttributeDTO(org.activityinfo.shared.dto.AttributeDTO)

Example 5 with AttributeDTO

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);
        }
    }
}
Also used : AttributeDTO(org.activityinfo.shared.dto.AttributeDTO) AttributeGroupDTO(org.activityinfo.shared.dto.AttributeGroupDTO) IndicatorDTO(org.activityinfo.shared.dto.IndicatorDTO) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO)

Aggregations

AttributeDTO (org.activityinfo.shared.dto.AttributeDTO)10 AttributeGroupDTO (org.activityinfo.shared.dto.AttributeGroupDTO)6 IndicatorDTO (org.activityinfo.shared.dto.IndicatorDTO)6 ActivityDTO (org.activityinfo.shared.dto.ActivityDTO)5 ModelData (com.extjs.gxt.ui.client.data.ModelData)3 SchemaDTO (org.activityinfo.shared.dto.SchemaDTO)2 FieldBinding (com.extjs.gxt.ui.client.binding.FieldBinding)1 TreeGridDragSource (com.extjs.gxt.ui.client.dnd.TreeGridDragSource)1 TreeGridDropTarget (com.extjs.gxt.ui.client.dnd.TreeGridDropTarget)1 BaseEvent (com.extjs.gxt.ui.client.event.BaseEvent)1 DNDEvent (com.extjs.gxt.ui.client.event.DNDEvent)1 DNDListener (com.extjs.gxt.ui.client.event.DNDListener)1 GridEvent (com.extjs.gxt.ui.client.event.GridEvent)1 TreeStore (com.extjs.gxt.ui.client.store.TreeStore)1 BorderLayoutData (com.extjs.gxt.ui.client.widget.layout.BorderLayoutData)1 MenuItem (com.extjs.gxt.ui.client.widget.menu.MenuItem)1 SeparatorMenuItem (com.extjs.gxt.ui.client.widget.menu.SeparatorMenuItem)1 CellTreeGridSelectionModel (com.extjs.gxt.ui.client.widget.treegrid.CellTreeGridSelectionModel)1 AbstractImagePrototype (com.google.gwt.user.client.ui.AbstractImagePrototype)1 FormDialogImpl (org.activityinfo.client.page.common.dialog.FormDialogImpl)1