use of org.activityinfo.shared.dto.LocationDTO 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.LocationDTO in project activityinfo by bedatadriven.
the class BoundLocationSection method newLocation.
private void newLocation() {
location = new LocationDTO(location);
location.setId(new KeyGenerator().generateInt());
location.setName(leafComboBox.getValue().getName());
for (AdminLevelDTO level : adminFieldSet.getAdminLevels()) {
location.setAdminEntity(level.getId(), adminFieldSet.getAdminEntity(level));
}
}
use of org.activityinfo.shared.dto.LocationDTO in project activityinfo by bedatadriven.
the class SiteDialogLauncher method addNewSiteWithBoundLocation.
private void addNewSiteWithBoundLocation(ActivityDTO activity, SiteDialogCallback callback) {
SiteDTO newSite = new SiteDTO();
newSite.setActivityId(activity.getId());
LocationDTO location = new LocationDTO();
location.setId(new KeyGenerator().generateInt());
location.setLocationTypeId(activity.getLocationTypeId());
SiteDialog dialog = new SiteDialog(dispatcher, activity);
dialog.showNew(newSite, location, true, callback);
}
use of org.activityinfo.shared.dto.LocationDTO in project activityinfo by bedatadriven.
the class LocationMap method updateSearchMarkers.
private void updateSearchMarkers() {
markerLayer.clearLayers();
List<LocationDTO> locations = Lists.reverse(searchPresenter.getStore().getModels());
LatLngBounds bounds = new LatLngBounds();
boolean empty = true;
for (LocationDTO location : locations) {
if (location.hasCoordinates()) {
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
Marker marker = createMarker(latLng, location.getMarker());
markerLayer.addLayer(marker);
bounds.extend(latLng);
bindClickEvent(location, marker);
empty = false;
}
}
if (empty) {
if (searchPresenter.getBounds() != null) {
bounds = LeafletUtil.newLatLngBounds(searchPresenter.getBounds());
} else {
bounds = LeafletUtil.newLatLngBounds(searchPresenter.getCountry().getBounds());
}
}
int effectiveZoom = Math.min(8, map.getBoundsZoom(bounds, false));
map.setView(bounds.getCenter(), effectiveZoom, false);
map.fitBounds(bounds);
}
use of org.activityinfo.shared.dto.LocationDTO in project activityinfo by bedatadriven.
the class LocationForm method saveNewLocation.
private void saveNewLocation() {
if (coordinateFields.validate() && nameField.validate()) {
LocationDTO newLocation = new LocationDTO();
newLocation.setId(new KeyGenerator().generateInt());
newLocation.setLocationTypeId(locationType.getId());
newLocation.setName(nameField.getValue());
newLocation.setAxe(axeField.getValue());
newLocation.setLatitude(coordinateFields.getLatitudeField().getValue());
newLocation.setLongitude(coordinateFields.getLongitudeField().getValue());
for (AdminLevelDTO level : adminPresenter.getAdminLevels()) {
newLocation.setAdminEntity(level.getId(), adminPresenter.getAdminEntity(level));
}
newLocationPresenter.accept(newLocation);
}
}
Aggregations