Guest User

Untitled

a guest
Nov 9th, 2013
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.16 KB | None | 0 0
  1. public class MainScreen extends javax.swing.JFrame {
  2.  
  3. private TableRowSorter<TableModel> sorter;
  4.  
  5. public MainScreen() {
  6. initComponents();
  7. this.setSize(java.awt.Toolkit.getDefaultToolkit().getScreenSize());
  8.  
  9. sorter = new TableRowSorter<>(tblCustomer.getModel());
  10. tblCustomer.setRowSorter(sorter);
  11. List<BasicDetailsDTO> findAll = UtilDAO.getDaoBasicDetails().findAll();
  12. System.out.println("I'm here "+findAll.size());
  13.  
  14.  
  15. ((DefaultTableModel) tblCustomer.getModel()).setDataVector(getDataVector(findAll), getVectorHeader());
  16. tblCustomer.setAutoCreateRowSorter(true);
  17. tblCustomer.getColumnModel().getColumn(0).setMinWidth(0);
  18. tblCustomer.getColumnModel().getColumn(0).setMaxWidth(0);
  19.  
  20. }
  21.  
  22. public static Vector getDataVector(List<BasicDetailsDTO> listData) {
  23. Vector dataVector = new Vector();
  24. for (BasicDetailsDTO instance : listData) {
  25. Vector row = new Vector();
  26. row.add(instance.getId());
  27. row.add(instance.getParticulars());
  28. row.add(instance.getBookedBy());
  29. row.add(instance.getContactPerson());
  30. row.add(instance.getMobileNo());
  31. row.add(instance.getEmail_id());
  32. dataVector.add(row);
  33.  
  34. }
  35. return dataVector;
  36.  
  37. }
  38.  
  39. public static Vector getVectorHeader() {
  40.  
  41. Vector header = new Vector();
  42. header.add("ID");
  43. header.add("Particulars");
  44. header.add("BOOKED BY");
  45. header.add("CONTACT PERSON");
  46. header.add("MOBILE NO");
  47. header.add("EMAIL ID");
  48. return header;
  49.  
  50. }
  51.  
  52. private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {
  53. // TODO add your handling code here:
  54.  
  55. displayPanel(new HomePage(), "Details Of Customer", 1200, 800);
  56. }
  57.  
  58. private void tblCustomerKeyPressed(java.awt.event.KeyEvent evt) {
  59. // TODO add your handling code here:
  60. }
  61.  
  62. private void tblCustomerMousePressed(java.awt.event.MouseEvent evt) {
  63. // TODO add your handling code here:
  64. }
  65.  
  66. private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {
  67. // TODO add your handling code here:
  68.  
  69. if (tblCustomer.getSelectedRow() == -1) {
  70. displayError("Please Select the Record");
  71. return;
  72. }
  73.  
  74. int option = displayConfirmDialog("Do you Really want to delete Record ?");
  75. if (option == JOptionPane.YES_OPTION) {
  76. String recordId = tblCustomer.getValueAt(tblCustomer.getSelectedRow(), 0).toString();
  77. BasicDetailsDTO instance = UtilDAO.getDaoBasicDetails().findById(Integer.parseInt(recordId));
  78.  
  79. instance.setDeleted(Boolean.TRUE);
  80. UtilDAO.getDaoBasicDetails().remove(instance);
  81.  
  82. List<BasicDetailsDTO> findAll = UtilDAO.getDaoBasicDetails().findAll();
  83. getDataVector(findAll);
  84.  
  85. displayMessage(" Record Deleted ");
  86. }
  87.  
  88. }
  89.  
  90. private void btnEditActionPerformed(java.awt.event.ActionEvent evt) {
  91. // TODO add your handling code here:
  92.  
  93. if (tblCustomer.getSelectedRow() == -1) {
  94. displayError("Please select record.");
  95. return;
  96. }
  97. String recordID = tblCustomer.getValueAt(tblCustomer.getSelectedRow(), 0).toString();
  98. BasicDetailsDTO instance = UtilDAO.getDaoBasicDetails().findById(Integer.parseInt(recordID));
  99.  
  100. displayPanel(new HomePage(instance, 1), "Customer " + instance.getBillingName(), 1200, 1000);
  101.  
  102.  
  103.  
  104. }
  105.  
  106. private void tblCustomerMouseClicked(java.awt.event.MouseEvent evt) {
  107. // TODO add your handling code here:
  108.  
  109. if (evt.getClickCount() == 2) {
  110. String recordID = tblCustomer.getValueAt(tblCustomer.getSelectedRow(), 0).toString();
  111. BasicDetailsDTO instance = UtilDAO.getDaoBasicDetails().findById(Integer.parseInt(recordID));
  112.  
  113. displayPanel(new HomePage(instance, 1), "Customer " + instance.getBillingName(), 1000, 1000);
  114. }
  115. }
  116.  
  117. private void btnViewHotelListActionPerformed(java.awt.event.ActionEvent evt) {
  118. // TODO add your handling code here:
  119.  
  120. displayPanel(new ViewHotelDetails(), "List Of Hotels", 800, 700);
  121. }
  122.  
  123. private void btnViewAgencyListActionPerformed(java.awt.event.ActionEvent evt) {
  124. // TODO add your handling code here:
  125.  
  126. displayPanel(new ViewAgencyDetails(), "List Of Hotels", 800, 700);
  127. }
  128.  
  129. private void txtSearchKeyReleased(java.awt.event.KeyEvent evt) {
  130. // TODO add your handling code here:
  131. if (evt.getKeyCode() != KeyEvent.VK_ENTER && evt.getKeyCode() != KeyEvent.VK_DOWN) {
  132. if (txtSearch.getText().trim().length() > 0) {
  133. RowFilter<TableModel, Object> filter = new RowFilter<TableModel, Object>() {
  134. @Override
  135. public boolean include(javax.swing.RowFilter.Entry<? extends TableModel, ? extends Object> entry) {
  136. String search = txtSearch.getText().trim().toLowerCase();
  137. // System.out.println(entry.getStringValue(1));
  138. return (entry.getValue(1).toString().toLowerCase().indexOf(search) != -1 || entry.getValue(2).toString().toLowerCase().indexOf(search) != -1 || entry.getValue(3).toString().toLowerCase().indexOf(search) != -1);
  139. }
  140. };
  141. sorter.setRowFilter(filter);
  142. //sorter.setRowFilter(null);
  143. tblCustomer.setRowSorter(sorter);
  144. // System.out.println("New Row is " + filter);
  145. } else {
  146. sorter.setRowFilter(null);
  147. tblCustomer.setRowSorter(sorter);
  148. }
  149. } else {
  150. if (tblCustomer.getRowCount() > 0) {
  151. tblCustomer.requestFocus();
  152. tblCustomer.setRowSelectionInterval(0, 0);
  153. } else {
  154. txtSearch.requestFocus();
  155. }
  156.  
  157. }
  158. }
  159.  
  160. private void btnInvoiceActionPerformed(java.awt.event.ActionEvent evt) {
  161. // TODO add your handling code here:
  162. try {
  163. InputStream in = MainScreen.class.getResourceAsStream("Passenger_Name.docx");
  164. IXDocReport report = XDocReportRegistry.getRegistry().loadReport(in, TemplateEngineKind.Velocity);
  165.  
  166. IContext context = report.createContext();
  167. if (tblCustomer.getSelectedRow() == -1) {
  168. displayError("Please select record.");
  169. return;
  170. }
  171. String recordID = tblCustomer.getValueAt(tblCustomer.getSelectedRow(), 0).toString();
  172. BasicDetailsDTO instance = UtilDAO.getDaoBasicDetails().findById(Integer.parseInt(recordID));
  173. context.put("Customer", instance);
  174.  
  175.  
  176.  
  177. OutputStream out = new FileOutputStream(new File("Passenger Name_Out.docx"));
  178. report.process(context, out);
  179. Desktop desktop = Desktop.getDesktop();
  180. File f = new File("Passenger Name_Out.docx");
  181. desktop.open(f);
  182.  
  183.  
  184. } catch (IOException | XDocReportException ex) {
  185. Logger.getLogger(MainScreen.class.getName()).log(Level.SEVERE, null, ex);
  186. }
  187.  
  188. }
  189.  
  190. /**
  191. * @param args the command line arguments
  192. */
  193. public static void main(String args[]) {
  194. try {
  195. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  196. if ("Nimbus".equals(info.getName())) {
  197. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  198. break;
  199. }
  200. }
  201. } catch (ClassNotFoundException ex) {
  202. java.util.logging.Logger.getLogger(MainScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  203. } catch (InstantiationException ex) {
  204. java.util.logging.Logger.getLogger(MainScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  205. } catch (IllegalAccessException ex) {
  206. java.util.logging.Logger.getLogger(MainScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  207. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  208. java.util.logging.Logger.getLogger(MainScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  209. }
  210. //</editor-fold>
  211.  
  212. /* Create and display the form */
  213. java.awt.EventQueue.invokeLater(new Runnable() {
  214. public void run() {
  215. try {
  216.  
  217. UIManager.setLookAndFeel("com.jtattoo.plaf.texture.TextureLookAndFeel");
  218. } catch (ClassNotFoundException ex) {
  219. Logger.getLogger(MainScreen.class.getName()).log(Level.SEVERE, null, ex);
  220. } catch (InstantiationException ex) {
  221. Logger.getLogger(MainScreen.class.getName()).log(Level.SEVERE, null, ex);
  222. } catch (IllegalAccessException ex) {
  223. Logger.getLogger(MainScreen.class.getName()).log(Level.SEVERE, null, ex);
  224. } catch (UnsupportedLookAndFeelException ex) {
  225. Logger.getLogger(MainScreen.class.getName()).log(Level.SEVERE, null, ex);
  226. }
  227. new MainScreen().setVisible(true);
  228. }
  229. });
  230.  
  231. }
  232.  
  233. public static void setlblMessageDetail(String msg) {
  234.  
  235. MainScreen.lblMessage.setHorizontalAlignment(JLabel.CENTER);
  236. MainScreen.lblMessage.setText(msg);
  237. }
  238. // Variables declaration - do not modify
  239. }
Advertisement
Add Comment
Please, Sign In to add comment