Search in sources :

Example 1 with SiteDTO

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

the class ImporterWizard method submitSites.

private void submitSites(List<LocationDTO> results, final AsyncCallback<Void> callback) {
    int numColums = model.getData().getNumColumns();
    ColumnBinding[] bindings = bindingsArray();
    KeyGenerator keyGenerator = new KeyGenerator();
    // do a first pass to match the location
    List<Command> siteBatch = Lists.newArrayList();
    int rowIndex = 0;
    for (ImportRowModel row : model.getData().getRowStore().getModels()) {
        LocationDTO location = results.get(rowIndex);
        if (location.isNew()) {
            siteBatch.add(new CreateLocation(location));
        }
        SiteDTO site = new SiteDTO();
        site.setId(keyGenerator.generateInt());
        site.setReportingPeriodId(keyGenerator.generateInt());
        site.setActivityId(model.getActivity().getId());
        site.setLocationId(location.getId());
        site.setPartner(model.getActivity().getDatabase().getPartners().get(0));
        for (int i = 0; i != numColums; ++i) {
            bindings[i].bindSite(row.get(i), site);
        }
        siteBatch.add(new CreateSite(site));
        rowIndex++;
    }
    dispatcher.execute(new BatchCommand(siteBatch), new AsyncCallback<BatchResult>() {

        @Override
        public void onFailure(Throwable caught) {
            MessageBox.alert("Import failed", "Exception: " + caught.getMessage(), null);
            callback.onFailure(null);
        }

        @Override
        public void onSuccess(BatchResult result) {
            MessageBox.alert("Import succeeded!", "Refresh the data grid to see your new sites", null);
            callback.onSuccess(null);
        }
    });
}
Also used : CreateLocation(org.activityinfo.shared.command.CreateLocation) ColumnBinding(org.activityinfo.client.importer.column.ColumnBinding) BatchResult(org.activityinfo.shared.command.result.BatchResult) CreateSite(org.activityinfo.shared.command.CreateSite) Command(org.activityinfo.shared.command.Command) BatchCommand(org.activityinfo.shared.command.BatchCommand) BatchCommand(org.activityinfo.shared.command.BatchCommand) SiteDTO(org.activityinfo.shared.dto.SiteDTO) KeyGenerator(org.activityinfo.client.local.command.handler.KeyGenerator) LocationDTO(org.activityinfo.shared.dto.LocationDTO)

Example 2 with SiteDTO

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

the class DataEntryPage method addCenter.

private void addCenter() {
    gridPanel = new SiteGridPanel(dispatcher, new DefaultColumnModelProvider(dispatcher));
    gridPanel.setTopComponent(createToolBar());
    LayoutContainer center = new LayoutContainer();
    center.setLayout(new BorderLayout());
    center.add(gridPanel, new BorderLayoutData(LayoutRegion.CENTER));
    gridPanel.addSelectionChangedListener(new SelectionChangedListener<SiteDTO>() {

        @Override
        public void selectionChanged(SelectionChangedEvent<SiteDTO> se) {
            onSiteSelected(se);
        }
    });
    detailTab = new DetailTab(dispatcher);
    monthlyPanel = new MonthlyReportsPanel(dispatcher);
    monthlyTab = new TabItem(I18N.CONSTANTS.monthlyReports());
    monthlyTab.setLayout(new FitLayout());
    monthlyTab.add(monthlyPanel);
    attachmentsTab = new AttachmentsTab(dispatcher, eventBus);
    siteHistoryTab = new SiteHistoryTab(dispatcher);
    tabPanel = new CollapsibleTabPanel();
    tabPanel.add(detailTab);
    tabPanel.add(monthlyTab);
    tabPanel.add(attachmentsTab);
    tabPanel.add(siteHistoryTab);
    tabPanel.setSelection(detailTab);
    center.add(tabPanel, tabPanel.getBorderLayoutData());
    add(center, new BorderLayoutData(LayoutRegion.CENTER));
}
Also used : BorderLayoutData(com.extjs.gxt.ui.client.widget.layout.BorderLayoutData) DefaultColumnModelProvider(org.activityinfo.client.page.entry.column.DefaultColumnModelProvider) TabItem(com.extjs.gxt.ui.client.widget.TabItem) SiteHistoryTab(org.activityinfo.client.page.entry.sitehistory.SiteHistoryTab) BorderLayout(com.extjs.gxt.ui.client.widget.layout.BorderLayout) LayoutContainer(com.extjs.gxt.ui.client.widget.LayoutContainer) SiteDTO(org.activityinfo.shared.dto.SiteDTO) CollapsibleTabPanel(org.activityinfo.client.widget.CollapsibleTabPanel) FitLayout(com.extjs.gxt.ui.client.widget.layout.FitLayout)

