loggerThreadCheckBox.setOpaque(false);
loggerThreadCheckBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
boolean isThreadDisplayed = e.getStateChange() == ItemEvent.SELECTED;
XTableColumnModel columnModel = (XTableColumnModel)table.getColumnModel();
columnModel.setColumnVisible(columnModel.getColumnByModelIndex(COLUMN_THREAD), isThreadDisplayed);
table.adjustLastColumn();
}
});
loggerHeaderCenterPanel.add(loggerThreadCheckBox);
JCheckBox loggerTimestampCheckBox = new JCheckBox("Timestamps", true);
loggerTimestampCheckBox.setOpaque(false);
loggerTimestampCheckBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
boolean isTimestampDisplayed = e.getStateChange() == ItemEvent.SELECTED;
XTableColumnModel columnModel = (XTableColumnModel)table.getColumnModel();
columnModel.setColumnVisible(columnModel.getColumnByModelIndex(COLUMN_TIMESTAMP), isTimestampDisplayed);
table.adjustLastColumn();
}
});
loggerHeaderCenterPanel.add(loggerTimestampCheckBox);
JCheckBox preparedStatementDataCheckBox = new JCheckBox("PS Data", true);
preparedStatementDataCheckBox.setOpaque(false);
preparedStatementDataCheckBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
boolean isPreparedStatementDataShown = e.getStateChange() == ItemEvent.SELECTED;
XTableColumnModel columnModel = (XTableColumnModel)table.getColumnModel();
columnModel.setColumnVisible(columnModel.getColumnByModelIndex(COLUMN_PS_PREPARATION_DURATION), isPreparedStatementDataShown);
columnModel.setColumnVisible(columnModel.getColumnByModelIndex(COLUMN_PS_BINDING_DURATION), isPreparedStatementDataShown);
table.adjustLastColumn();
}
});
loggerHeaderCenterPanel.add(preparedStatementDataCheckBox);
JCheckBox loggerDurationCheckBox = new JCheckBox("Exec Time", true);
loggerDurationCheckBox.setOpaque(false);
loggerDurationCheckBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
boolean isDurationDisplayed = e.getStateChange() == ItemEvent.SELECTED;
XTableColumnModel columnModel = (XTableColumnModel)table.getColumnModel();
columnModel.setColumnVisible(columnModel.getColumnByModelIndex(COLUMN_EXEC_TIME), isDurationDisplayed);
table.adjustLastColumn();
}
});
loggerHeaderCenterPanel.add(loggerDurationCheckBox);
JCheckBox resultSetDataCheckBox = new JCheckBox("RS Data", true);
resultSetDataCheckBox.setOpaque(false);
resultSetDataCheckBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
boolean isResultSetDataShown = e.getStateChange() == ItemEvent.SELECTED;
XTableColumnModel columnModel = (XTableColumnModel)table.getColumnModel();
columnModel.setColumnVisible(columnModel.getColumnByModelIndex(COLUMN_RS_LIFETIME), isResultSetDataShown);
columnModel.setColumnVisible(columnModel.getColumnByModelIndex(COLUMN_RS_READ), isResultSetDataShown);
columnModel.setColumnVisible(columnModel.getColumnByModelIndex(COLUMN_RS_READ_ROWS), isResultSetDataShown);
table.adjustLastColumn();
}
});
loggerHeaderCenterPanel.add(resultSetDataCheckBox);
JCheckBox duplicationCountCheckBox = new JCheckBox("Duplication", true);
duplicationCountCheckBox.setOpaque(false);
duplicationCountCheckBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
boolean isDuplicationCountShown = e.getStateChange() == ItemEvent.SELECTED;
XTableColumnModel columnModel = (XTableColumnModel)table.getColumnModel();
columnModel.setColumnVisible(columnModel.getColumnByModelIndex(COLUMN_DUPLICATION_COUNT), isDuplicationCountShown);
table.adjustLastColumn();
}
});
loggerHeaderCenterPanel.add(duplicationCountCheckBox);
loggerHeaderPanel.add(loggerHeaderCenterPanel, BorderLayout.CENTER);
JToolBar loggerHeaderEastPanel = new JToolBar();
loggerHeaderEastPanel.setFloatable(false);
loggerHeaderEastPanel.setOpaque(false);
JToggleButton loggerReadQueryTypeToggleButton = new JToggleButton(SELECT_ICON, isReadQueryTypeDisplayed);
loggerReadQueryTypeToggleButton.setOpaque(false);
loggerReadQueryTypeToggleButton.setFocusable(false);
loggerReadQueryTypeToggleButton.setToolTipText("Show/hide read statements");
loggerReadQueryTypeToggleButton.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
isReadQueryTypeDisplayed = e.getStateChange() == ItemEvent.SELECTED;
refreshRows();
}
});
loggerHeaderEastPanel.add(loggerReadQueryTypeToggleButton);
JToggleButton loggerWriteQueryTypeToggleButton = new JToggleButton(UPDATE_ICON, isWriteQueryTypeDisplayed);
loggerWriteQueryTypeToggleButton.setOpaque(false);
loggerWriteQueryTypeToggleButton.setFocusable(false);
loggerWriteQueryTypeToggleButton.setToolTipText("Show/hide modification statements");
loggerWriteQueryTypeToggleButton.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
isWriteQueryTypeDisplayed = e.getStateChange() == ItemEvent.SELECTED;
refreshRows();
}
});
loggerHeaderEastPanel.add(loggerWriteQueryTypeToggleButton);
JToggleButton loggerOtherQueryTypeToggleButton = new JToggleButton(OTHER_ICON, isOtherQueryTypeDisplayed);
loggerOtherQueryTypeToggleButton.setOpaque(false);
loggerOtherQueryTypeToggleButton.setFocusable(false);
loggerOtherQueryTypeToggleButton.setToolTipText("Show/hide other types of statements");
loggerOtherQueryTypeToggleButton.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
isOtherQueryTypeDisplayed = e.getStateChange() == ItemEvent.SELECTED;
refreshRows();
}
});
loggerHeaderEastPanel.add(loggerOtherQueryTypeToggleButton);
JButton loggerClearButton = new JButton(new ImageIcon(getClass().getResource("/org/jooq/debug/console/resources/Clear16.png")));
loggerClearButton.setOpaque(false);
loggerClearButton.setFocusable(false);
loggerClearButton.setToolTipText("Clear collected data");
loggerClearButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
queryDebuggingInfoList.clear();
textArea.setText("");
int originalRowCount = displayedQueryDebuggingInfoList.size();
displayedQueryDebuggingInfoList.clear();
queriesToCountMap.clear();
if(originalRowCount > 0) {
((AbstractTableModel)table.getModel()).fireTableRowsDeleted(0, originalRowCount - 1);
}
updateStatusLabel();
}
});
loggerHeaderEastPanel.add(new JToolBar.Separator());
loggerHeaderEastPanel.add(loggerClearButton);
JToggleButton scrollLockToggleButton = new JToggleButton(new ImageIcon(getClass().getResource("/org/jooq/debug/console/resources/LockScroll16.png")));
scrollLockToggleButton.setFocusable(false);
scrollLockToggleButton.setToolTipText("Scroll Lock");
scrollLockToggleButton.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
isScrollLocked = e.getStateChange() == ItemEvent.SELECTED;
}
});
loggerHeaderEastPanel.add(scrollLockToggleButton);
loggerHeaderPanel.add(loggerHeaderEastPanel, BorderLayout.EAST);
add(loggerHeaderPanel, BorderLayout.NORTH);
table = new JTableX(new AbstractTableModel() {
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
QueryDebuggingInfo queryDebuggingInfo = displayedQueryDebuggingInfoList.get(rowIndex);
switch(columnIndex) {
case COLUMN_LINE: {
return rowIndex + 1;
}
case COLUMN_TYPE: {
return queryDebuggingInfo.getQueryType();
}
case COLUMN_THREAD: {
return queryDebuggingInfo.getThreadName() + " [" + queryDebuggingInfo.getThreadId() + "]";
}
case COLUMN_TIMESTAMP: {
return TIMESTAMP_FORMAT.format(new Date(queryDebuggingInfo.getTimestamp()));
}
case COLUMN_PS_PREPARATION_DURATION: {
Long duration = queryDebuggingInfo.getPrepardeStatementPreparationDuration();
return duration == null? null: duration;
}
case COLUMN_PS_BINDING_DURATION: {
Long duration = queryDebuggingInfo.getPrepardeStatementBindingDuration();
return duration == null? null: duration;
}
case COLUMN_EXEC_TIME: {
long duration = queryDebuggingInfo.getExecutionDuration();
return duration < 0? null: duration;
}
case COLUMN_RS_LIFETIME: {
DebuggerResultSetData rsData = queryDebuggingInfo.getSqlQueryDebuggerResultSetData();
return rsData == null? null: rsData.getLifeTime();
}
case COLUMN_RS_READ: {
DebuggerResultSetData rsData = queryDebuggingInfo.getSqlQueryDebuggerResultSetData();
return rsData == null? null: rsData.getReadCount();
}
case COLUMN_RS_READ_ROWS: {
DebuggerResultSetData rsData = queryDebuggingInfo.getSqlQueryDebuggerResultSetData();
return rsData == null? null: rsData.getReadRows();
}
case COLUMN_DUPLICATION_COUNT: {
return queryDebuggingInfo.getDuplicationCount();
}
case COLUMN_QUERY: {
StringBuilder querySB = new StringBuilder();
String[] queries = queryDebuggingInfo.getQueries();
for(int i=0; i<queries.length; i++) {
if(i > 0) {
querySB.append(LS);
}
String s = queries[i];
querySB.append(s.trim());
}
return querySB.toString();
}
}
return null;
}
@Override
public int getRowCount() {
return displayedQueryDebuggingInfoList.size();
}
@Override
public int getColumnCount() {
return COLUMN_COUNT;
}
@Override
public String getColumnName(int column) {
switch(column) {
case COLUMN_LINE:
return "Line";
case COLUMN_TYPE:
return "Type";
case COLUMN_THREAD:
return "Thread";
case COLUMN_TIMESTAMP:
return "Timestamp";
case COLUMN_PS_PREPARATION_DURATION:
return "PS preparation (ms)";
case COLUMN_PS_BINDING_DURATION:
return "PS binding (ms)";
case COLUMN_EXEC_TIME:
return "Exec time (ms)";
case COLUMN_RS_LIFETIME:
return "RS lifetime (ms)";
case COLUMN_RS_READ:
return "RS read";
case COLUMN_RS_READ_ROWS:
return "RS rows";
case COLUMN_DUPLICATION_COUNT:
return "Duplic.";
case COLUMN_QUERY:
return "Query";
}
return null;
}
@Override
public Class<?> getColumnClass(int columnIndex) {
switch(columnIndex) {
case COLUMN_LINE: return Integer.class;
case COLUMN_TYPE: return SqlQueryType.class;
case COLUMN_PS_PREPARATION_DURATION: return Long.class;
case COLUMN_PS_BINDING_DURATION: return Long.class;
case COLUMN_EXEC_TIME: return Long.class;
case COLUMN_RS_LIFETIME: return Long.class;
case COLUMN_RS_READ: return Integer.class;
case COLUMN_RS_READ_ROWS: return Integer.class;
case COLUMN_DUPLICATION_COUNT: return Integer.class;
case COLUMN_QUERY: return String.class;
}
return super.getColumnClass(columnIndex);
}
});
registerTooltip();
table.setAutoCreateRowSorter(true);
table.getRowSorter().setSortKeys(Arrays.asList(new RowSorter.SortKey(COLUMN_LINE, SortOrder.ASCENDING)));
XTableColumnModel columnModel = new XTableColumnModel();
table.setColumnModel(columnModel);
table.createDefaultColumnsFromModel();
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
columnModel.getColumnByModelIndex(COLUMN_LINE).setPreferredWidth(30);
columnModel.getColumnByModelIndex(COLUMN_TYPE).setPreferredWidth(20);
columnModel.getColumnByModelIndex(COLUMN_TIMESTAMP).setPreferredWidth(80);
columnModel.getColumnByModelIndex(COLUMN_THREAD).setPreferredWidth(150);
columnModel.getColumnByModelIndex(COLUMN_DUPLICATION_COUNT).setPreferredWidth(40);
table.setColumnSelectionAllowed(true);
table.setFillsViewportHeight(true);
// ToolTipManager.sharedInstance().registerComponent(table);
table.setDefaultRenderer(SqlQueryType.class, new DefaultTableCellRenderer() {
@Override