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