Example 3 with SiteDTO

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

the class DataEntryPage method onUIAction.

@Override
public void onUIAction(String actionId) {
    if (UIActions.ADD.equals(actionId)) {
        SiteDialogLauncher formHelper = new SiteDialogLauncher(dispatcher);
        formHelper.addSite(currentPlace.getFilter(), new SiteDialogCallback() {

            @Override
            public void onSaved(SiteDTO site) {
                gridPanel.refresh();
            }
        });
    } else if (UIActions.EDIT.equals(actionId)) {
        SiteDialogLauncher launcher = new SiteDialogLauncher(dispatcher);
        launcher.editSite(gridPanel.getSelection(), new SiteDialogCallback() {

            @Override
            public void onSaved(SiteDTO site) {
                gridPanel.refresh();
            }
        });
    } else if (UIActions.DELETE.equals(actionId)) {
        delete();
    } else if (UIActions.PRINT.equals(actionId)) {
        int activityId = currentPlace.getFilter().getRestrictedCategory(DimensionType.Activity);
        PrintDataEntryForm form = new PrintDataEntryForm(dispatcher);
        form.print(activityId);
    } else if (UIActions.EXPORT.equals(actionId)) {
        Window.Location.assign(GWT.getModuleBaseURL() + "export?filter=" + FilterUrlSerializer.toUrlFragment(currentPlace.getFilter()));
    } else if ("EMBED".equals(actionId)) {
        EmbedDialog dialog = new EmbedDialog(dispatcher);
        dialog.show(currentPlace);
    } else if ("IMPORT".equals(actionId)) {
        doImport();
    }
}
Also used : SiteDialogLauncher(org.activityinfo.client.page.entry.form.SiteDialogLauncher) SiteDTO(org.activityinfo.shared.dto.SiteDTO) PrintDataEntryForm(org.activityinfo.client.page.entry.form.PrintDataEntryForm) SiteDialogCallback(org.activityinfo.client.page.entry.form.SiteDialogCallback)

Example 4 with SiteDTO

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

the class FlatSiteGridPanel method initGrid.

