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);
}
});
}
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));
}
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();
}
}
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();
}
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'> </div>";
} else {
return "<div class='unmapped'> </div>";
}
}
return " ";
}
});
columns.add(mapColumn);
return this;
}
Aggregations