/** Method add employee on database */ private void addEmp() { parent.doBlur(); // Display Add employee dialog addEmp = new AddEmployeeController(new AddEmployeeDialog(parent.getView())); addEmp.getView().setVisible(true); // invoked method add employee if (addEmp.getEmp() != null) { if (AccessEmp.getInstance().addEmp(addEmp.getEmp())) { JOptionPane.showMessageDialog( view, Messages.getString("EmployeeController.0"), // $NON-NLS-1$ Messages.getString("EmployeeController.1"), JOptionPane.INFORMATION_MESSAGE); // Move last page and show newest employee view.getTxtEmpID().setText(Messages.getString("EmptyText")); // $NON-NLS-1$ view.getTxtEmpName().setText(Messages.getString("EmptyText")); // $NON-NLS-1$ view.getBtnLast().doClick(); } else { JOptionPane.showMessageDialog( view, Messages.getString("EmployeeController.4") // $NON-NLS-1$ + Messages.getString("EmployeeController.5"), Messages.getString("EmployeeController.6"), // $NON-NLS-1$ JOptionPane.ERROR_MESSAGE); } } parent.doBlur(); // Set selection to new employee view.getTblEmp().changeSelection(view.getTblEmp().getRowCount() - 1, 0, false, 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(); } }); }