Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dbeaver/pro#3198 Properly show first deepest collection element
Browse files Browse the repository at this point in the history
ShadelessFox committed Sep 2, 2024
1 parent 07be08f commit 9bd9d6b
Showing 3 changed files with 43 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -688,17 +688,19 @@ public static DBDAttributeBinding[] injectAndFilterAttributeBindings(@NotNull DB
@Nullable
public static Object getAttributeValue(
@NotNull DBDAttributeBinding attribute,
DBDAttributeBinding[] allAttributes,
Object[] row) {
return getAttributeValue(attribute, allAttributes, row, null);
@NotNull DBDAttributeBinding[] allAttributes,
@NotNull Object[] row
) {
return getAttributeValue(attribute, allAttributes, row, null, false);
}

@Nullable
public static Object getAttributeValue(
@NotNull DBDAttributeBinding attribute,
@NotNull DBDAttributeBinding[] allAttributes,
@NotNull Object[] row,
@Nullable int[] nestedIndexes
@Nullable int[] nestedIndexes,
boolean retrieveDeepestCollectionElement
) {
if (attribute.isCustom()) {
try {
@@ -734,7 +736,7 @@ public static Object getAttributeValue(
pendingIndices.offer(nestedIndexes[i]);
}

while (!pendingAttributes.isEmpty() || !pendingIndices.isEmpty()) {
while (!pendingAttributes.isEmpty() || !pendingIndices.isEmpty() || retrieveDeepestCollectionElement) {
if (curValue == null) {
break;
}
@@ -752,15 +754,23 @@ public static Object getAttributeValue(
}

while (curValue instanceof DBDCollection collection) {
if (pendingIndices.isEmpty()) {
int itemIndex;
if (!pendingIndices.isEmpty()) {
itemIndex = pendingIndices.pop();
} else if (retrieveDeepestCollectionElement) {
itemIndex = 0;
} else {
return curValue;
}
int itemIndex = pendingIndices.pop();
if (itemIndex >= collection.getItemCount()) {
return DBDVoid.INSTANCE;
}
curValue = collection.get(itemIndex);
}

if (retrieveDeepestCollectionElement && pendingAttributes.isEmpty()) {
return curValue;
}
}

return curValue;
Original file line number Diff line number Diff line change
@@ -380,29 +380,28 @@ void setTotalRowCount(Long totalRowCount) {

@Nullable
public Object getCellValue(@NotNull ResultSetCellLocation cellLocation) {
return DBUtils.getAttributeValue(
cellLocation.getAttribute(),
attributes,
cellLocation.getRow().values,
cellLocation.getRowIndexes());
return getCellValue(cellLocation.getAttribute(), cellLocation.getRow(), cellLocation.getRowIndexes(), false);
}

@Nullable
public Object getCellValue(@NotNull DBDAttributeBinding attribute, @NotNull ResultSetRow row) {
return DBUtils.getAttributeValue(
attribute,
attributes,
row.values,
null);
return getCellValue(attribute, row, null, false);
}

@Nullable
public Object getCellValue(@NotNull DBDAttributeBinding attribute, @NotNull ResultSetRow row, @Nullable int[] rowIndexes) {
public Object getCellValue(
@NotNull DBDAttributeBinding attribute,
@NotNull ResultSetRow row,
@Nullable int[] rowIndexes,
boolean retrieveDeepestCollectionElement
) {
return DBUtils.getAttributeValue(
attribute,
attributes,
row.values,
rowIndexes);
rowIndexes,
retrieveDeepestCollectionElement
);
}

/**
Original file line number Diff line number Diff line change
@@ -2312,7 +2312,7 @@ public CellInformation getCellInfo(@NotNull IGridColumn colElement, @NotNull IGr
if (cellValue instanceof Number) {
cellValue = ((Number) cellValue).byteValue() != 0;
}
if (DBUtils.isNullValue(cellValue) || cellValue instanceof Boolean) {
if (cellValue instanceof Boolean || cellValue == null) {
info.image = booleanStyles.getStyle((Boolean) cellValue).getIcon();
}
}
@@ -2358,7 +2358,7 @@ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
@Nullable
@Override
public Object getCellValue(IGridColumn gridColumn, IGridRow gridRow, boolean formatString) {
final Object value = getCellValue(gridColumn, gridRow, getRowNestedIndexes(gridRow));
final Object value = getCellValue(gridColumn, gridRow, getRowNestedIndexes(gridRow), false);
if (formatString) {
return formatValue(gridColumn, gridRow, value);
} else {
@@ -2367,7 +2367,12 @@ public Object getCellValue(IGridColumn gridColumn, IGridRow gridRow, boolean for
}

@Nullable
public Object getCellValue(@NotNull IGridColumn gridColumn, @NotNull IGridRow gridRow, @Nullable int[] rowIndexes) {
public Object getCellValue(
@NotNull IGridColumn gridColumn,
@NotNull IGridRow gridRow,
@Nullable int[] rowIndexes,
boolean retrieveDeepestCollectionElement
) {
if (gridRow.getParent() != null && !spreadsheet.isCellExpanded(gridRow.getParent(), gridColumn)) {
return DBDVoid.INSTANCE;
}
@@ -2376,7 +2381,7 @@ public Object getCellValue(@NotNull IGridColumn gridColumn, @NotNull IGridRow gr
if (attr == null || row == null) {
return null;
}
return controller.getModel().getCellValue(attr, row, rowIndexes);
return controller.getModel().getCellValue(attr, row, rowIndexes, retrieveDeepestCollectionElement);
}

@Nullable
@@ -2386,6 +2391,7 @@ private Object formatValue(@NotNull IGridColumn gridColumn, @NotNull IGridRow gr
if (attr == null || row == null) {
return null;
}

if (DBUtils.isNullValue(value) && row.getState() == ResultSetRow.STATE_ADDED) {
// New row and no value. Let's try to show default value
DBSEntityAttribute entityAttribute = attr.getEntityAttribute();
@@ -2413,27 +2419,17 @@ private Object formatValue(@NotNull IGridColumn gridColumn, @NotNull IGridRow gr
}
return value;
}
if (value instanceof DBDCollection)
return "<collection>";
if (value instanceof DBDComposite)
return "<composite>";
/*if (isShowAsExpander(null, attr, value)) {
if (isShowAsExpander(null, attr, value)) {
if (spreadsheet.isCellExpanded(gridRow, gridColumn) && value instanceof DBDCollection collection) {
return COLLECTION_SIZE_FORMAT.format(new Object[]{collection.size()});
}
int count = 0;
for (DBDAttributeBinding cur = attr; cur != null; cur = cur.getParentObject()) {
if (cur.getDataKind() == DBPDataKind.ARRAY) {
count++;
}
}
Object child = getCellValue(gridColumn, gridRow, new int[count]);
Object child = getCellValue(gridColumn, gridRow, getRowNestedIndexes(gridRow), true);
if (child == value) {
return value;
}
return formatValue(gridColumn, gridRow, child);
} else */if (attr.getDataKind() == DBPDataKind.STRUCT && value instanceof DBDComposite && !DBUtils.isNullValue(value)) {
return "[" + ((DBDComposite) value).getDataType().getName() + "]";
} else if (value instanceof DBDComposite composite && !DBUtils.isNullValue(value)) {
return "[" + composite.getDataType().getName() + "]";
}
try {
return attr.getValueRenderer().getValueDisplayString(
@@ -2756,9 +2752,7 @@ private boolean isShowAsCheckbox(DBDAttributeBinding attr) {
}

private boolean isShowAsExpander(@Nullable IGridRow rowElement, @NotNull DBDAttributeBinding attr, @Nullable Object value) {
return spreadsheet.getColumnCount() > 1
&& isAttributeExpandable(rowElement, attr)
&& value instanceof DBDCollection collection && !collection.isNull();
return value instanceof DBDCollection collection && !collection.isNull() && isAttributeExpandable(rowElement, attr);
}

private class GridLabelProvider implements IGridLabelProvider {

0 comments on commit 9bd9d6b

Please sign in to comment.