Search in sources :

Example 1 with ModelData

use of com.extjs.gxt.ui.client.data.ModelData in project activityinfo by bedatadriven.

the class BaseMapDialog method loadBaseMaps.

private void loadBaseMaps() {
    listView.getStore().removeAll();
    listView.getStore().add(googleThumb(GoogleBaseMap.ROADMAP, I18N.CONSTANTS.googleRoadmap()));
    listView.getStore().add(googleThumb(GoogleBaseMap.SATELLITE, I18N.CONSTANTS.googleSatelliteMap()));
    listView.getStore().add(googleThumb(GoogleBaseMap.HYBRID, I18N.CONSTANTS.googleHybrid()));
    listView.getStore().add(googleThumb(GoogleBaseMap.TERRAIN, I18N.CONSTANTS.googleTerrainMap()));
    updateSelection();
    service.execute(new GetBaseMaps(), new MaskingAsyncMonitor(listView, I18N.CONSTANTS.loading()), new AsyncCallback<BaseMapResult>() {

        @Override
        public void onFailure(Throwable caught) {
            failLoadingBaseMaps();
        }

        @Override
        public void onSuccess(BaseMapResult result) {
            List<ModelData> thumbnails = new ArrayList<ModelData>();
            for (BaseMap baseMap : result.getBaseMaps()) {
                thumbnails.add(tileThumb(baseMap));
            }
            listView.getStore().add(thumbnails);
            updateSelection();
        }
    });
}
Also used : ModelData(com.extjs.gxt.ui.client.data.ModelData) BaseModelData(com.extjs.gxt.ui.client.data.BaseModelData) MaskingAsyncMonitor(org.activityinfo.ui.client.dispatch.monitor.MaskingAsyncMonitor) BaseMapResult(org.activityinfo.legacy.shared.command.result.BaseMapResult) GetBaseMaps(org.activityinfo.legacy.shared.command.GetBaseMaps) ArrayList(java.util.ArrayList) List(java.util.List) BaseMap(org.activityinfo.legacy.shared.model.BaseMap) TileBaseMap(org.activityinfo.legacy.shared.model.TileBaseMap) GoogleBaseMap(org.activityinfo.legacy.shared.reports.content.GoogleBaseMap)

Example 2 with ModelData

use of com.extjs.gxt.ui.client.data.ModelData 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);
}
Also used : ProjectDTO(org.activityinfo.legacy.shared.model.ProjectDTO) ModelData(com.extjs.gxt.ui.client.data.ModelData) PartnerDTO(org.activityinfo.legacy.shared.model.PartnerDTO) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) ArrayList(java.util.ArrayList) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) ListStore(com.extjs.gxt.ui.client.store.ListStore) TimePeriodColumn(org.activityinfo.ui.client.page.common.columns.TimePeriodColumn)

Example 3 with ModelData

use of com.extjs.gxt.ui.client.data.ModelData in project activityinfo by bedatadriven.

the class TargetIndicatorView method createGridAndAddToContainer.

@Override
protected Grid<ModelData> createGridAndAddToContainer(Store store) {
    final TreeStore treeStore = (TreeStore) store;
    tree = new EditorTreeGrid<ModelData>(treeStore, createColumnModel());
    tree.setAutoExpandColumn("name");
    tree.setSelectionModel(new ImprovedCellTreeGridSelectionModel<ModelData>());
    tree.setClicksToEdit(EditorGrid.ClicksToEdit.ONE);
    tree.setLoadMask(true);
    tree.setStateId("TargetValueGrid" + db.getId());
    tree.setStateful(true);
    tree.setIconProvider(new ModelIconProvider<ModelData>() {

        @Override
        public AbstractImagePrototype getIcon(ModelData model) {
            if (model instanceof IsActivityDTO) {
                return IconImageBundle.ICONS.activity();
            } else if (model instanceof TargetValueDTO) {
                return IconImageBundle.ICONS.indicator();
            } else if (model instanceof Link) {
                return IconImageBundle.ICONS.folder();
            } else {
                return null;
            }
        }
    });
    addBeforeEditListener();
    addAfterEditListener();
    add(tree, new BorderLayoutData(Style.LayoutRegion.CENTER));
    return tree;
}
Also used : AbstractImagePrototype(com.google.gwt.user.client.ui.AbstractImagePrototype) ModelData(com.extjs.gxt.ui.client.data.ModelData) TreeStore(com.extjs.gxt.ui.client.store.TreeStore) BorderLayoutData(com.extjs.gxt.ui.client.widget.layout.BorderLayoutData) Link(org.activityinfo.ui.client.page.common.nav.Link)

Example 4 with ModelData

use of com.extjs.gxt.ui.client.data.ModelData in project activityinfo by bedatadriven.

the class DbEditor method promptDeleteSelection.

private void promptDeleteSelection() {
    ModelData selected = tree.getSelectionModel().getSelectedItem();
    if (!(selected instanceof EntityDTO)) {
        return;
    }
    EntityDTO selectedEntity = (EntityDTO) selected;
    if (selectedEntity instanceof FolderDTO && treeStore.getChildCount(selectedEntity) != 0) {
        MessageBox.alert(I18N.CONSTANTS.delete(), I18N.CONSTANTS.folderNotEmpty(), null);
        return;
    }
    SafeHtml message = confirmationMessage(selectedEntity);
    if (message == null) {
        deleteEntity(selectedEntity);
    } else {
        MessageBox.confirm(SafeHtmlUtils.fromString(I18N.CONSTANTS.confirmDeletion()), message, event -> {
            if (event.getButtonClicked().getItemId().equals(Dialog.YES)) {
                deleteEntity(selectedEntity);
            }
        });
    }
}
Also used : ModelData(com.extjs.gxt.ui.client.data.ModelData) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml)

