use of easik.ui.datamanip.SelectDataDialog in project fql by CategoricalData.
the class DatabaseUtil method displayQueryNode.
/**
* @param node
* @param parent
*/
@SuppressWarnings({ "rawtypes", "unchecked", "unused" })
public static void displayQueryNode(final QueryNode node, final JFrame parent) {
final JDBCDriver dbd;
final ResultSet result;
final ResultSetMetaData rsmd;
final Vector<Object[]> data;
final JTable asTable;
final String[] columnNames;
final int cols;
try {
dbd = node.getMModel().getSketch().getDatabase().getJDBCDriver();
result = dbd.executeQuery(node.getQuery());
rsmd = result.getMetaData();
cols = rsmd.getColumnCount();
// build 2D array of data
data = new Vector();
columnNames = new String[cols];
int currRow, i;
// Populate array of column names
for (i = 0; i < cols; i++) {
columnNames[i] = rsmd.getColumnName(i + 1);
}
while (result.next()) {
currRow = result.getRow();
// if we have no rows, break
if (currRow == 0) {
break;
}
final Object[] row = new Object[cols];
for (i = 0; i < cols; i++) {
row[i] = result.getString(columnNames[i]);
}
data.add(row);
}
final Object[][] dataObj = data.toArray(new Object[0][0]);
asTable = new JTable(dataObj, columnNames);
new SelectDataDialog(parent, node.getName(), asTable);
} catch (SQLException e) {
JOptionPane.showMessageDialog(node.getMModel().getSketch().getFrame(), "Could not get record: " + e.getMessage());
}
}
use of easik.ui.datamanip.SelectDataDialog in project fql by CategoricalData.
the class DatabaseUtil method selectRowPKs.
/**
* Pops up a dialog for the user to select records from the table
* represented by the given entity node. The primary IDs of the records are
* returned.
*
* @param frame
* the JFrame to attach the dialog to
* @param table
* The entity node representing the table from which we wish to
* select the records
* @return An array of primary IDs representing the records we selected
*/
public static int[] selectRowPKs(final JFrame frame, final EntityNode table) {
@SuppressWarnings("unused") final JDBCDriver dbd;
final JTable tableData;
try {
dbd = table.getMModel().getDatabase().getJDBCDriver();
tableData = getTable(table);
} catch (PersistenceDriver.LoadException e) {
System.err.println("Error in DatabaseUtil: " + e.getMessage());
return null;
} catch (SQLException e) {
System.err.println("Error in DatabaseUtil: " + e.getMessage());
return null;
}
final SelectDataDialog sdd = new SelectDataDialog(frame, table.getName(), tableData);
if (sdd.isAccepted()) {
return sdd.getSelectedPKs();
}
return new int[0];
}
use of easik.ui.datamanip.SelectDataDialog in project fql by CategoricalData.
the class DatabaseUtil method selectRowPK.
/**
* Pops up a dialog for the user to select a single record from the table
* represented by the given entity node. The primary ID of the selected
* record is returned.
*
* @param win
* the JFrame or JDialog to attach the dialog to
* @param table
* The entity node representing the table from which we wish to
* select the record
* @return The primary ID representing the record we selected
*/
public static int selectRowPK(final Window win, final EntityNode table) {
@SuppressWarnings("unused") final PersistenceDriver dbd;
final JTable tableData;
try {
dbd = table.getMModel().getDatabase().getJDBCDriver();
tableData = getTable(table);
tableData.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
} catch (PersistenceDriver.LoadException e) {
System.err.println("Error in DatabaseUtil: " + e.getMessage());
// 0 is an invalid PK
return 0;
} catch (SQLException e) {
System.err.println("Error in DatabaseUtil: " + e.getMessage());
// 0 is an invalid PK
return 0;
}
final SelectDataDialog sdd = (win instanceof JDialog) ? new SelectDataDialog((JDialog) win, table.getName(), tableData) : new SelectDataDialog((JFrame) win, table.getName(), tableData);
if (sdd.isAccepted()) {
// recall that we set our table for singleton selection
final int[] selected = sdd.getSelectedPKs();
return selected[0];
}
// 0 is an invalid PK
return 0;
}
Aggregations