Search in sources :

Example 91 with DBDAttributeBinding

use of org.jkiss.dbeaver.model.data.DBDAttributeBinding in project dbeaver by dbeaver.

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)

Example 92 with DBDAttributeBinding

use of org.jkiss.dbeaver.model.data.DBDAttributeBinding in project dbeaver by dbeaver.

the class GeometryPresentation method refreshData.

@Override
public void refreshData(boolean refreshMetadata, boolean append, boolean keepState) {
    controller.updateEditControls();
    List<GeometryDataUtils.GeomAttrs> result = GeometryDataUtils.extractGeometryAttributes(getController());
    ResultSetModel model = getController().getModel();
    // Now extract all geom values from data
    List<DBGeometry> geometries = new ArrayList<>();
    for (int i = 0; i < result.size(); i++) {
        GeometryDataUtils.GeomAttrs geomAttrs = result.get(i);
        Color attrColor;
        if (i == 0) {
            attrColor = Display.getCurrent().getSystemColor(SWT.COLOR_BLUE);
        } else {
            attrColor = UIColors.getColor(i);
        }
        RGB rgb = attrColor.getRGB();
        String colorCode = String.format("#%02x%02x%02x", rgb.red, rgb.green, rgb.blue);
        for (ResultSetRow row : model.getAllRows()) {
            Object value = model.getCellValue(geomAttrs.geomAttr, row);
            DBGeometry geometry = GisTransformUtils.getGeometryValueFromObject(controller.getDataContainer(), geomAttrs.geomAttr.getValueHandler(), geomAttrs.geomAttr, value);
            if (geometry != null && !(geometry.getSRID() != 0 && geometry.isEmpty())) {
                geometries.add(geometry);
                // Now get description
                Map<String, Object> properties = new LinkedHashMap<>();
                properties.put("id", DBUtils.getObjectFullName(geomAttrs.geomAttr, DBPEvaluationContext.UI));
                properties.put("color", colorCode);
                if (!geomAttrs.descAttrs.isEmpty()) {
                    Map<String, Object> infoMap = new LinkedHashMap<>();
                    properties.put("info", infoMap);
                    for (DBDAttributeBinding da : geomAttrs.descAttrs) {
                        Object descValue = model.getCellValue(da, row);
                        if (!DBUtils.isNullValue(descValue) && !(descValue instanceof String && ((String) descValue).isEmpty())) {
                            infoMap.put(da.getName(), descValue);
                        }
                    }
                }
                geometry.setProperties(properties);
            }
        }
    }
    try {
        leafletViewer.setGeometryData(geometries.toArray(new DBGeometry[0]));
    } catch (DBException e) {
        DBWorkbench.getPlatformUI().showError("Error rendering GIS data", "Error while rendering geometry data", e);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) GeometryDataUtils(org.jkiss.dbeaver.ui.gis.GeometryDataUtils) Color(org.eclipse.swt.graphics.Color) RGB(org.eclipse.swt.graphics.RGB) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) DBGeometry(org.jkiss.dbeaver.model.gis.DBGeometry)

Example 93 with DBDAttributeBinding

use of org.jkiss.dbeaver.model.data.DBDAttributeBinding in project dbeaver by dbeaver.

the class DataExporterXLSX method printHeader.

private void printHeader(DBCResultSet resultSet, Worksheet wsh) throws DBException {
    boolean hasDescription = false;
    if (showDescription) {
        // Read bindings to extract column descriptions
        boolean bindingsOk = true;
        DBDAttributeBindingMeta[] bindings = new DBDAttributeBindingMeta[columns.length];
        for (int i = 0; i < columns.length; i++) {
            if (columns[i] instanceof DBDAttributeBindingMeta) {
                bindings[i] = (DBDAttributeBindingMeta) columns[i];
            } else {
                bindingsOk = false;
                break;
            }
        }
        if (bindingsOk) {
            DBSEntity sourceEntity = null;
            if (getSite().getSource() instanceof DBSEntity) {
                sourceEntity = (DBSEntity) getSite().getSource();
            }
            DBExecUtils.bindAttributes(resultSet.getSession(), sourceEntity, resultSet, bindings, null);
        }
        for (DBDAttributeBinding column : columns) {
            if (!CommonUtils.isEmpty(column.getDescription())) {
                hasDescription = true;
                break;
            }
        }
    }
    SXSSFSheet sh = (SXSSFSheet) wsh.getSh();
    Row row = sh.createRow(wsh.getCurrentRow());
    int startCol = rowNumber ? 1 : 0;
    sh.trackAllColumnsForAutoSizing();
    for (int i = 0, columnsSize = columns.length; i < columnsSize; i++) {
        DBDAttributeBinding column = columns[i];
        String colName = column.getLabel();
        if (CommonUtils.isEmpty(colName)) {
            colName = column.getName();
        }
        Cell cell = row.createCell(i + startCol, CellType.STRING);
        cell.setCellValue(colName);
        cell.setCellStyle(styleHeader);
    }
    if (hasDescription) {
        wsh.incRow();
        Row descRow = sh.createRow(wsh.getCurrentRow());
        for (int i = 0, columnsSize = columns.length; i < columnsSize; i++) {
            Cell descCell = descRow.createCell(i + startCol, CellType.STRING);
            String description = columns[i].getDescription();
            if (CommonUtils.isEmpty(description)) {
                description = "";
            }
            descCell.setCellValue(description);
            descCell.setCellStyle(styleHeader);
        }
    }
    for (int i = 0, columnsSize = columns.length; i < columnsSize; i++) {
        sh.autoSizeColumn(i);
    }
    wsh.incRow();
    try {
        sh.flushRows();
    } catch (IOException e) {
        throw new DBException("Error processing header", e);
    }
    sh.untrackAllColumnsForAutoSizing();
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBDAttributeBindingMeta(org.jkiss.dbeaver.model.data.DBDAttributeBindingMeta) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) IOException(java.io.IOException) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) SXSSFSheet(org.apache.poi.xssf.streaming.SXSSFSheet)

