EditorAdmin
codice:
public class EditorAdmin extends javax.swing.JFrame
{
public EditorAdmin() throws SQLException
{
setResizable(false);
initComponents();
ini();
aggiorna_lista();
aggiorna_tabella();
}
DefaultTableModel model = new DefaultTableModel(new Object[] { "Tabella", "Campo" }, 0)
{
private static final long serialVersionUID = 1L;
public boolean isCellEditable(int row, int column)
{
//all cells false
return false;
}
};
ComponentiEpad sessione = new ComponentiEpad();
Generatore myGen = new Generatore();
private String tabella;
private void jButtonChiudiActionPerformed(java.awt.event.ActionEvent evt) {
EditorEpad.start(null);
dispose();
}
private void jListTabelleValueChanged(javax.swing.event.ListSelectionEvent evt) {
tabella = (String) jListTabelle.getSelectedValue(); //restituisce l'item selezionato
jListCampi.setModel(ComponentiEpad.listModel("campi", tabella));
}
private void jListCampiValueChanged(javax.swing.event.ListSelectionEvent evt) {
}
private void jButtonGeneraCCActionPerformed(java.awt.event.ActionEvent evt) {
String nome = "";
int[] selectedIx = jListCampi.getSelectedIndices();
Record campoSel[] = new Record[selectedIx.length];
for (int i = 0; i < selectedIx.length; i++)
{
campoSel[i] = new Record();
campoSel[i].nome = (String) (jListCampi.getModel().getElementAt(selectedIx[i]));
System.out.println("camposel = "+campoSel[i].nome);
nome += campoSel[i].nome + "\n";
}
int n;
n = JOptionPane.showConfirmDialog(
null,
"Sono stati selezionati i seguenti campi:\n" + nome + "Continuare?",
"Generazione CC",
JOptionPane.YES_NO_OPTION);
if (n == JOptionPane.YES_OPTION)
{
double inizio = System.currentTimeMillis();
try {
myGen.generaCC(sessione.getGrado(), tabella, campoSel);
} catch (SQLException ex) {
Logger.getLogger(EditorAdmin.class.getName()).log(Level.SEVERE, null, ex);
}
double fine = System.currentTimeMillis();
double durata = (fine - inizio) / 1000;
System.out.println("durata: " +durata);
JOptionPane.showMessageDialog(null,
"Calcolo concluso",
"Generazione CC",
JOptionPane.INFORMATION_MESSAGE);
}
for (int i = 0; i < selectedIx.length; i++)
{
String[] tab = {tabella, campoSel[i].nome};
model.addRow(tab);
jTableCoefficienti.setModel(model);
}
EditorEpad.aggiorna_lista();
}
private void jButtonEliminaActionPerformed(java.awt.event.ActionEvent evt) {
Object selection = jTableCoefficienti.getValueAt(jTableCoefficienti.getSelectedRow(), 0);
int n;
n = JOptionPane.showConfirmDialog(
null,
"Vuoi cancellare i CC calcolati sulla tabella " + selection + "?",
"Elimina",
JOptionPane.YES_NO_OPTION);
if (n == JOptionPane.YES_OPTION)
{
myGen.eliminaCC((String) selection);
}
try {
aggiorna_tabella();
} catch (SQLException ex) {
Logger.getLogger(EditorAdmin.class.getName()).log(Level.SEVERE, null, ex);
}
//EditorEpad.aggiorna_lista();
}
public static void start(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
try {
new EditorAdmin().setVisible(true);
} catch (SQLException ex) {
Logger.getLogger(EditorAdmin.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
}
private void ini()
{
jTableCoefficienti.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
jTableCoefficienti.setAutoCreateRowSorter(true);
jTableCoefficienti.setNextFocusableComponent(jTableCoefficienti);
jTableCoefficienti.getTableHeader().setReorderingAllowed(false);
jScrollPane3.setViewportView(jTableCoefficienti);
jListTabelle.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
jListCampi.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
}
private void aggiorna_lista() {
jListTabelle.setModel(ComponentiEpad.listModel("tabella", null));
}
private void aggiorna_tabella() throws SQLException {
jTableCoefficienti.setModel( (TableModel) ComponentiEpad.tableModel("campo"));
}