Search in sources :

Example 26 with ActivityDTO

use of org.activityinfo.shared.dto.ActivityDTO 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)

Example 27 with ActivityDTO

use of org.activityinfo.shared.dto.ActivityDTO in project activityinfo by bedatadriven.

the class DesignPresenter method createEntity.

private void createEntity(final ModelData parent, final EntityDTO newEntity) {
    view.showNewForm(newEntity, new FormDialogCallback() {

        @Override
        public void onValidated(final FormDialogTether tether) {
            service.execute(new CreateEntity(newEntity), tether, new AsyncCallback<CreateResult>() {

                @Override
                public void onFailure(Throwable caught) {
                    GWT.log(caught.getMessage());
                }

                @Override
                public void onSuccess(CreateResult result) {
                    // todo add
                    newEntity.set("id", result.getNewId());
                    if (parent == null) {
                        treeStore.add(newEntity, false);
                    } else {
                        treeStore.add(parent, newEntity, false);
                    }
                    if (newEntity instanceof ActivityDTO) {
                        treeStore.add(newEntity, new AttributeGroupFolder(messages.attributes()), false);
                        treeStore.add(newEntity, new IndicatorFolder(messages.indicators()), false);
                    }
                    tether.hide();
                    eventBus.fireEvent(AppEvents.SCHEMA_CHANGED);
                }
            });
        }
    });
}
Also used : CreateEntity(org.activityinfo.shared.command.CreateEntity) FormDialogCallback(org.activityinfo.client.page.common.dialog.FormDialogCallback) CreateResult(org.activityinfo.shared.command.result.CreateResult) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) FormDialogTether(org.activityinfo.client.page.common.dialog.FormDialogTether) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO)

Example 28 with ActivityDTO

use of org.activityinfo.shared.dto.ActivityDTO in project activityinfo by bedatadriven.

the class DesignPresenter method onNew.

public void onNew(String entityName) {
    final EntityDTO newEntity;
    ModelData parent;
    ModelData selected = view.getSelection();
    if ("Activity".equals(entityName)) {
        newEntity = new ActivityDTO(db);
        newEntity.set("databaseId", db.getId());
        parent = null;
    } else if ("AttributeGroup".equals(entityName)) {
        ActivityDTO activity = findActivityFolder(selected);
        newEntity = new AttributeGroupDTO();
        newEntity.set("activityId", activity.getId());
        parent = treeStore.getChild(activity, 0);
    } else if ("Attribute".equals(entityName)) {
        AttributeGroupDTO group = findAttributeGroupNode(selected);
        newEntity = new AttributeDTO();
        newEntity.set("attributeGroupId", group.getId());
        parent = group;
    } else if ("Indicator".equals(entityName)) {
        ActivityDTO activity = findActivityFolder(selected);
        IndicatorDTO newIndicator = new IndicatorDTO();
        newIndicator.setAggregation(IndicatorDTO.AGGREGATE_SUM);
        newEntity = newIndicator;
        newEntity.set("activityId", activity.getId());
        parent = treeStore.getChild(activity, 1);
    } else {
        // TODO log error
        return;
    }
    createEntity(parent, newEntity);
}
Also used : AttributeDTO(org.activityinfo.shared.dto.AttributeDTO) EntityDTO(org.activityinfo.shared.dto.EntityDTO) ModelData(com.extjs.gxt.ui.client.data.ModelData) AttributeGroupDTO(org.activityinfo.shared.dto.AttributeGroupDTO) IndicatorDTO(org.activityinfo.shared.dto.IndicatorDTO) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO)

Example 29 with ActivityDTO

use of org.activityinfo.shared.dto.ActivityDTO in project activityinfo by bedatadriven.

the class DesignView method createGridAndAddToContainer.

