/*
* NewUzaverkaList.java
*
* Created on 4.11.2010, 15:04:20
*/
package cz.cvut.fel.restauracefel.storage.sklad_gui;
import cz.cvut.fel.restauracefel.hibernate.User;
import cz.cvut.fel.restauracefel.library.service.LocalizationManager;
import cz.cvut.fel.restauracefel.storage.storageController.StorageController;
import java.io.FileNotFoundException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import cz.cvut.fel.restauracefel.storage.zrcadlo.controller.UzaverkaController;
import cz.cvut.fel.restauracefel.storage.zrcadlo.controller.ValidateInputException;
/**
*
* @author Vojta
*/
public class NewUzaverkaList extends AbstractForm {
private final int NOTSELECTED = -1;
UzaverkaController kontroler;
int vybranaUzaverkaId;
MainFrame parent;
/** Creates new form NewUzaverkaList */
public NewUzaverkaList(JFrame parent, User loggedUser) {
try {
initComponents();
initTable();
LocalizationManager manager = LocalizationManager.getInstance();
manager.localizeButton(StorageController.DEFAULT_BUNDLE_BASE_NAME, "ShowBalancingButton", zobrazDetail);
manager.localizeButton(StorageController.DEFAULT_BUNDLE_BASE_NAME, "NewBalancingButton", novaUzaverka);
manager.localizeButton(StorageController.DEFAULT_BUNDLE_BASE_NAME, "ContinueInBalancingButton", pokracovatUzaverku);
kontroler = UzaverkaController.getInstance();
kontroler.initByUzaverkaList(loggedUser);
refresh();
table.getSelectionModel().addListSelectionListener(new UzaverkaSelectionListener());
this.parent = (MainFrame) parent;
} catch (FileNotFoundException ex) {
Logger.getLogger(NewUzaverkaList.class.getName()).log(Level.SEVERE, null, ex);
} catch (NotBoundException ex) {
Logger.getLogger(NewUzaverkaList.class.getName()).log(Level.SEVERE, null, ex);
} catch (RemoteException ex) {
Logger.getLogger(NewUzaverkaList.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void zobrazNebylaVybranaUzaverkaException() {
JOptionPane.showMessageDialog(parent, "Nebyla vybrána žádná uzávěrka.", "Chyba", JOptionPane.ERROR_MESSAGE);
}
public void zobrazException(Exception ex) {
JOptionPane.showMessageDialog(parent, ex.getMessage(), "Chyba", JOptionPane.ERROR_MESSAGE);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
scrollPaneForTable = new javax.swing.JScrollPane();
table = new javax.swing.JTable();
zobrazDetail = new javax.swing.JButton();
novaUzaverka = new javax.swing.JButton();
pokracovatUzaverku = new javax.swing.JButton();
setPreferredSize(new java.awt.Dimension(580, 353));
table.setColumnSelectionAllowed(true);
table.getTableHeader().setReorderingAllowed(false);
scrollPaneForTable.setViewportView(table);
table.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
zobrazDetail.setText("Zobrazit uzávěrku");
zobrazDetail.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
zobrazDetailActionPerformed(evt);
}
});
novaUzaverka.setText("Nová uzávěrka");
novaUzaverka.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
novaUzaverkaActionPerformed(evt);
}
});
pokracovatUzaverku.setText("Pokračovat v uzávěrce");
pokracovatUzaverku.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
pokracovatUzaverkuActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(zobrazDetail)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(novaUzaverka)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(pokracovatUzaverku)
.addContainerGap(191, Short.MAX_VALUE))
.addComponent(scrollPaneForTable, javax.swing.GroupLayout.DEFAULT_SIZE, 580, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(scrollPaneForTable, javax.swing.GroupLayout.DEFAULT_SIZE, 313, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(zobrazDetail)
.addComponent(novaUzaverka)
.addComponent(pokracovatUzaverku))
.addContainerGap())
);
}// </editor-fold>//GEN-END:initComponents
private void zobrazDetailActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_zobrazDetailActionPerformed
try {
if (vybranaUzaverkaId == NOTSELECTED) {
zobrazNebylaVybranaUzaverkaException();
return;
}
StatistikaDialog sd = new StatistikaDialog(parent, true, kontroler.getStatistikaFromUzaverka(vybranaUzaverkaId));
sd.setVisible(true);
} catch (RemoteException ex) {
Logger.getLogger(NewUzaverkaList.class.getName()).log(Level.SEVERE, null, ex);
} catch (FileNotFoundException ex) {
Logger.getLogger(NewUzaverkaList.class.getName()).log(Level.SEVERE, null, ex);
} catch (NotBoundException ex) {
Logger.getLogger(NewUzaverkaList.class.getName()).log(Level.SEVERE, null, ex);
}
}//GEN-LAST:event_zobrazDetailActionPerformed
private void novaUzaverkaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_novaUzaverkaActionPerformed
try {
kontroler.zalozNovouUzaverku();
zobrazUzaverkaForm();
} catch (FileNotFoundException ex) {
Logger.getLogger(NewUzaverkaList.class.getName()).log(Level.SEVERE, null, ex);
} catch (NotBoundException ex) {
Logger.getLogger(NewUzaverkaList.class.getName()).log(Level.SEVERE, null, ex);
} catch (RemoteException ex) {
Logger.getLogger(NewUzaverkaList.class.getName()).log(Level.SEVERE, null, ex);
}
}//GEN-LAST:event_novaUzaverkaActionPerformed
private void pokracovatUzaverkuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pokracovatUzaverkuActionPerformed
try {
if (vybranaUzaverkaId == NOTSELECTED) {
zobrazNebylaVybranaUzaverkaException();
return;
}
kontroler.nactiUzaverku(vybranaUzaverkaId);
zobrazUzaverkaForm();
} catch (ValidateInputException ex) {
zobrazException(ex);
} catch (FileNotFoundException ex) {
Logger.getLogger(NewUzaverkaList.class.getName()).log(Level.SEVERE, null, ex);
} catch (RemoteException ex) {
Logger.getLogger(NewUzaverkaList.class.getName()).log(Level.SEVERE, null, ex);
} catch (NotBoundException ex) {
Logger.getLogger(NewUzaverkaList.class.getName()).log(Level.SEVERE, null, ex);
}
}//GEN-LAST:event_pokracovatUzaverkuActionPerformed
public void zobrazUzaverkaForm() throws FileNotFoundException, RemoteException, NotBoundException {
NewUzaverkaForm nuf = new NewUzaverkaForm(parent);
nuf.refresh();
parent.addPanel(nuf);
}
@Override
protected final void refresh() throws FileNotFoundException, NotBoundException, RemoteException {
table.setModel(kontroler.nactiUzaverky());
vybranaUzaverkaId = NOTSELECTED;
}
@Override
protected int isValidInput() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
protected final void initTable() {
table.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
table.setRowSelectionAllowed(true);
table.setColumnSelectionAllowed(false);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
}
@Override
protected void refreshTable() throws FileNotFoundException, NotBoundException, RemoteException {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
protected void clearFields() {
throw new UnsupportedOperationException("Not supported yet.");
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton novaUzaverka;
private javax.swing.JButton pokracovatUzaverku;
private javax.swing.JScrollPane scrollPaneForTable;
private javax.swing.JTable table;
private javax.swing.JButton zobrazDetail;
// End of variables declaration//GEN-END:variables
class UzaverkaSelectionListener implements ListSelectionListener {
public void valueChanged(ListSelectionEvent e) {
int vybranyRadek = table.getSelectedRow();
vybranaUzaverkaId = Integer.parseInt(table.getValueAt(vybranyRadek, 0).toString());
}
}
}