Search in sources :

Example 1 with IDataController

use of org.jkiss.dbeaver.ui.data.IDataController in project dbeaver by serge-rider.

the class GISBrowserViewer method primeEditorValue.

@Override
public void primeEditorValue(@Nullable Object value) throws DBException {
    List<DBGeometry> geometries = new ArrayList<>();
    IDataController dataController = valueController.getDataController();
    if (dataController instanceof IResultSetController) {
        IResultSetController resultSetController = (IResultSetController) dataController;
        DBSTypedObject valueType = valueController.getValueType();
        List<GeometryDataUtils.GeomAttrs> geomAttrs = null;
        if (valueType instanceof DBSAttributeBase) {
            geomAttrs = GeometryDataUtils.extractGeometryAttributes(resultSetController);
        }
        IResultSetSelection selection = resultSetController.getSelection();
        Object[] selectedValues = selection.toArray();
        if (ArrayUtils.isEmpty(selectedValues)) {
            selectedValues = new Object[] { value };
        }
        for (Object cell : selectedValues) {
            DBGeometry geometry;
            DBDAttributeBinding attr;
            ResultSetRow row;
            if (cell instanceof DBGeometry) {
                attr = resultSetController.getActivePresentation().getCurrentAttribute();
                row = resultSetController.getCurrentRow();
                geometry = (DBGeometry) cell;
            } else {
                attr = selection.getElementAttribute(cell);
                row = selection.getElementRow(cell);
                Object cellValue = resultSetController.getModel().getCellValue(attr, row);
                geometry = GisTransformUtils.getGeometryValueFromObject(valueController.getDataController().getDataContainer(), valueController.getValueHandler(), valueController.getValueType(), cellValue);
            }
            if (geometry != null) {
                geometries.add(geometry);
                // Set properties
                if (valueType instanceof DBSAttributeBase) {
                    for (GeometryDataUtils.GeomAttrs ga : geomAttrs) {
                        if (ga.geomAttr.matches(attr, false)) {
                            GeometryDataUtils.setGeometryProperties(resultSetController, ga, geometry, row);
                            break;
                        }
                    }
                }
                if (geometry.getProperties() == null) {
                    geometry.setProperties(Collections.singletonMap("Object", geometry.getSRID()));
                }
            }
        }
    }
    leafletViewer.setGeometryData(geometries.toArray(new DBGeometry[0]));
}
Also used : GeometryDataUtils(org.jkiss.dbeaver.ui.gis.GeometryDataUtils) ArrayList(java.util.ArrayList) DBSAttributeBase(org.jkiss.dbeaver.model.struct.DBSAttributeBase) IResultSetSelection(org.jkiss.dbeaver.ui.controls.resultset.IResultSetSelection) ResultSetRow(org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow) IResultSetController(org.jkiss.dbeaver.ui.controls.resultset.IResultSetController) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) DBSTypedObject(org.jkiss.dbeaver.model.struct.DBSTypedObject) IDataController(org.jkiss.dbeaver.ui.data.IDataController) DBGeometry(org.jkiss.dbeaver.model.gis.DBGeometry) DBSTypedObject(org.jkiss.dbeaver.model.struct.DBSTypedObject)

Aggregations

ArrayList (java.util.ArrayList)1 DBDAttributeBinding (org.jkiss.dbeaver.model.data.DBDAttributeBinding)1 DBGeometry (org.jkiss.dbeaver.model.gis.DBGeometry)1 DBSAttributeBase (org.jkiss.dbeaver.model.struct.DBSAttributeBase)1 DBSTypedObject (org.jkiss.dbeaver.model.struct.DBSTypedObject)1 IResultSetController (org.jkiss.dbeaver.ui.controls.resultset.IResultSetController)1 IResultSetSelection (org.jkiss.dbeaver.ui.controls.resultset.IResultSetSelection)1 ResultSetRow (org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow)1 IDataController (org.jkiss.dbeaver.ui.data.IDataController)1 GeometryDataUtils (org.jkiss.dbeaver.ui.gis.GeometryDataUtils)1