Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
- Adding data toolbar for DQL execution results opened as a new editor tab
- Adding an option to change the DQL execution results column order and visibility
- Adding predefined timeframes to the DQL execution toolbar (user can still define a custom one)
- The DQL execution result will show an empty cell for a boolean column that had a `null` value (instead of the
unchecked checkbox). This change helps to differentiate between `false` and `null` values.
- The "Show DQL query" option when executing DQL will now try to show the parsed query instead of the raw one, if
possible.
- Adding support for "Expression DQL" file (with `.edql` extensions), which allows to define a DQL expression without
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.JBPopup;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.ui.table.JBTable;
import com.intellij.util.ui.ColumnInfo;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.ListTableModel;
Expand All @@ -34,6 +35,7 @@

import javax.swing.*;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import java.awt.*;
Expand Down Expand Up @@ -89,6 +91,7 @@ public void showColumnSettingsPopup(@NotNull AnActionEvent e) {
table.setAutoCreateRowSorter(true);
table.addRightClickSelection();
table.setDefaultRenderer(Object.class, new DQLCellRenderer());
table.setDefaultRenderer(Boolean.class, new NullableBooleanRenderer());
table.getTableHeader().setDefaultRenderer(new DQLHeaderRenderer(columnTypes, table.getTableHeader()));
updateColumnSizes(table, columnTypes);

Expand Down Expand Up @@ -149,9 +152,8 @@ private List<ColumnInfo<DQLRecord, Object>> calculateColumns(@NotNull Set<String
String columnValue = columnTypes.get(s);
try {
return switch (columnValue) {
case "double", "number" -> Double.valueOf(stringValue);
case "boolean" -> Boolean.valueOf(stringValue);
case "long" -> Long.valueOf(stringValue);
case "double", "number", "long" -> Double.valueOf(stringValue);
case "boolean" -> stringValue == null ? null : Boolean.valueOf(stringValue);
case "array", "record", "timeframe" -> {
try {
yield mapper.writeValueAsString(value);
Expand Down Expand Up @@ -197,6 +199,26 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole
}
}

private static final class NullableBooleanRenderer extends CommonTableCellRenderer {
private final TableCellRenderer delegate = new JBTable().getDefaultRenderer(Boolean.class);
private final JLabel empty = new JLabel();

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Component original = delegate.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (value == null && original instanceof JComponent component) {
empty.setOpaque(component.isOpaque());
empty.setBackground(component.getBackground());
empty.setForeground(component.getForeground());
empty.setBorder(component.getBorder());
empty.setText("");
empty.setIcon(null);
return empty;
}
return original;
}
}

private static final class DQLHeaderRenderer extends CommonTableHeaderRenderer {
private final Map<String, String> columnTypes;

Expand Down
Loading