/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Views;
import Helpers.BookTableModel;
import Models.BookModel;
import Models.Pojo.Book;
import java.util.List;
/**
*
* @author Tejas
*/
public class panelSearchBook extends javax.swing.JPanel {
/**
* Creates new form panelSearchBook
*/
public panelSearchBook() {
initComponents();
}
private void fillTable(String type , String name){
BookModel bookModel = new BookModel();
List<Book> books = null;
switch (type) {
case "whereName":
books = bookModel.whereName(name);
break;
case "all":
books = bookModel.all();
break;
default: ;
}
BookTableModel bookTableModel = new BookTableModel(books);
tblBooks.setModel(bookTableModel);
}
/**
* 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() {
lblBook = new javax.swing.JLabel();
txtBook = new javax.swing.JTextField();
jScrollPane1 = new javax.swing.JScrollPane();
tblBooks = new javax.swing.JTable();
btnSearch = new javax.swing.JButton();
btnShowAll = new javax.swing.JButton();
lblBook.setFont(new java.awt.Font("Verdana", 0, 12)); // NOI18N
lblBook.setText("Search Book");
txtBook.setFont(new java.awt.Font("Verdana", 0, 12)); // NOI18N
tblBooks.setFont(new java.awt.Font("Verdana", 0, 12)); // NOI18N
tblBooks.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
tblBooks.setRowHeight(20);
jScrollPane1.setViewportView(tblBooks);
btnSearch.setFont(new java.awt.Font("Verdana", 0, 12)); // NOI18N
btnSearch.setText("Search");
btnSearch.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSearchActionPerformed(evt);
}
});
btnShowAll.setFont(new java.awt.Font("Verdana", 0, 12)); // NOI18N
btnShowAll.setText("Show All");
btnShowAll.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnShowAllActionPerformed(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(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 638, Short.MAX_VALUE)
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addGap(82, 82, 82)
.addComponent(lblBook)
.addGap(58, 58, 58)
.addComponent(txtBook, javax.swing.GroupLayout.PREFERRED_SIZE, 211, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(btnSearch)
.addGap(29, 29, 29)
.addComponent(btnShowAll)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(69, 69, 69)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblBook)
.addComponent(txtBook, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnSearch)
.addComponent(btnShowAll))
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 351, Short.MAX_VALUE)
.addContainerGap())
);
}// </editor-fold>//GEN-END:initComponents
private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchActionPerformed
String book_name = txtBook.getText();
if(book_name.length() != 0 ){
fillTable("whereName", book_name);
}
}//GEN-LAST:event_btnSearchActionPerformed
private void btnShowAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnShowAllActionPerformed
fillTable("all", null);
}//GEN-LAST:event_btnShowAllActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnSearch;
private javax.swing.JButton btnShowAll;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JLabel lblBook;
private javax.swing.JTable tblBooks;
private javax.swing.JTextField txtBook;
// End of variables declaration//GEN-END:variables
}