Search in sources :

Example 6 with AdminEntity

use of org.activityinfo.geoadmin.model.AdminEntity in project activityinfo by bedatadriven.

the class LocationImportWindow method doMatch.

private void doMatch() {
    LocationAdminMatcher matcher = new LocationAdminMatcher(client, levels);
    for (AdminLevel level : levels) {
        matcher.setLevelAttribute(level, importForm.getLevelAttributeIndex(level));
    }
    for (LocationFeature location : locations) {
        location.getEntities().clear();
        for (AdminEntity entity : matcher.forFeature(location.getFeature())) {
            location.getEntities().put(entity.getLevelId(), entity);
        }
    }
    tableModel.fireTableDataChanged();
}
Also used : AdminEntity(org.activityinfo.geoadmin.model.AdminEntity) AdminLevel(org.activityinfo.geoadmin.model.AdminLevel)

Example 7 with AdminEntity

use of org.activityinfo.geoadmin.model.AdminEntity in project activityinfo by bedatadriven.

the class LocationImportWindow method createTableModel.

private GenericTableModel<LocationFeature> createTableModel() {
    Builder<LocationFeature> model = GenericTableModel.newModel(locations);
    for (final AdminLevel level : levels) {
        model.addColumn(level.getName(), String.class, new Function<LocationFeature, String>() {

            @Override
            public String apply(LocationFeature location) {
                AdminEntity entity = location.getEntities().get(level.getId());
                if (entity == null) {
                    return null;
                }
                return entity.getName();
            }
        });
    }
    for (int i = 0; i != source.getAttributeCount(); ++i) {
        final int attributeindex = i;
        model.addColumn(source.getAttributes().get(i).getName().getLocalPart(), Object.class, new Function<LocationFeature, Object>() {

            @Override
            public Object apply(LocationFeature location) {
                return location.getFeature().getAttributeValue(attributeindex);
            }
        });
    }
    return model.build();
}
Also used : AdminEntity(org.activityinfo.geoadmin.model.AdminEntity) AdminLevel(org.activityinfo.geoadmin.model.AdminLevel) Point(com.vividsolutions.jts.geom.Point)

Example 8 with AdminEntity

use of org.activityinfo.geoadmin.model.AdminEntity in project activityinfo by bedatadriven.

the class LocationImportWindow method doImport.

private void doImport() {
    int nameIndex = importForm.getNameAttributeIndex();
    List<NewLocation> newLocations = Lists.newArrayList();
    for (LocationFeature location : locations) {
        Point point = location.getPoint();
        NewLocation newLocation = new NewLocation();
        newLocation.setName(truncate(location.getFeature().getAttributeStringValue(nameIndex)));
        newLocation.setLongitude(point.getX());
        newLocation.setLatitude(point.getY());
        for (AdminEntity entity : location.getEntities().values()) {
            newLocation.getAdminEntityIds().add(entity.getId());
        }
        newLocations.add(newLocation);
    }
    client.postNewLocations(locationTypeId, newLocations);
    setVisible(false);
}
Also used : AdminEntity(org.activityinfo.geoadmin.model.AdminEntity) NewLocation(org.activityinfo.geoadmin.model.NewLocation) Point(com.vividsolutions.jts.geom.Point) Point(com.vividsolutions.jts.geom.Point)

Example 9 with AdminEntity

use of org.activityinfo.geoadmin.model.AdminEntity in project activityinfo by bedatadriven.

the class ColumnGuesser method forEntities.

public ColumnGuesser forEntities(List<AdminEntity> entities) {
    final Set<String> expected = Sets.newHashSet();
    for (AdminEntity entity : entities) {
        expected.add(PlaceNames.cleanName(entity.getName()));
    }
    this.predicate = Predicates.and(predicate, new Predicate<Object>() {

        @Override
        public boolean apply(Object value) {
            if (value == null) {
                return false;
            } else {
                String stringValue = PlaceNames.cleanName(value.toString());
                return expected.contains(stringValue);
            }
        }
    });
    return this;
}
Also used : AdminEntity(org.activityinfo.geoadmin.model.AdminEntity) Predicate(com.google.common.base.Predicate)

Example 10 with AdminEntity

use of org.activityinfo.geoadmin.model.AdminEntity in project activityinfo by bedatadriven.

the class ImportTableCellRenderer method getTableCellRendererComponent.

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    final Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    if (!isSelected) {
        int featureIndex = table.convertRowIndexToModel(row);
        if (tableModel.getParent(row) != null) {
            AdminEntity parent = tableModel.getParent(featureIndex);
            ImportFeature feature = tableModel.getFeatureAt(featureIndex);
            switch(scorer.quality(feature, parent)) {
                case OK:
                    c.setBackground(FOREST_GREEN);
                    break;
                case WARNING:
                    c.setBackground(PINK);
                    break;
                case SEVERE:
                    c.setBackground(FIREBRICK3);
                    c.setForeground(Color.WHITE);
                    break;
            }
        }
    }
    return c;
}
Also used : AdminEntity(org.activityinfo.geoadmin.model.AdminEntity) Component(java.awt.Component)

Aggregations

AdminEntity (org.activityinfo.geoadmin.model.AdminEntity)14 AdminLevel (org.activityinfo.geoadmin.model.AdminLevel)5 Point (com.vividsolutions.jts.geom.Point)3 Predicate (com.google.common.base.Predicate)1 Envelope (com.vividsolutions.jts.geom.Envelope)1 Component (java.awt.Component)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 Date (java.util.Date)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 ColumnGuesser (org.activityinfo.geoadmin.ColumnGuesser)1 AdminLevelNode (org.activityinfo.geoadmin.model.AdminLevelNode)1 NewLocation (org.activityinfo.geoadmin.model.NewLocation)1 Extents (org.activityinfo.model.type.geo.Extents)1