Search in sources :

Example 1 with LocationDTO

use of org.activityinfo.legacy.shared.model.LocationDTO in project activityinfo by bedatadriven.

the class LocationFilterPanel method createList.

private void createList() {
    ListLoader filterLoader = new BaseListLoader(new LocationProxy());
    ListStore<LocationDTO> filterComboboxStore = new ListStore<>(filterLoader);
    filterCombobox = new ComboBox<>();
    filterCombobox.setEmptyText(I18N.CONSTANTS.searchForLocationToAdd());
    filterCombobox.setDisplayField("name");
    filterCombobox.setStore(filterComboboxStore);
    filterCombobox.setUseQueryCache(false);
    filterCombobox.setTypeAhead(true);
    filterCombobox.setTypeAheadDelay(120);
    filterCombobox.setQueryDelay(100);
    filterCombobox.addSelectionChangedListener(new SelectionChangedListener<LocationDTO>() {

        @Override
        public void selectionChanged(SelectionChangedEvent<LocationDTO> se) {
            if (se.getSelectedItem() != null && !store.contains(se.getSelectedItem())) {
                store.add(se.getSelectedItem());
                filterToolBar.setApplyFilterEnabled(true);
                // reset typed filter
                filterCombobox.setRawValue("");
            }
        }
    });
    listView = new ListView<>();
    listView.setStore(store);
    listView.setDisplayProperty("name");
    listView.setSelectionModel(listSelectionModel);
    add(filterCombobox, new RowData(1, -1));
    add(listView, new RowData(1, 1));
}
Also used : ListStore(com.extjs.gxt.ui.client.store.ListStore) RowData(com.extjs.gxt.ui.client.widget.layout.RowData) LocationDTO(org.activityinfo.legacy.shared.model.LocationDTO)

Example 2 with LocationDTO

use of org.activityinfo.legacy.shared.model.LocationDTO in project activityinfo by bedatadriven.

the class LocationForm method saveNewLocation.

private void saveNewLocation() {
    if (coordinateFields.validate() && nameField.validate() && axeField.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);
    }
}
Also used : AdminLevelDTO(org.activityinfo.legacy.shared.model.AdminLevelDTO) KeyGenerator(org.activityinfo.model.legacy.KeyGenerator) LocationDTO(org.activityinfo.legacy.shared.model.LocationDTO)

Example 3 with LocationDTO

use of org.activityinfo.legacy.shared.model.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 (searchPresenter.get !empty) {
// updateMap(bounds);
// }
}
Also used : AiLatLng(org.activityinfo.model.type.geo.AiLatLng) Marker(org.discotools.gwt.leaflet.client.marker.Marker) LocationDTO(org.activityinfo.legacy.shared.model.LocationDTO)

Example 4 with LocationDTO

use of org.activityinfo.legacy.shared.model.LocationDTO in project activityinfo by bedatadriven.

the class LocationSearchPresenter method numberLocations.

private void numberLocations(List<LocationDTO> locations) {
    int number = 0;
    for (LocationDTO location : locations) {
        if (location.hasCoordinates()) {
            location.setMarker(String.valueOf((char) ('A' + number)));
            number++;
        }
        if (number >= 26) {
            break;
        }
    }
}
Also used : LocationDTO(org.activityinfo.legacy.shared.model.LocationDTO)

Example 5 with LocationDTO

use of org.activityinfo.legacy.shared.model.LocationDTO in project activityinfo by bedatadriven.

the class SearchLocationsHandler method retrieveLocations.

private void retrieveLocations(final SearchLocations command, final ExecutionContext context, final AsyncCallback<LocationResult> callback, final int limit, final int totalCount) {
    SqlQuery query = baseQuery(command).appendColumns("LocationId", "Name", "Axe", "X", "Y", "LocationTypeId").setLimitClause(dialect.limitClause(0, limit));
    query.execute(context.getTransaction(), new SqlResultCallback() {

        @Override
        public void onSuccess(SqlTransaction tx, SqlResultSet results) {
            // Create a list of locations from query result
            List<LocationDTO> locations = Lists.newArrayList();
            Map<Integer, LocationDTO> locationsById = Maps.newHashMap();
            for (SqlResultSetRow row : results.getRows()) {
                LocationDTO location = LocationDTO.fromSqlRow(row);
                locations.add(location);
                locationsById.put(location.getId(), location);
            }
            LocationResult result = new LocationResult(locations);
            result.setOffset(0);
            result.setTotalLength(totalCount > results.getRows().size() ? totalCount : results.getRows().size());
            callback.onSuccess(result);
        }
    });
}
Also used : SqlResultSet(com.bedatadriven.rebar.sql.client.SqlResultSet) SqlQuery(com.bedatadriven.rebar.sql.client.query.SqlQuery) SqlResultCallback(com.bedatadriven.rebar.sql.client.SqlResultCallback) SqlTransaction(com.bedatadriven.rebar.sql.client.SqlTransaction) List(java.util.List) SqlResultSetRow(com.bedatadriven.rebar.sql.client.SqlResultSetRow) Map(java.util.Map) LocationDTO(org.activityinfo.legacy.shared.model.LocationDTO) LocationResult(org.activityinfo.legacy.shared.command.result.LocationResult)

Aggregations

LocationDTO (org.activityinfo.legacy.shared.model.LocationDTO)14 LocationResult (org.activityinfo.legacy.shared.command.result.LocationResult)6 Test (org.junit.Test)5 GetLocations (org.activityinfo.legacy.shared.command.GetLocations)4 SqlResultCallback (com.bedatadriven.rebar.sql.client.SqlResultCallback)2 SqlResultSet (com.bedatadriven.rebar.sql.client.SqlResultSet)2 SqlResultSetRow (com.bedatadriven.rebar.sql.client.SqlResultSetRow)2 SqlTransaction (com.bedatadriven.rebar.sql.client.SqlTransaction)2 SqlQuery (com.bedatadriven.rebar.sql.client.query.SqlQuery)2 AdminEntityDTO (org.activityinfo.legacy.shared.model.AdminEntityDTO)2 FormInstance (org.activityinfo.model.form.FormInstance)2 ButtonEvent (com.extjs.gxt.ui.client.event.ButtonEvent)1 ListStore (com.extjs.gxt.ui.client.store.ListStore)1 RowData (com.extjs.gxt.ui.client.widget.layout.RowData)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)1