Example 5 with ModelData

use of com.extjs.gxt.ui.client.data.ModelData in project activityinfo by bedatadriven.

the class DbEditor method onNew.

private void onNew(String entityName) {
    final EntityDTO newEntity;
    ModelData parent;
    ModelData selected = tree.getSelectionModel().getSelectedItem();
    if (ActivityDTO.ENTITY_NAME.equals(entityName)) {
        newEntity = new ActivityDTO();
        newEntity.set(DATABASE_ID_PROPERTY, db.getId());
        newEntity.set(CLASSIC_VIEW_PROPERTY, true);
        newEntity.set(PUBLISHED_PROPERTY, Published.NOT_PUBLISHED);
        parent = null;
    } else if ("Form".equals(entityName)) {
        newEntity = new ActivityDTO();
        newEntity.set(DATABASE_ID_PROPERTY, db.getId());
        newEntity.set(CLASSIC_VIEW_PROPERTY, false);
        newEntity.set(REPORTING_FREQUENCY_PROPERTY, ActivityFormDTO.REPORT_ONCE);
        newEntity.set(LOCATION_TYPE_ID_PROPERTY, db.getCountry().getNullLocationType().getId());
        newEntity.set(PUBLISHED_PROPERTY, Published.NOT_PUBLISHED);
        parent = null;
    } else if (FolderDTO.ENTITY_NAME.equals(entityName)) {
        newEntity = new FolderDTO(db.getId(), null);
        parent = null;
    } else if (LocationTypeDTO.ENTITY_NAME.equals(entityName)) {
        newEntity = new LocationTypeDTO();
        newEntity.set(DATABASE_ID_PROPERTY, db.getId());
        parent = null;
    } else if (AttributeGroupDTO.ENTITY_NAME.equals(entityName)) {
        IsActivityDTO activity = findActivityFolder(selected);
        AttributeGroupDTO newAttributeGroup = new AttributeGroupDTO();
        newAttributeGroup.setMultipleAllowed(false);
        newEntity = newAttributeGroup;
        newEntity.set("activityId", activity.getId());
        parent = treeStore.getChild((ModelData) activity, 0);
    } else if (AttributeDTO.ENTITY_NAME.equals(entityName)) {
        AttributeGroupDTO group = findAttributeGroupNode(selected);
        newEntity = new AttributeDTO();
        newEntity.set("attributeGroupId", group.getId());
        parent = group;
    } else if (IndicatorDTO.ENTITY_NAME.equals(entityName)) {
        IsActivityDTO activity = findActivityFolder(selected);
        IndicatorDTO newIndicator = new IndicatorDTO();
        newIndicator.setAggregation(IndicatorDTO.AGGREGATE_SUM);
        newIndicator.setType(FieldTypeClass.QUANTITY);
        if (activity instanceof ActivityFormDTO) {
            newIndicator.set(SORT_ORDER_PROPERTY, ((ActivityFormDTO) activity).getIndicators().size() + 1);
        }
        newEntity = newIndicator;
        newEntity.set("activityId", activity.getId());
        parent = treeStore.getChild((ModelData) activity, 1);
    } else {
        Log.error("Unsupported entity type.");
        return;
    }
    createEntity(parent, newEntity);
}
Also used : ModelData(com.extjs.gxt.ui.client.data.ModelData) ActivityDTO(org.activityinfo.legacy.shared.model.ActivityDTO)

Aggregations

ModelData (com.extjs.gxt.ui.client.data.ModelData)10 ActivityDTO (org.activityinfo.legacy.shared.model.ActivityDTO)3 BaseModelData (com.extjs.gxt.ui.client.data.BaseModelData)2 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)2 ArrayList (java.util.ArrayList)2 GridEvent (com.extjs.gxt.ui.client.event.GridEvent)1 ListStore (com.extjs.gxt.ui.client.store.ListStore)1 Record (com.extjs.gxt.ui.client.store.Record)1 TreeStore (com.extjs.gxt.ui.client.store.TreeStore)1 BorderLayoutData (com.extjs.gxt.ui.client.widget.layout.BorderLayoutData)1 TreePanel (com.extjs.gxt.ui.client.widget.treepanel.TreePanel)1 SafeHtmlBuilder (com.google.gwt.safehtml.shared.SafeHtmlBuilder)1 AbstractImagePrototype (com.google.gwt.user.client.ui.AbstractImagePrototype)1 List (java.util.List)1 GetBaseMaps (org.activityinfo.legacy.shared.command.GetBaseMaps)1 BaseMapResult (org.activityinfo.legacy.shared.command.result.BaseMapResult)1 BaseMap (org.activityinfo.legacy.shared.model.BaseMap)1 FolderDTO (org.activityinfo.legacy.shared.model.FolderDTO)1 PartnerDTO (org.activityinfo.legacy.shared.model.PartnerDTO)1 ProjectDTO (org.activityinfo.legacy.shared.model.ProjectDTO)1