diff --git a/src/main/java/com/alibaba/druid/jconsole/SQLDetailDialog.java b/src/main/java/com/alibaba/druid/jconsole/SQLDetailDialog.java new file mode 100644 index 0000000000..76f5f687ea --- /dev/null +++ b/src/main/java/com/alibaba/druid/jconsole/SQLDetailDialog.java @@ -0,0 +1,12 @@ +package com.alibaba.druid.jconsole; + +import javax.swing.JDialog; + +public class SQLDetailDialog extends JDialog { + + private static final long serialVersionUID = 1L; + + public SQLDetailDialog(Object[] row) { + + } +} diff --git a/src/main/java/com/alibaba/druid/jconsole/SQLDetailPanel.java b/src/main/java/com/alibaba/druid/jconsole/SQLDetailPanel.java index 6310dae951..fc2049ea8f 100644 --- a/src/main/java/com/alibaba/druid/jconsole/SQLDetailPanel.java +++ b/src/main/java/com/alibaba/druid/jconsole/SQLDetailPanel.java @@ -6,4 +6,9 @@ public class SQLDetailPanel extends JPanel { private static final long serialVersionUID = 1L; + private Object[] row; + + public SQLDetailPanel(Object[] row) { + this.row = row; + } } diff --git a/src/main/java/com/alibaba/druid/jconsole/SQLPanel.java b/src/main/java/com/alibaba/druid/jconsole/SQLPanel.java index 9806175d33..e9582bde6c 100644 --- a/src/main/java/com/alibaba/druid/jconsole/SQLPanel.java +++ b/src/main/java/com/alibaba/druid/jconsole/SQLPanel.java @@ -1,6 +1,8 @@ package com.alibaba.druid.jconsole; import java.awt.BorderLayout; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.List; @@ -11,6 +13,7 @@ import javax.management.openmbean.TabularData; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; +import javax.swing.ListSelectionModel; public class SQLPanel extends JPanel { @@ -22,15 +25,15 @@ public class SQLPanel extends JPanel { private JTable table; - private String[] columns = { "ID", "DataSource", "SQL", "ExecuteCount", "ErrorCount", - - "TotalTime", "LastTime", "MaxTimespan", "LastError", "EffectedRowCount", - - "FetchRowCount", "MaxTimespanOccurTime", "BatchSizeMax", "BatchSizeTotal", "ConcurrentMax", - - "RunningCount", "Name", "File", "LastErrorMessage", "LastErrorClass", - - "LastErrorStackTrace", "LastErrorTime", "DbType" }; + private String[] columns = { "ID", "Name", "File", "SQL", "ExecuteCount", + + "ErrorCount", "TotalTime", "LastTime", "MaxTimespan", "LastError", + + "EffectedRowCount", "FetchRowCount", "MaxTimespanOccurTime", "BatchSizeMax", "BatchSizeTotal", + + "ConcurrentMax", "RunningCount", "LastErrorMessage", "LastErrorClass", "LastErrorStackTrace", + + "LastErrorTime"}; public SQLPanel(MBeanServerConnection connection, ObjectInstance objectInstance, DataSourceInfo dataSourceInfo){ super(); @@ -45,9 +48,9 @@ public class SQLPanel extends JPanel { for (Object item : connectionTabularData.values()) { CompositeData rowData = (CompositeData) item; - + String url = (String) rowData.get("DataSource"); - + if (!dataSourceInfo.getUrl().equals(url)) { continue; } @@ -55,32 +58,30 @@ public class SQLPanel extends JPanel { Object[] row = new Object[columns.length]; int columnIndex = 0; row[columnIndex++] = rowData.get("ID"); - row[columnIndex++] = rowData.get("DataSource"); + row[columnIndex++] = rowData.get("Name"); + row[columnIndex++] = rowData.get("File"); row[columnIndex++] = rowData.get("SQL"); row[columnIndex++] = rowData.get("ExecuteCount"); - row[columnIndex++] = rowData.get("ErrorCount"); + row[columnIndex++] = rowData.get("ErrorCount"); row[columnIndex++] = rowData.get("TotalTime"); row[columnIndex++] = rowData.get("LastTime"); row[columnIndex++] = rowData.get("MaxTimespan"); row[columnIndex++] = rowData.get("LastError"); - row[columnIndex++] = rowData.get("EffectedRowCount"); + row[columnIndex++] = rowData.get("EffectedRowCount"); row[columnIndex++] = rowData.get("FetchRowCount"); row[columnIndex++] = rowData.get("MaxTimespanOccurTime"); row[columnIndex++] = rowData.get("BatchSizeMax"); row[columnIndex++] = rowData.get("BatchSizeTotal"); - row[columnIndex++] = rowData.get("ConcurrentMax"); + row[columnIndex++] = rowData.get("ConcurrentMax"); row[columnIndex++] = rowData.get("RunningCount"); - row[columnIndex++] = rowData.get("Name"); - row[columnIndex++] = rowData.get("File"); row[columnIndex++] = rowData.get("LastErrorMessage"); row[columnIndex++] = rowData.get("LastErrorClass"); - row[columnIndex++] = rowData.get("LastErrorStackTrace"); + row[columnIndex++] = rowData.get("LastErrorTime"); - row[columnIndex++] = rowData.get("DbType"); rowList.add(row); } @@ -88,6 +89,13 @@ public class SQLPanel extends JPanel { Object[][] rows = new Object[rowList.size()][]; rowList.toArray(rows); table = new JTable(rows, columns); + table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + table.addMouseListener(new MouseAdapter() { + + public void mouseClicked(MouseEvent e) { + tableMouseClicked(e); + } + }); JScrollPane tableScrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); @@ -98,6 +106,25 @@ public class SQLPanel extends JPanel { } } + public void tableMouseClicked(MouseEvent e) { + if (e.getClickCount() < 2) { + return; + } + + int rowIndex = table.getSelectedRow(); + if (rowIndex < 0) { + return; + } + + Object[] row = new Object[columns.length]; + for (int i = 0; i < row.length; ++i) { + row[i] = table.getModel().getValueAt(rowIndex, i); + } + + SQLDetailDialog dialog = new SQLDetailDialog(row); + dialog.setVisible(true); + } + public MBeanServerConnection getConnection() { return connection; }