use of org.jkiss.dbeaver.model.data.DBDAttributeBinding in project dbeaver by serge-rider.
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 serge-rider.
the class SQLSemanticProcessor method isValidTableColumn.
private static boolean isValidTableColumn(DBRProgressMonitor monitor, DBPDataSource dataSource, Table table, DBDAttributeConstraint co) throws DBException {
DBSAttributeBase attribute = co.getAttribute();
if (attribute instanceof DBDAttributeBinding) {
attribute = ((DBDAttributeBinding) attribute).getMetaAttribute();
}
if (table != null && attribute instanceof DBCAttributeMetaData) {
DBSEntityAttribute entityAttribute = null;
DBCEntityMetaData entityMetaData = ((DBCAttributeMetaData) attribute).getEntityMetaData();
if (entityMetaData != null) {
DBSEntity entity = DBUtils.getEntityFromMetaData(monitor, DBUtils.getDefaultContext(dataSource, true), entityMetaData);
if (entity != null) {
entityAttribute = entity.getAttribute(monitor, co.getAttributeName());
}
}
// No such attribute in entity. Do not use table prefix (#6927)
return entityAttribute != null;
}
return true;
}
use of org.jkiss.dbeaver.model.data.DBDAttributeBinding in project dbeaver by serge-rider.
the class SQLSemanticProcessor method getConstraintTable.
/**
* Extract alias (or source table name) for specified constraint from SQL select.
* Searches in FROM and JOIN
*/
@Nullable
public static Table getConstraintTable(PlainSelect select, DBDAttributeConstraint constraint) {
String constrTable;
DBSAttributeBase ca = constraint.getAttribute();
if (ca instanceof DBDAttributeBinding) {
constrTable = ((DBDAttributeBinding) ca).getMetaAttribute().getEntityName();
} else if (ca instanceof DBSEntityAttribute) {
constrTable = ((DBSEntityAttribute) ca).getParentObject().getName();
} else {
return null;
}
if (constrTable == null) {
return null;
}
FromItem fromItem = select.getFromItem();
Table table = findTableInFrom(fromItem, constrTable);
if (table == null) {
// Maybe it is a join
if (!CommonUtils.isEmpty(select.getJoins())) {
for (Join join : select.getJoins()) {
table = findTableInFrom(join.getRightItem(), constrTable);
if (table != null) {
break;
}
}
}
}
return table;
}
use of org.jkiss.dbeaver.model.data.DBDAttributeBinding in project dbeaver by serge-rider.
the class ContentPanelEditor method makeValueId.
private String makeValueId() {
String valueId;
DBSTypedObject valueType = valueController.getValueType();
if (valueType instanceof DBDAttributeBinding) {
valueType = ((DBDAttributeBinding) valueType).getAttribute();
}
if (valueType instanceof DBSObject) {
DBSObject object = (DBSObject) valueType;
valueId = DBUtils.getObjectFullName(object, DBPEvaluationContext.DDL);
if (object.getParentObject() != null) {
valueId = DBUtils.getObjectFullName(object.getParentObject(), DBPEvaluationContext.DDL) + ":" + valueId;
}
} else {
valueId = valueController.getValueName();
}
String dsId = "unknown";
if (valueController.getExecutionContext() != null) {
dsId = valueController.getExecutionContext().getDataSource().getContainer().getId();
}
return dsId + ":" + valueId;
}
use of org.jkiss.dbeaver.model.data.DBDAttributeBinding in project dbeaver by serge-rider.
the class SQLGeneratorContributor method makeResultSetContributions.
private void makeResultSetContributions(List<IContributionItem> menu, IResultSetSelection rss) {
final IResultSetController rsv = rss.getController();
DBSDataContainer dataContainer = rsv.getDataContainer();
final List<DBDAttributeBinding> visibleAttributes = rsv.getModel().getVisibleAttributes();
final DBSEntity entity = rsv.getModel().getSingleSource();
if (dataContainer != null && !visibleAttributes.isEmpty() && entity != null) {
final List<ResultSetRow> selectedRows = new ArrayList<>(rss.getSelectedRows());
if (!CommonUtils.isEmpty(selectedRows)) {
List<IResultSetController> objects = new ArrayList<>();
objects.add(rsv);
List<SQLGeneratorDescriptor> generators = SQLGeneratorConfigurationRegistry.getInstance().getApplicableGenerators(objects, rsv);
for (SQLGeneratorDescriptor gen : generators) {
if (gen.isMultiObject() && selectedRows.size() < 2) {
continue;
}
menu.add(makeAction(gen.getLabel(), gen, objects));
}
}
} else {
// if (dataContainer != null && !visibleAttributes.isEmpty() && entity != null)
String message = dataContainer == null ? "no data container" : (visibleAttributes.isEmpty() ? "empty attribute list" : "can't resolve table");
Action disabledAction = new Action("Not available - " + message) {
};
disabledAction.setEnabled(false);
menu.add(new ActionContributionItem(disabledAction));
}
}
Aggregations