Search in sources :

Example 1 with SelectDataDialog

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());
    }
}
Also used : SQLException(java.sql.SQLException) SelectDataDialog(easik.ui.datamanip.SelectDataDialog) ResultSetMetaData(java.sql.ResultSetMetaData) JTable(javax.swing.JTable) ResultSet(java.sql.ResultSet) JDBCDriver(easik.database.api.jdbc.JDBCDriver) Vector(java.util.Vector)

Example 2 with SelectDataDialog

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

Example 3 with SelectDataDialog

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;
}
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

SelectDataDialog (easik.ui.datamanip.SelectDataDialog)3 SQLException (java.sql.SQLException)3 JTable (javax.swing.JTable)3 JDBCDriver (easik.database.api.jdbc.JDBCDriver)2 PersistenceDriver (easik.database.base.PersistenceDriver)2 ResultSet (java.sql.ResultSet)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 Vector (java.util.Vector)1 JDialog (javax.swing.JDialog)1 JFrame (javax.swing.JFrame)1