@Override
protected Grid<ModelData> createGridAndAddToContainer(Store store) {
    final TreeStore treeStore = (TreeStore) store;
    tree = new EditorTreeGrid<ModelData>(treeStore, createColumnModel());
    tree.setSelectionModel(new ImprovedCellTreeGridSelectionModel<ModelData>());
    tree.setClicksToEdit(EditorGrid.ClicksToEdit.TWO);
    tree.setAutoExpandColumn("name");
    tree.setHideHeaders(true);
    tree.setLoadMask(true);
    // tree.setContextMenu(createContextMenu());
    tree.setIconProvider(new ModelIconProvider<ModelData>() {

        @Override
        public AbstractImagePrototype getIcon(ModelData model) {
            if (model instanceof ActivityDTO) {
                return IconImageBundle.ICONS.activity();
            } else if (model instanceof Folder) {
                return GXT.IMAGES.tree_folder_closed();
            } else if (model instanceof AttributeGroupDTO) {
                return IconImageBundle.ICONS.attributeGroup();
            } else if (model instanceof AttributeDTO) {
                return IconImageBundle.ICONS.attribute();
            } else if (model instanceof IndicatorDTO) {
                return IconImageBundle.ICONS.indicator();
            } else {
                return null;
            }
        }
    });
    tree.addListener(Events.CellClick, new Listener<GridEvent>() {

        @Override
        public void handleEvent(GridEvent ge) {
            showForm(tree.getStore().getAt(ge.getRowIndex()));
        }
    });
    add(tree, new BorderLayoutData(Style.LayoutRegion.CENTER));
    TreeGridDragSource source = new TreeGridDragSource(tree);
    source.addDNDListener(new DNDListener() {

        @Override
        public void dragStart(DNDEvent e) {
            ModelData sel = ((CellTreeGridSelectionModel) tree.getSelectionModel()).getSelectCell().model;
            if (!db.isDesignAllowed() || sel == null || sel instanceof Folder) {
                e.setCancelled(true);
                e.getStatus().setStatus(false);
                return;
            }
            super.dragStart(e);
        }
    });
    TreeGridDropTarget target = new TreeGridDropTarget(tree);
    target.setAllowSelfAsSource(true);
    target.setFeedback(DND.Feedback.BOTH);
    target.setAutoExpand(false);
    target.addDNDListener(new DragDropListener(treeStore));
    return tree;
}
Also used : AbstractImagePrototype(com.google.gwt.user.client.ui.AbstractImagePrototype) TreeGridDragSource(com.extjs.gxt.ui.client.dnd.TreeGridDragSource) ModelData(com.extjs.gxt.ui.client.data.ModelData) AttributeGroupDTO(org.activityinfo.shared.dto.AttributeGroupDTO) GridEvent(com.extjs.gxt.ui.client.event.GridEvent) DNDEvent(com.extjs.gxt.ui.client.event.DNDEvent) BorderLayoutData(com.extjs.gxt.ui.client.widget.layout.BorderLayoutData) DNDListener(com.extjs.gxt.ui.client.event.DNDListener) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO) TreeGridDropTarget(com.extjs.gxt.ui.client.dnd.TreeGridDropTarget) AttributeDTO(org.activityinfo.shared.dto.AttributeDTO) TreeStore(com.extjs.gxt.ui.client.store.TreeStore) IndicatorDTO(org.activityinfo.shared.dto.IndicatorDTO) CellTreeGridSelectionModel(com.extjs.gxt.ui.client.widget.treegrid.CellTreeGridSelectionModel) ImprovedCellTreeGridSelectionModel(org.activityinfo.client.page.common.grid.ImprovedCellTreeGridSelectionModel)

Example 30 with ActivityDTO

use of org.activityinfo.shared.dto.ActivityDTO in project activityinfo by bedatadriven.

the class DesignView method showNewForm.

@Override
public FormDialogTether showNewForm(EntityDTO entity, FormDialogCallback callback) {
    AbstractDesignForm form = createForm(entity);
    form.getBinding().bind(entity);
    for (FieldBinding field : form.getBinding().getBindings()) {
        field.getField().clearInvalid();
    }
    FormDialogImpl dlg = new FormDialogImpl(form);
    dlg.setWidth(form.getPreferredDialogWidth());
    dlg.setHeight(form.getPreferredDialogHeight());
    dlg.setScrollMode(Style.Scroll.AUTOY);
    if (entity instanceof ActivityDTO) {
        dlg.setHeading(I18N.CONSTANTS.newActivity());
    } else if (entity instanceof AttributeGroupDTO) {
        dlg.setHeading(I18N.CONSTANTS.newAttributeGroup());
    } else if (entity instanceof AttributeDTO) {
        dlg.setHeading(I18N.CONSTANTS.newAttribute());
    } else if (entity instanceof IndicatorDTO) {
        dlg.setHeading(I18N.CONSTANTS.newIndicator());
    }
    dlg.show(callback);
    return dlg;
}
Also used : AttributeDTO(org.activityinfo.shared.dto.AttributeDTO) AttributeGroupDTO(org.activityinfo.shared.dto.AttributeGroupDTO) IndicatorDTO(org.activityinfo.shared.dto.IndicatorDTO) FormDialogImpl(org.activityinfo.client.page.common.dialog.FormDialogImpl) FieldBinding(com.extjs.gxt.ui.client.binding.FieldBinding) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO)

Aggregations

ActivityDTO (org.activityinfo.shared.dto.ActivityDTO)44 SchemaDTO (org.activityinfo.shared.dto.SchemaDTO)20 GetSchema (org.activityinfo.shared.command.GetSchema)15 UserDatabaseDTO (org.activityinfo.shared.dto.UserDatabaseDTO)13 Test (org.junit.Test)13 AttributeGroupDTO (org.activityinfo.shared.dto.AttributeGroupDTO)9 IndicatorDTO (org.activityinfo.shared.dto.IndicatorDTO)9 SiteDTO (org.activityinfo.shared.dto.SiteDTO)8 CreateResult (org.activityinfo.shared.command.result.CreateResult)6 ModelData (com.extjs.gxt.ui.client.data.ModelData)5 AttributeDTO (org.activityinfo.shared.dto.AttributeDTO)5 ProjectDTO (org.activityinfo.shared.dto.ProjectDTO)5 TreeStore (com.extjs.gxt.ui.client.store.TreeStore)4 ColumnConfig (com.extjs.gxt.ui.client.widget.grid.ColumnConfig)3 ColumnData (com.extjs.gxt.ui.client.widget.grid.ColumnData)3 HashMap (java.util.HashMap)3 MockEventBus (org.activityinfo.client.MockEventBus)3 DispatcherStub (org.activityinfo.client.dispatch.DispatcherStub)3 UIConstants (org.activityinfo.client.i18n.UIConstants)3 StateManagerStub (org.activityinfo.client.mock.StateManagerStub)3