public void initGrid(Filter filter, ColumnModel columnModel) {
    PagingLoader<PagingLoadResult<SiteDTO>> loader = new BasePagingLoader<PagingLoadResult<SiteDTO>>(new SiteProxy());
    loader.addLoadListener(new LoadListener() {

        @Override
        public void loaderLoadException(LoadEvent le) {
            Log.debug("Exception thrown during load of FlatSiteGrid: ", le.exception);
        }
    });
    loader.setRemoteSort(true);
    loader.setSortField("date2");
    loader.setSortDir(SortDir.DESC);
    pagingToolBar.bind(loader);
    listStore = new ListStore<SiteDTO>(loader);
    if (editorGrid == null) {
        editorGrid = new EditorGrid<SiteDTO>(listStore, columnModel);
        editorGrid.setLoadMask(true);
        // editorGrid.setStateful(true);
        editorGrid.setClicksToEdit(ClicksToEdit.TWO);
        editorGrid.setStripeRows(true);
        GridSelectionModel<SiteDTO> sm = new GridSelectionModel<SiteDTO>();
        sm.setSelectionMode(SelectionMode.SINGLE);
        sm.addSelectionChangedListener(new SelectionChangedListener<SiteDTO>() {

            @Override
            public void selectionChanged(SelectionChangedEvent<SiteDTO> se) {
                fireEvent(Events.SelectionChange, se);
            }
        });
        editorGrid.setSelectionModel(sm);
        new QuickTip(editorGrid);
        add(editorGrid, new BorderLayoutData(Style.LayoutRegion.CENTER));
        layout();
    } else {
        editorGrid.reconfigure(listStore, columnModel);
    }
    this.currentFilter = filter;
    loader.load();
}
Also used : LoadEvent(com.extjs.gxt.ui.client.data.LoadEvent) QuickTip(com.extjs.gxt.ui.client.widget.tips.QuickTip) BorderLayoutData(com.extjs.gxt.ui.client.widget.layout.BorderLayoutData) BasePagingLoader(com.extjs.gxt.ui.client.data.BasePagingLoader) GridSelectionModel(com.extjs.gxt.ui.client.widget.grid.GridSelectionModel) LoadListener(com.extjs.gxt.ui.client.event.LoadListener) PagingLoadResult(com.extjs.gxt.ui.client.data.PagingLoadResult) SiteDTO(org.activityinfo.shared.dto.SiteDTO)

Example 5 with SiteDTO

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

the class ColumnModelBuilder method addMapColumn.

public ColumnModelBuilder addMapColumn() {
    ColumnConfig mapColumn = new ColumnConfig("x", "", 25);
    mapColumn.setRenderer(new GridCellRenderer<ModelData>() {

        @Override
        public Object render(ModelData model, String property, ColumnData config, int rowIndex, int colIndex, ListStore listStore, Grid grid) {
            if (model instanceof SiteDTO) {
                SiteDTO siteModel = (SiteDTO) model;
                if (siteModel.hasCoords()) {
                    return "<div class='mapped'>&nbsp;&nbsp;</div>";
                } else {
                    return "<div class='unmapped'>&nbsp;&nbsp;</div>";
                }
            }
            return " ";
        }
    });
    columns.add(mapColumn);
    return this;
}
Also used : ListStore(com.extjs.gxt.ui.client.store.ListStore) ModelData(com.extjs.gxt.ui.client.data.ModelData) ColumnConfig(com.extjs.gxt.ui.client.widget.grid.ColumnConfig) Grid(com.extjs.gxt.ui.client.widget.grid.Grid) ColumnData(com.extjs.gxt.ui.client.widget.grid.ColumnData) SiteDTO(org.activityinfo.shared.dto.SiteDTO)

Aggregations

SiteDTO (org.activityinfo.shared.dto.SiteDTO)71 Test (org.junit.Test)32 GetSites (org.activityinfo.shared.command.GetSites)16 SiteResult (org.activityinfo.shared.command.result.SiteResult)11 CreateSite (org.activityinfo.shared.command.CreateSite)9 ActivityDTO (org.activityinfo.shared.dto.ActivityDTO)8 SortInfo (com.extjs.gxt.ui.client.data.SortInfo)7 ArrayList (java.util.ArrayList)7 CreateResult (org.activityinfo.shared.command.result.CreateResult)7 Date (java.util.Date)6 OnDataSet (org.activityinfo.server.database.OnDataSet)6 PartnerDTO (org.activityinfo.shared.dto.PartnerDTO)6 AiLatLng (org.activityinfo.shared.report.content.AiLatLng)6 ColumnConfig (com.extjs.gxt.ui.client.widget.grid.ColumnConfig)5 ColumnData (com.extjs.gxt.ui.client.widget.grid.ColumnData)5 KeyGenerator (org.activityinfo.client.local.command.handler.KeyGenerator)5 UpdateSite (org.activityinfo.shared.command.UpdateSite)5 LocationDTO (org.activityinfo.shared.dto.LocationDTO)5 PointValue (org.activityinfo.shared.report.model.PointValue)5 SqlResultCallback (com.bedatadriven.rebar.sql.client.SqlResultCallback)4