use of com.revolsys.io.BaseCloseable in project com.revolsys.open by revolsys.
the class FieldFilterPanel method setFilter.
public void setFilter(final Condition filter) {
if (!this.fieldNames.isEmpty()) {
Invoke.later(() -> {
try (BaseCloseable settingFilter = this.settingFilter.closeable(true)) {
setSearchFilter(filter);
boolean simple = false;
if (Property.isEmpty(filter)) {
final Field searchField = (Field) this.searchField;
if (searchField != null) {
searchField.setFieldValue(null);
}
setSearchOperator("=");
simple = true;
} else if (filter instanceof Not) {
final Not not = (Not) filter;
final QueryValue condition = not.getValue();
if (condition instanceof IsNull) {
final IsNull isNull = (IsNull) condition;
final IsNotNull isNotNull = new IsNotNull(isNull.getValue());
setFilter(isNotNull);
return;
}
} else if (filter instanceof ILike) {
final ILike equal = (ILike) filter;
final QueryValue leftCondition = equal.getLeft();
final QueryValue rightCondition = equal.getRight();
if (leftCondition instanceof Column && rightCondition instanceof Value) {
final Column column = (Column) leftCondition;
final String searchFieldName = column.getName();
setSearchFieldName(searchFieldName);
if (setSearchOperator("Like")) {
final Value value = (Value) rightCondition;
final Object searchValue = value.getValue();
String searchText = DataTypes.toString(searchValue);
if (Property.hasValue(searchText)) {
setSearchField(this.searchTextField);
searchText = searchText.replaceAll("%", "");
final String previousSearchText = this.searchTextField.getText();
if (!DataType.equal(searchText, previousSearchText)) {
this.searchTextField.setFieldValue(searchText);
}
simple = true;
} else {
setSearchFilter(null);
}
}
}
} else if (filter instanceof BinaryCondition) {
final BinaryCondition condition = (BinaryCondition) filter;
final QueryValue leftCondition = condition.getLeft();
final QueryValue rightCondition = condition.getRight();
if (leftCondition instanceof Column && rightCondition instanceof Value) {
final Column column = (Column) leftCondition;
final String searchFieldName = column.getName();
setSearchFieldName(searchFieldName);
final String searchOperator = condition.getOperator();
if (setSearchOperator(searchOperator)) {
final Value value = (Value) rightCondition;
final Object searchValue = value.getValue();
final String searchText = DataTypes.toString(searchValue);
final Field searchField = (Field) this.searchField;
final Object oldValue = searchField.getFieldValue();
if (!searchText.equalsIgnoreCase(DataTypes.toString(oldValue))) {
searchField.setFieldValue(searchText);
}
simple = true;
}
}
} else if (filter instanceof RightUnaryCondition) {
final RightUnaryCondition condition = (RightUnaryCondition) filter;
final String operator = condition.getOperator();
if (filter instanceof IsNull || filter instanceof IsNotNull) {
final QueryValue leftValue = condition.getValue();
if (leftValue instanceof Column) {
final Column column = (Column) leftValue;
final String searchFieldName = column.getName();
setSearchFieldName(searchFieldName);
if (setSearchOperator(operator)) {
simple = true;
}
}
}
}
if (simple) {
this.whereLabel.setVisible(false);
if (this.nameField != null) {
this.nameField.setVisible(true);
}
if (this.operatorField != null) {
this.operatorField.setVisible(true);
}
this.searchFieldPanel.setVisible(true);
} else {
String filterText = filter.toString();
if (filterText.length() > 40) {
filterText = filterText.substring(0, 40) + "...";
}
this.whereLabel.setText(filterText);
this.whereLabel.setToolTipText(filterText);
this.whereLabel.setVisible(true);
if (this.nameField != null) {
this.nameField.setVisible(false);
}
this.operatorField.setVisible(false);
this.searchFieldPanel.setVisible(false);
}
}
});
}
}
use of com.revolsys.io.BaseCloseable in project com.revolsys.open by revolsys.
the class GridLayerRenderer method render.
@Override
public void render(final Viewport2D viewport, final Cancellable cancellable, final GridLayer layer) {
try {
final double scaleForVisible = viewport.getScaleForVisible();
if (layer.isVisible(scaleForVisible)) {
final BoundingBox boundingBox = viewport.getBoundingBox();
final RectangularMapGrid grid = layer.getGrid();
final List<RectangularMapTile> tiles = grid.getTiles(boundingBox);
final Graphics2D graphics = viewport.getGraphics();
if (graphics != null) {
final Font font = graphics.getFont();
for (final RectangularMapTile tile : cancellable.cancellable(tiles)) {
final BoundingBox tileBoundingBox = tile.getBoundingBox();
final BoundingBox intersectBoundingBox = boundingBox.intersection(tileBoundingBox);
if (!intersectBoundingBox.isEmpty()) {
final GeometryFactory geometryFactory = viewport.getGeometryFactory();
final Polygon polygon = tile.getPolygon(geometryFactory, 50);
try (BaseCloseable transformCloseable = viewport.setUseModelCoordinates(graphics, true)) {
viewport.drawGeometryOutline(polygon, this.geometryStyle);
}
try (BaseCloseable transformClosable = viewport.setUseModelCoordinates(false)) {
viewport.drawText(tile, polygon, this.textStyle);
}
}
graphics.setFont(font);
}
}
}
} catch (final IllegalArgumentException e) {
}
}
use of com.revolsys.io.BaseCloseable in project com.revolsys.open by revolsys.
the class PointCloudLayerRenderer method render.
@Override
public void render(final Viewport2D viewport, final Cancellable cancellable, final PointCloudLayer layer) {
// TODO cancellable
final double scaleForVisible = viewport.getScaleForVisible();
if (layer.isVisible(scaleForVisible)) {
if (!layer.isEditable()) {
final PointCloud<?> pointCloud = layer.getPointCloud();
if (pointCloud != null) {
final BoundingBox boundingBox = layer.getBoundingBox();
final Graphics2D graphics = viewport.getGraphics();
if (graphics != null) {
try (BaseCloseable transformCloseable = viewport.setUseModelCoordinates(true)) {
final Polygon polygon = boundingBox.toPolygon(0);
viewport.drawGeometryOutline(polygon, STYLE_BOUNDING_BOX);
}
}
}
}
}
}
use of com.revolsys.io.BaseCloseable in project com.revolsys.open by revolsys.
the class FileRecordLayer method revertDo.
protected boolean revertDo() {
if (this.resource == null) {
return false;
} else {
if (this.resource.exists()) {
try (final RecordReader reader = RecordReader.newRecordReader(this.resource)) {
if (reader == null) {
Logs.error(this, "Cannot find reader for: " + this.resource);
return false;
} else {
final Map<String, Object> properties = getProperties();
reader.setProperties(properties);
final RecordDefinition recordDefinition = reader.getRecordDefinition();
setRecordDefinition(recordDefinition);
if (recordDefinition == null) {
Logs.error(this, "No record definition found for: " + this.url);
return false;
} else {
GeometryFactory geometryFactory = recordDefinition.getGeometryFactory();
clearRecords();
try (BaseCloseable eventsDisabled = eventsDisabled()) {
for (final Record record : reader) {
final Geometry geometry = record.getGeometry();
if (geometry != null) {
if (geometryFactory == null || !geometryFactory.isHasCoordinateSystem()) {
final GeometryFactory geometryFactory2 = geometry.getGeometryFactory();
if (geometryFactory2.isHasCoordinateSystem()) {
setGeometryFactory(geometryFactory2);
geometryFactory = geometryFactory2;
recordDefinition.setGeometryFactory(geometryFactory2);
}
}
}
newRecordInternal(record);
}
}
}
refreshBoundingBox();
initRecordMenu();
setExists(true);
return true;
}
} catch (final RuntimeException e) {
Logs.error(this, "Error reading: " + this.resource, e);
} finally {
refresh();
}
} else {
Logs.error(this, "Cannot find: " + this.url);
}
}
return false;
}
use of com.revolsys.io.BaseCloseable in project com.revolsys.open by revolsys.
the class AbstractOverlay method drawXorGeometry.
protected void drawXorGeometry(final Graphics2D graphics) {
Geometry geometry = this.xorGeometry;
if (geometry != null) {
geometry = geometry.newGeometry(getViewport().getGeometryFactory2dFloating());
final Paint paint = graphics.getPaint();
try {
graphics.setXORMode(Color.WHITE);
if (geometry instanceof Point) {
final Point point = (Point) geometry;
final Point2D screenPoint = this.viewport.toViewPoint(point);
final double x = screenPoint.getX() - getHotspotPixels();
final double y = screenPoint.getY() - getHotspotPixels();
final int diameter = 2 * getHotspotPixels();
final Shape shape = new Ellipse2D.Double(x, y, diameter, diameter);
graphics.setPaint(new Color(0, 0, 255));
graphics.fill(shape);
} else {
XOR_LINE_STYLE.setLineCap(LineCap.BUTT);
try (BaseCloseable transformCloseable = this.viewport.setUseModelCoordinates(graphics, true)) {
GeometryStyleRenderer.renderGeometry(this.viewport, graphics, geometry, XOR_LINE_STYLE);
}
}
} finally {
graphics.setPaint(paint);
}
}
}
Aggregations