Search in sources :

Example 1 with PersistenceDriver

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;
}
Also used : SQLException(java.sql.SQLException) JFrame(javax.swing.JFrame) PersistenceDriver(easik.database.base.PersistenceDriver) JTable(javax.swing.JTable) SelectDataDialog(easik.ui.datamanip.SelectDataDialog) JDialog(javax.swing.JDialog)

Aggregations

PersistenceDriver (easik.database.base.PersistenceDriver)1 SelectDataDialog (easik.ui.datamanip.SelectDataDialog)1 SQLException (java.sql.SQLException)1 JDialog (javax.swing.JDialog)1 JFrame (javax.swing.JFrame)1 JTable (javax.swing.JTable)1