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();
}
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();
}
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);
}
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;
}
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;
}
Aggregations