/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* restaurantsJFrame.java
*
* Created on 14.06.2009, 17:04:25
*/
package restaurantadministration.view;
import restaurantadministration.DBConnection.MyDBConnection;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ComboBoxModel;
import restaurantadministration.models.RestaurantTableModel;
import restaurantadministration.models.comboModel;
import restaurantadministration.models.sqlModels;
/**
*
* @author Christoph
*/
public class restaurantsJFrame extends javax.swing.JFrame {
private MyDBConnection mdbc = null;
private java.sql.Statement stmt = null;
ResultSet rs = null;
ResultSet rs2 = null;
comboModel cm = null;
sqlModels getAll = new sqlModels();
sqlModels getLocation = new sqlModels();
/** Creates new form restaurantsJFrame */
public restaurantsJFrame() throws SQLException {
try {
javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
mdbc = new MyDBConnection();
mdbc.init();
} catch (Exception e) {
e.printStackTrace();
}
initComponents();
rs = getAll.getAllRestaurants();
//rs2 = getLocation.sortByLocation(searchID);
restaurantTable.setModel(new RestaurantTableModel(rs));
//searchLocation.setModel((ComboBoxModel) (new comboModel (rs1)));
}
//public ResultSet getLocation () {
//}
/** 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">
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
restaurantTable = new javax.swing.JTable();
jPanel1 = new javax.swing.JPanel();
refreshButtonLabel = new javax.swing.JLabel();
javax.swing.JButton refreshButton = new javax.swing.JButton();
detailInformation1 = new javax.swing.JLabel();
details1 = new javax.swing.JButton();
detailInformation = new javax.swing.JLabel();
details = new javax.swing.JButton();
textfeld1 = new javax.swing.JTextField();
jPanel2 = new javax.swing.JPanel();
searchLocation = new javax.swing.JComboBox();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Restaurants");
setName("mainFrame"); // NOI18N
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosed(java.awt.event.WindowEvent evt) {
formWindowClosed(evt);
}
public void windowClosing(java.awt.event.WindowEvent evt) {
formWindowClosing(evt);
}
});
getContentPane().setLayout(new java.awt.BorderLayout(500, 0));
restaurantTable.setAutoCreateRowSorter(true);
restaurantTable.setModel(new RestaurantTableModel (rs));
restaurantTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
restaurantTable.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
restaurantTableMouseClicked(evt);
}
});
jScrollPane1.setViewportView(restaurantTable);
jScrollPane1.repaint();
jScrollPane1.revalidate();
getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
jPanel1.setLayout(new java.awt.GridLayout(4, 2, 15, 10));
refreshButtonLabel.setText(" Akutalisieren");
jPanel1.add(refreshButtonLabel);
refreshButton.setText("Aktualisieren / Alle anzeigen");
refreshButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
refreshButtonActionPerformed(evt);
}
});
jPanel1.add(refreshButton);
detailInformation1.setText(" Neues Lokal hinzufügen");
jPanel1.add(detailInformation1);
details1.setText("Neus Lokal hinzufügen");
details1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
details1ActionPerformed(evt);
}
});
jPanel1.add(details1);
detailInformation.setText(" Detailansicht");
jPanel1.add(detailInformation);
details.setText("Details");
details.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
detailsActionPerformed(evt);
}
});
jPanel1.add(details);
jPanel1.add(textfeld1);
getContentPane().add(jPanel1, java.awt.BorderLayout.PAGE_END);
jPanel2.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT, 5, 15));
mdbc.init();
Connection con = mdbc.getMyConnection();
try {
stmt = con.createStatement();
} catch (SQLException ex) {
Logger.getLogger(restaurantsJFrame.class.getName()).log(Level.SEVERE, null, ex);
}
searchLocation.setToolTipText("");
searchLocation.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
searchLocationActionPerformed(evt);
}
});
try {
rs2 = stmt.executeQuery("SELECT * FROM locations order by location");
while (rs2.next()) {
searchLocation.addItem(new comboModel(rs2.getInt(1), rs2.getString(2)));
}
rs2.close();
} catch (SQLException ex) {
Logger.getLogger(restaurantsJFrame.class.getName()).log(Level.SEVERE, null, ex);
}
jPanel2.add(searchLocation);
jButton1.setText("Nach diesem Ort suchen");
jButton1.setAlignmentX(0.5F);
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jPanel2.add(jButton1);
getContentPane().add(jPanel2, java.awt.BorderLayout.PAGE_START);
pack();
}// </editor-fold>
private void detailsActionPerformed(java.awt.event.ActionEvent evt) {
administrationJFrame af;
try {
af = new administrationJFrame();
af.setVisible(true);
} catch (SQLException ex) {
Logger.getLogger(restaurantsJFrame.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void formWindowClosed(java.awt.event.WindowEvent evt) {
//mdbc.close(stmt);
//mdbc.destroy();
}
private void formWindowClosing(java.awt.event.WindowEvent evt) {
mdbc.close(stmt);
mdbc.destroy();
}
private void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) {
rs = getAll.getAllRestaurants();
restaurantTable.setModel(new RestaurantTableModel(rs));
restaurantTable.updateUI();
restaurantTable.repaint();
restaurantTable.revalidate();
}
private void details1ActionPerformed(java.awt.event.ActionEvent evt) {
addRestaurantJFrame ar = new addRestaurantJFrame();
ar.setVisible(true);
}
private void restaurantTableMouseClicked(java.awt.event.MouseEvent evt) {
System.out.println("Click erkannt");
int row = restaurantTable.getSelectedRow();
System.out.println (row);
if (row > -1) {
textfeld1.setText(String.valueOf(restaurantTable.getValueAt(row, 1)));
}
}
private void searchLocationActionPerformed(java.awt.event.ActionEvent evt) {
//initComponents();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
comboModel getID = (comboModel) searchLocation.getSelectedItem();
int searchID = getID.getID();
rs2 = getLocation.sortByLocation(searchID);
System.out.println (searchID);
restaurantTable.setModel(new RestaurantTableModel(rs2));
restaurantTable.updateUI();
restaurantTable.repaint();
restaurantTable.revalidate();
}
//private int getLokal () {
//}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
try {
new restaurantsJFrame().setVisible(true);
} catch (SQLException ex) {
Logger.getLogger(restaurantsJFrame.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
}
// Variables declaration - do not modify
private javax.swing.JLabel detailInformation;
private javax.swing.JLabel detailInformation1;
private javax.swing.JButton details;
private javax.swing.JButton details1;
private javax.swing.JButton jButton1;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JLabel refreshButtonLabel;
public javax.swing.JTable restaurantTable;
private javax.swing.JComboBox searchLocation;
private javax.swing.JTextField textfeld1;
// End of variables declaration
}