use of easik.database.base.PersistenceDriver 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