/** Do lost focus table */ private void tableFocus() { // Set disable action button view.getBtnEdit().setEnabled(false); view.getBtnView().setEnabled(false); view.getBtnDelete().setEnabled(false); view.getTblEmp().setFocusable(false); }
/** initialize the controller. */ private void initComponent() { // Set default page page = 1; totalRow = 1; // Set selection mode view.getTblEmp().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // Add model to table view.getTblEmp().setModel(empModel); // Set model empModel.addColumn(Messages.getString("EmployeeController.19")); // $NON-NLS-1$ empModel.addColumn(Messages.getString("EmployeeController.20")); // $NON-NLS-1$ empModel.addColumn(Messages.getString("EmployeeController.21")); // $NON-NLS-1$ empModel.addColumn(Messages.getString("EmployeeController.22")); // $NON-NLS-1$ empModel.addColumn(Messages.getString("EmployeeController.23")); // $NON-NLS-1$ empModel.addColumn(Messages.getString("EmployeeController.24")); // $NON-NLS-1$ // Add event to employee table view.getTblEmp() .addFocusListener( new FocusAdapter() { @Override public void focusLost(java.awt.event.FocusEvent evt) { tableFocus(); } }); view.getTblEmp() .addMouseListener( new MouseAdapter() { @Override public void mouseClicked(java.awt.event.MouseEvent evt) { if (evt.getButton() == MouseEvent.BUTTON1) { // Set enable action button view.getBtnEdit().setEnabled(true); view.getBtnView().setEnabled(true); view.getBtnDelete().setEnabled(true); // If double click display edit employee dialog if (evt.getClickCount() == 2) { viewEmp(); } } } }); // Add event to add employee btn view.getBtnAdd() .addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { tableFocus(); addEmp(); } }); // Add event click search employee view.getBtnSearch() .addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { tableFocus(); page = 1; searchEmp(); } }); // Add event view button view.getBtnView() .addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { viewEmp(); } }); // Add event edit btn view.getBtnEdit() .addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { tableFocus(); editEmp(); } }); // Add event delete btn view.getBtnDelete() .addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { deleteEmp(); } }); // Add event enter key view.getTxtEmpID() .addKeyListener( new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { searchEmp(); } } }); view.getTxtEmpName() .addKeyListener( new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { searchEmp(); } } }); // Add event navigation btn view.getBtnNext() .addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (page == LibUtil.getInstance().getPage(totalRow) || LibUtil.getInstance().getPage(totalRow) == 0) { return; } else { page++; searchEmp(); } } }); view.getBtnBack() .addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (page != 1 && LibUtil.getInstance().getPage(totalRow) != 0) { page--; } searchEmp(); } }); view.getBtnFirst() .addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { page = 1; searchEmp(); } }); view.getBtnLast() .addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { page = LibUtil.getInstance().getPage(totalRow); searchEmp(); } }); }