1 19 20 package org.netbeans.modules.db.sql.execute.ui; 21 22 import java.io.IOException ; 23 import java.sql.ResultSet ; 24 import java.sql.ResultSetMetaData ; 25 import java.sql.SQLException ; 26 import java.util.List ; 27 import javax.swing.JButton ; 28 import javax.swing.table.AbstractTableModel ; 29 import org.netbeans.modules.db.core.SQLOptions; 30 import org.openide.DialogDisplayer; 31 import org.openide.NotifyDescriptor; 32 import org.openide.util.NbBundle; 33 import org.netbeans.modules.db.sql.execute.ColumnDef; 34 import org.netbeans.modules.db.sql.execute.FetchLimitHandler; 35 import org.netbeans.modules.db.sql.execute.ResultSetTableModelSupport; 36 import org.openide.awt.Mnemonics; 37 38 43 public class ResultSetTableModel extends AbstractTableModel { 44 45 48 private final List columnDefs; 49 private final List rows; 50 51 58 public static ResultSetTableModel create(ResultSet rs) throws SQLException , IOException { 59 ResultSetMetaData rsmd = rs.getMetaData(); 60 List columnDefs = ResultSetTableModelSupport.createColumnDefs(rsmd); 61 if (columnDefs == null) { return null; 63 } 64 List rows = ResultSetTableModelSupport.retrieveRows(rs, rsmd, new FetchLimitHandlerImpl()); 65 if (rows == null) { return null; 67 } 68 return new ResultSetTableModel(columnDefs, rows); 69 } 70 71 private ResultSetTableModel(List columnDefs, List rows) { 72 this.columnDefs = columnDefs; 73 this.rows = rows; 74 } 75 76 public int getRowCount() { 77 return rows.size(); 78 } 79 80 public int getColumnCount() { 81 return columnDefs.size(); 82 } 83 84 public Object getValueAt(int row, int column) { 85 List rowData = (List )rows.get(row); 86 return rowData.get(column); 87 } 88 89 public boolean isCellEditable(int row, int column) { 90 return false; 91 } 92 93 public String getColumnName(int column) { 94 return getColumnDef(column).getName(); 95 } 96 97 public Class getColumnClass(int column) { 98 return getColumnDef(column).getDisplayClass(); 99 } 100 101 private ColumnDef getColumnDef(int column) { 102 return (ColumnDef)columnDefs.get(column); 103 } 104 105 private static final class FetchLimitHandlerImpl implements FetchLimitHandler { 106 107 public int fetchLimitReached(int fetchCount) { 108 JButton fetchYes = new JButton (); 109 Mnemonics.setLocalizedText(fetchYes, NbBundle.getMessage(ResultSetTableModel.class, "LBL_FetchYes")); 110 fetchYes.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ResultSetTableModel.class, "ACSD_FetchYes")); 111 112 JButton fetchAll = new JButton (); 113 Mnemonics.setLocalizedText(fetchAll, NbBundle.getMessage(ResultSetTableModel.class, "LBL_FetchAll")); 114 fetchAll.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ResultSetTableModel.class, "ACSD_FetchAll")); 115 116 JButton fetchNo = new JButton (); 117 Mnemonics.setLocalizedText(fetchNo, NbBundle.getMessage(ResultSetTableModel.class, "LBL_FetchNo")); 118 fetchNo.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ResultSetTableModel.class, "ACSD_FetchNo")); 119 120 String title = NbBundle.getMessage(ResultSetTableModel.class, "LBL_FetchNextTitle"); 121 String message = NbBundle.getMessage(ResultSetTableModel.class, "LBL_FetchNextMessage", 122 new Object [] { new Integer (fetchCount), new Integer (SQLOptions.getDefault().getFetchStep()) }); 123 124 NotifyDescriptor desc = new NotifyDescriptor(message, title, NotifyDescriptor.YES_NO_CANCEL_OPTION, NotifyDescriptor.QUESTION_MESSAGE, new Object [] { fetchYes, fetchAll , fetchNo }, NotifyDescriptor.CANCEL_OPTION); 125 Object ret = DialogDisplayer.getDefault().notify(desc); 126 127 if (ret instanceof JButton ) { 128 if (ret == fetchYes) { 129 return fetchCount + SQLOptions.getDefault().getFetchStep(); 130 } else if (ret == fetchAll) { 131 return 0; 132 } else { 133 return fetchCount; 134 } 135 } else { 136 return fetchCount; 138 } 139 } 140 141 public int getFetchLimit() { 142 return SQLOptions.getDefault().getFetchStep(); 143 } 144 } 145 } 146 | Popular Tags |