Example 94 with DBDAttributeBinding

use of org.jkiss.dbeaver.model.data.DBDAttributeBinding in project dbeaver by dbeaver.

the class DataExporterHTML method exportRow.

@Override
public void exportRow(DBCSession session, DBCResultSet resultSet, Object[] row) throws DBException, IOException {
    PrintWriter out = getWriter();
    out.write("<tr" + (rowCount++ % 2 == 0 ? " class=\"odd\"" : "") + ">");
    for (int i = 0; i < row.length; i++) {
        DBDAttributeBinding column = columns[i];
        if (DBUtils.isNullValue(row[i])) {
            writeTextCell(null, false);
        } else if (row[i] instanceof DBDContent) {
            // Content
            // Inline textual content and handle binaries in some special way
            DBDContent content = (DBDContent) row[i];
            try {
                DBDContentStorage cs = content.getContents(session.getProgressMonitor());
                out.write("<td>");
                if (cs != null) {
                    if (ContentUtils.isTextContent(content)) {
                        writeCellValue(cs.getContentReader());
                    } else {
                        getSite().writeBinaryData(cs);
                    }
                }
                out.write("</td>");
            } finally {
                content.release();
            }
        } else {
            String stringValue = super.getValueDisplayString(column, row[i]);
            boolean isImage = row[i] instanceof File && stringValue != null && stringValue.endsWith(".jpg");
            if (isImage) {
                writeImageCell((File) row[i]);
            } else {
                writeTextCell(stringValue, false);
            }
        }
    }
    out.write("</tr>\n");
}
Also used : DBDContent(org.jkiss.dbeaver.model.data.DBDContent) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) File(java.io.File) DBDContentStorage(org.jkiss.dbeaver.model.data.DBDContentStorage) PrintWriter(java.io.PrintWriter)

Example 95 with DBDAttributeBinding

use of org.jkiss.dbeaver.model.data.DBDAttributeBinding in project dbeaver by dbeaver.

the class DataExporterHTML method printHeader.

private void printHeader() {
    PrintWriter out = getWriter();
    out.write("<!DOCTYPE html>\n<html>\n");
    out.write("<head>\n" + "<meta charset=\"" + getSite().getOutputEncoding() + "\"/>" + "<style>\n" + "table {border: medium solid #6495ed;" + "border-collapse: collapse;" + "width: 100%;} " + "th{font-family: monospace;" + "border: thin solid #6495ed;" + // "width: 50%;" +
    "padding: 5px;" + "background-color: #D0E3FA;}" + "td{font-family: sans-serif;" + "border: thin solid #6495ed;" + // "width: 50%;" +
    "padding: 5px;" + "text-align: center;}" + ".odd{background:#e8edff;}" + "img{padding:5px; border:solid; border-color: #dddddd #aaaaaa #aaaaaa #dddddd; border-width: 1px 2px 2px 1px; background-color:white;}" + "</style>\n</head>\n");
    out.write("<body>\n<table>");
    if (outputHeader) {
        out.write("<tr>");
        writeTableTitle(name, columns.length);
        out.write("</tr>");
        out.write("<tr>");
    }
    if (outputColumnHeaders) {
        for (DBDAttributeBinding column : columns) {
            String colName = column.getLabel();
            if (CommonUtils.isEmpty(colName)) {
                colName = column.getName();
            }
            writeTextCell(colName, true);
        }
        out.write("</tr>");
    }
}
Also used : DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) PrintWriter(java.io.PrintWriter)

Aggregations

DBDAttributeBinding (org.jkiss.dbeaver.model.data.DBDAttributeBinding)147 ArrayList (java.util.ArrayList)32 DBException (org.jkiss.dbeaver.DBException)29 ResultSetRow (org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow)24 DBDContent (org.jkiss.dbeaver.model.data.DBDContent)23 DBDContentStorage (org.jkiss.dbeaver.model.data.DBDContentStorage)23 List (java.util.List)18 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)16 DBSAttributeBase (org.jkiss.dbeaver.model.struct.DBSAttributeBase)14 Reader (java.io.Reader)13 PrintWriter (java.io.PrintWriter)12 GridData (org.eclipse.swt.layout.GridData)12 Nullable (org.jkiss.code.Nullable)12 AbstractJob (org.jkiss.dbeaver.model.runtime.AbstractJob)12 Date (java.util.Date)10 SWT (org.eclipse.swt.SWT)10 NotNull (org.jkiss.code.NotNull)10 DBDDataFilter (org.jkiss.dbeaver.model.data.DBDDataFilter)10 DBPPreferenceStore (org.jkiss.dbeaver.model.preferences.DBPPreferenceStore)10 DBSEntityAttribute (org.jkiss.dbeaver.model.struct.DBSEntityAttribute)10