/** * Checks if the specified {@link Operation} has been modified. * * @param operation - the {@link Operation} to check. * @return <code>true</code> if has been modified, <code>false</code> otherwise. * @throws OHException if an error occurs during the check. */ public boolean hasOperationModified(Operation operation) throws OHException { DbQueryLogger dbQuery = new DbQueryLogger(); boolean result = false; // we establish if someone else has updated/deleted the record since the last read String query = "SELECT OPE_LOCK FROM OPERATION WHERE OPE_ID_A = ?"; List<Object> parameters = Collections.<Object>singletonList(operation.getCode()); try { // we use manual commit of the transaction ResultSet resultSet = dbQuery.getDataWithParams(query, parameters, true); if (resultSet.first()) { // ok the record is present, it was not deleted result = resultSet.getInt("OPE_LOCK") != operation.getLock(); } else { throw new OHException( MessageBundle.getMessage("angal.sql.couldntfindthedataithasprobablybeendeleted")); } } catch (SQLException e) { throw new OHException( MessageBundle.getMessage("angal.sql.problemsoccurredwiththesqlistruction"), e); } finally { dbQuery.releaseConnection(); } return result; }
/** * This method initializes this * * @return void */ private void initialize() { this.setBounds(300, 300, 350, 180); this.setContentPane(getJContentPane()); if (insert) { this.setTitle(MessageBundle.getMessage("angal.distype.newdiseasetyperecord")); } else { this.setTitle(MessageBundle.getMessage("angal.distype.editingdiseasetyperecord")); } this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); }
/** * This method initializes this * * @return void */ private void initialize() { this.setBounds(300, 300, 350, 180); this.setContentPane(getJContentPane()); if (insert) { this.setTitle(MessageBundle.getMessage("angal.exatype.newexamtype") + " (" + VERSION + ")"); } else { this.setTitle(MessageBundle.getMessage("angal.exatype.editexamtype") + " (" + VERSION + ")"); } this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); }
/** * This method initializes jCodeLabel * * @return javax.swing.JLabel */ private JLabel getJCodeLabel() { if (jCodeLabel == null) { jCodeLabel = new JLabel(); jCodeLabel.setText(MessageBundle.getMessage("angal.distype.codemaxchars")); } return jCodeLabel; }
private JComboBox getPrintTypeComboBox() { if (printTypeComboBox == null) { printTypeComboBox = new JComboBox(); printTypeComboBox.addItem(MessageBundle.getMessage("angal.lab.openwithjasperReport")); printTypeComboBox.addItem(MessageBundle.getMessage("angal.lab.exporttopdffile")); printTypeComboBox.addItem(MessageBundle.getMessage("angal.lab.printreport")); printTypeComboBox.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { printTypeSelected = printTypeComboBox.getSelectedIndex(); } }); } return printTypeComboBox; }
/** * This method initializes jDescriptionLabelPanel * * @return javax.swing.JPanel */ private JPanel getJDescriptionLabelPanel() { if (jDescriptionLabelPanel == null) { jDescripitonLabel = new JLabel(); jDescripitonLabel.setText(MessageBundle.getMessage("angal.distype.description")); jDescriptionLabelPanel = new JPanel(); jDescriptionLabelPanel.add(jDescripitonLabel, null); } return jDescriptionLabelPanel; }
private JButton getCloseButton() { if (closeButton == null) { closeButton = new JButton(MessageBundle.getMessage("angal.common.close")); closeButton.setMnemonic(KeyEvent.VK_C); closeButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { dispose(); } }); } return closeButton; }
/** * This method initializes cancelButton * * @return javax.swing.JButton */ private JButton getCancelButton() { if (cancelButton == null) { cancelButton = new JButton(); cancelButton.setMnemonic(KeyEvent.VK_C); cancelButton.setText(MessageBundle.getMessage("angal.common.cancel")); // Generated cancelButton.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { dispose(); } }); } return cancelButton; }
private void initialize() { Toolkit kit = Toolkit.getDefaultToolkit(); Dimension screensize = kit.getScreenSize(); final int pfrmBase = 20; final int pfrmWidth = 5; final int pfrmHeight = 4; setBounds( (screensize.width - screensize.width * pfrmWidth / pfrmBase) / 2, (screensize.height - screensize.height * pfrmHeight / pfrmBase) / 2, screensize.width * pfrmWidth / pfrmBase, screensize.height * pfrmHeight / pfrmBase); setContentPane(getJContentPanel()); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setTitle(MessageBundle.getMessage("angal.lab.laboratoryprinting")); }
private JButton getOkButton() { if (okButton == null) { okButton = new JButton(MessageBundle.getMessage("angal.common.ok")); okButton.setMnemonic(KeyEvent.VK_O); okButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { new PrintManager("Laboratory", labList, printTypeSelected); dispose(); } }); } return okButton; }
/** * checks if an {@link Operation} code has already been used * * @param code - the code * @return <code>true</code> if the code is already in use, <code>false</code> otherwise. * @throws OHException */ public boolean isCodePresent(String code) throws OHException { DbQueryLogger dbQuery = new DbQueryLogger(); boolean present = false; try { String sqlstring = "SELECT OPE_ID_A FROM OPERATION WHERE OPE_ID_A = ? "; List<Object> parameters = Collections.<Object>singletonList(code); ResultSet set = dbQuery.getDataWithParams(sqlstring, parameters, true); if (set.first()) present = true; } catch (SQLException e) { throw new OHException( MessageBundle.getMessage("angal.sql.problemsoccurredwiththesqlistruction"), e); } finally { dbQuery.releaseConnection(); } return present; }
/** * checks if an {@link Operation} description has already been used within the specified {@link * OperationType} * * @param description - the {@link Operation} description * @param typeCode - the {@link OperationType} code * @return <code>true</code> if the description is already in use, <code>false</code> otherwise. * @throws OHException */ public boolean isDescriptionPresent(String description, String typeCode) throws OHException { DbQueryLogger dbQuery = new DbQueryLogger(); boolean present = false; try { String sqlstring = "SELECT OPE_DESC FROM OPERATION WHERE OPE_DESC = ? AND OPE_OCL_ID_A = ?"; List<Object> parameters = new ArrayList<Object>(); parameters.add(description); parameters.add(typeCode); ResultSet set = dbQuery.getDataWithParams(sqlstring, parameters, true); if (set.first()) present = true; } catch (SQLException e) { throw new OHException( MessageBundle.getMessage("angal.sql.problemsoccurredwiththesqlistruction"), e); } finally { dbQuery.releaseConnection(); } return present; }
/** * return the {@link Operation}s whose type matches specified string * * @param typeDescription - a type description * @return the list of {@link Operation}s. It could be <code>empty</code> or <code>null</code>. * @throws OHException */ public ArrayList<Operation> getOperation(String typeDescription) throws OHException { DbQueryLogger dbQuery = new DbQueryLogger(); ArrayList<Operation> operationList = null; ResultSet resultSet; if (typeDescription == null) { String sqlString = "SELECT * FROM OPERATION JOIN OPERATIONTYPE ON OPE_OCL_ID_A = OCL_ID_A ORDER BY OPE_DESC"; resultSet = dbQuery.getData(sqlString, true); } else { String sqlString = "SELECT * FROM OPERATION JOIN OPERATIONTYPE ON OPE_OCL_ID_A = OCL_ID_A WHERE OCL_DESC LIKE CONCAT('%', ? , '%') ORDER BY OPE_DESC"; List<Object> parameters = Collections.<Object>singletonList(typeDescription); resultSet = dbQuery.getDataWithParams(sqlString, parameters, true); } try { operationList = new ArrayList<Operation>(resultSet.getFetchSize()); while (resultSet.next()) { Operation operation = new Operation( resultSet.getString("OPE_ID_A"), resultSet.getString("OPE_DESC"), new OperationType( resultSet.getString("OPE_OCL_ID_A"), resultSet.getString("OCL_DESC")), resultSet.getInt("OPE_STAT"), resultSet.getInt("OPE_LOCK")); operationList.add(operation); } } catch (SQLException e) { throw new OHException( MessageBundle.getMessage("angal.sql.problemsoccurredwiththesqlistruction"), e); } finally { dbQuery.releaseConnection(); } return operationList; }
public UserBrowsing() { setTitle(MessageBundle.getMessage("angal.menu.usersbrowser")); myFrame = this; // addWindowListener(this); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); Toolkit kit = Toolkit.getDefaultToolkit(); Dimension screensize = kit.getScreenSize(); pfrmWidth = screensize.width / 2 + 100; pfrmHeight = screensize.height / 2; setBounds(screensize.width / 4, screensize.height / 4, pfrmWidth, pfrmHeight); model = new UserBrowserModel(); table = new JTable(model); table.getColumnModel().getColumn(0).setPreferredWidth(pColumwidth[0]); table.getColumnModel().getColumn(1).setPreferredWidth(pColumwidth[1]); table.getColumnModel().getColumn(2).setPreferredWidth(pColumwidth[2]); // table.getColumnModel().getColumn(3).setPreferredWidth(pColumwidth[3]); scrollPane = new JScrollPane(table); add(scrollPane, BorderLayout.CENTER); JPanel buttonPanel = new JPanel(); selectlabel = new JLabel(MessageBundle.getMessage("angal.menu.selectgroup")); buttonPanel.add(selectlabel); pbox = new JComboBox(); pbox.addItem(MessageBundle.getMessage("angal.menu.all")); ArrayList<UserGroup> group = manager.getUserGroup(); for (UserGroup elem : group) { pbox.addItem(elem); } pbox.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { pSelection = pbox.getSelectedItem().toString(); if (pSelection.compareTo("ALL") == 0) model = new UserBrowserModel(); else model = new UserBrowserModel(pSelection); model.fireTableDataChanged(); table.updateUI(); } }); buttonPanel.add(pbox); JButton buttonNew = new JButton(MessageBundle.getMessage("angal.common.new")); buttonNew.setMnemonic(KeyEvent.VK_N); buttonNew.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { user = new User("", "", "", ""); new UserEdit(myFrame, user, true); } }); buttonPanel.add(buttonNew); JButton buttonEdit = new JButton(MessageBundle.getMessage("angal.common.edit")); buttonEdit.setMnemonic(KeyEvent.VK_E); buttonEdit.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { if (table.getSelectedRow() < 0) { JOptionPane.showMessageDialog( null, MessageBundle.getMessage("angal.common.pleaseselectarow"), MessageBundle.getMessage("angal.hospital"), JOptionPane.PLAIN_MESSAGE); return; } else { selectedrow = table.getSelectedRow(); user = (User) (((UserBrowserModel) model).getValueAt(table.getSelectedRow(), -1)); new UserEdit(myFrame, user, false); } } }); buttonPanel.add(buttonEdit); JButton buttonResetPassword = new JButton(MessageBundle.getMessage("angal.menu.resetpassword")); buttonResetPassword.setMnemonic(KeyEvent.VK_R); buttonResetPassword.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { if (table.getSelectedRow() < 0) { JOptionPane.showMessageDialog( null, MessageBundle.getMessage("angal.common.pleaseselectarow"), MessageBundle.getMessage("angal.hospital"), JOptionPane.PLAIN_MESSAGE); return; } else { selectedrow = table.getSelectedRow(); user = (User) (((UserBrowserModel) model).getValueAt(table.getSelectedRow(), -1)); // 1. Insert new password JPasswordField pwd = new JPasswordField(10); pwd.addAncestorListener( new AncestorListener() { public void ancestorRemoved(AncestorEvent event) {} public void ancestorMoved(AncestorEvent event) {} public void ancestorAdded(AncestorEvent event) { event.getComponent().requestFocusInWindow(); } }); String newPassword = ""; while (newPassword.equals("")) { int action = JOptionPane.showConfirmDialog( UserBrowsing.this, pwd, MessageBundle.getMessage( "angal.menu.onepleaseinsertnewpassowrdminsixdigits"), JOptionPane.OK_CANCEL_OPTION); if (action == JOptionPane.CANCEL_OPTION) return; newPassword = new String(pwd.getPassword()); if (newPassword == null || newPassword.equals("") || newPassword.length() < 6) { JOptionPane.showMessageDialog( UserBrowsing.this, MessageBundle.getMessage( "angal.menu.pleaseinsertavalidpasswordminsixdigits")); newPassword = ""; pwd.setText(""); } } // 2. Retype new password pwd.setText(""); int action = JOptionPane.showConfirmDialog( UserBrowsing.this, pwd, MessageBundle.getMessage("angal.menu.twopleaserepeatpassword"), JOptionPane.OK_CANCEL_OPTION); if (action == JOptionPane.CANCEL_OPTION) return; String newPassword2 = new String(pwd.getPassword()); // 3. Check & Save if (!newPassword.equals(newPassword2)) { JOptionPane.showMessageDialog( UserBrowsing.this, MessageBundle.getMessage("angal.menu.retypeerrorpleaseretry")); return; } if (newPassword != null && !newPassword.equals("") && newPassword.length() >= 6) { String hashed = BCrypt.hashpw(new String(newPassword), BCrypt.gensalt()); user.setPasswd(hashed); if (manager.updatePassword(user)) JOptionPane.showMessageDialog( UserBrowsing.this, MessageBundle.getMessage("angal.menu.thepasswordhasbeenchanged")); } else { JOptionPane.showMessageDialog( UserBrowsing.this, MessageBundle.getMessage("angal.menu.pleaseinsertavalidpasswordminsixdigits")); } } } }); buttonPanel.add(buttonResetPassword); JButton buttonDelete = new JButton(MessageBundle.getMessage("angal.common.delete")); buttonDelete.setMnemonic(KeyEvent.VK_D); buttonDelete.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { if (table.getSelectedRow() < 0) { JOptionPane.showMessageDialog( null, MessageBundle.getMessage("angal.common.pleaseselectarow"), MessageBundle.getMessage("angal.hospital"), JOptionPane.PLAIN_MESSAGE); return; } else { UserBrowsingManager manager = new UserBrowsingManager(); User m = (User) (((UserBrowserModel) model).getValueAt(table.getSelectedRow(), -1)); int n = JOptionPane.showConfirmDialog( null, MessageBundle.getMessage("angal.menu.deleteuser") + " \"" + m.getUserName() + "\" ?", MessageBundle.getMessage("angal.hospital"), JOptionPane.YES_NO_OPTION); if ((n == JOptionPane.YES_OPTION) && (manager.deleteUser(m))) { pUser.remove(table.getSelectedRow()); model.fireTableDataChanged(); table.updateUI(); } } } }); buttonPanel.add(buttonDelete); JButton buttonClose = new JButton(MessageBundle.getMessage("angal.common.close")); buttonClose.setMnemonic(KeyEvent.VK_C); buttonClose.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { dispose(); } }); buttonPanel.add(buttonClose); add(buttonPanel, BorderLayout.SOUTH); setVisible(true); }
/** * This method initializes okButton * * @return javax.swing.JButton */ private JButton getOkButton() { if (okButton == null) { okButton = new JButton(); okButton.setText(MessageBundle.getMessage("angal.common.ok")); // Generated okButton.setMnemonic(KeyEvent.VK_O); okButton.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { String key = codeTextField.getText(); DiseaseTypeBrowserManager manager = new DiseaseTypeBrowserManager(); if (key.equals("")) { JOptionPane.showMessageDialog( null, MessageBundle.getMessage("angal.distype.pleaseinsertacode"), MessageBundle.getMessage("angal.hospital"), JOptionPane.PLAIN_MESSAGE); return; } // System.out.print(key.length()); if (key.length() > 2) { JOptionPane.showMessageDialog( null, MessageBundle.getMessage("angal.distype.codetoolongmaxchars"), MessageBundle.getMessage("angal.hospital"), JOptionPane.PLAIN_MESSAGE); return; } if (insert) { if (manager.codeControl(key)) { JOptionPane.showMessageDialog( null, MessageBundle.getMessage("angal.distype.codealreadyinuse"), MessageBundle.getMessage("angal.hospital"), JOptionPane.PLAIN_MESSAGE); codeTextField.setText(""); return; } } ; if (descriptionTextField.getText().equals("")) { JOptionPane.showMessageDialog( null, MessageBundle.getMessage("angal.distype.pleaseinsertavaliddescription"), MessageBundle.getMessage("angal.hospital"), JOptionPane.PLAIN_MESSAGE); return; } if (descriptionTextField.getText().equals(lastdescription)) { dispose(); } diseaseType.setDescription(descriptionTextField.getText()); diseaseType.setCode(codeTextField.getText()); boolean result = false; if (insert) { // inserting result = manager.newDiseaseType(diseaseType); if (result) { fireDiseaseInserted(); } if (!result) JOptionPane.showMessageDialog( null, MessageBundle.getMessage("angal.distype.thedatacouldnotbesaved")); else dispose(); } else { // updating if (descriptionTextField.getText().equals(lastdescription)) { dispose(); } else { result = manager.updateDiseaseType(diseaseType); if (result) { fireDiseaseUpdated(); } if (!result) JOptionPane.showMessageDialog( null, MessageBundle.getMessage("angal.distype.thedatacouldnotbesaved")); else dispose(); } } } }); } return okButton; }
public class ExamTypeEdit extends JDialog { /** */ private static final long serialVersionUID = 1L; private static final String VERSION = MessageBundle.getMessage("angal.versione"); private EventListenerList examTypeListeners = new EventListenerList(); public interface ExamTypeListener extends EventListener { public void examTypeUpdated(AWTEvent e); public void examTypeInserted(AWTEvent e); } public void addExamTypeListener(ExamTypeListener l) { examTypeListeners.add(ExamTypeListener.class, l); } public void removeExamTypeListener(ExamTypeListener listener) { examTypeListeners.remove(ExamTypeListener.class, listener); } private void fireExamInserted() { AWTEvent event = new AWTEvent(new Object(), AWTEvent.RESERVED_ID_MAX + 1) { /** */ private static final long serialVersionUID = 1L; }; EventListener[] listeners = examTypeListeners.getListeners(ExamTypeListener.class); for (int i = 0; i < listeners.length; i++) ((ExamTypeListener) listeners[i]).examTypeInserted(event); } private void fireExamUpdated() { AWTEvent event = new AWTEvent(new Object(), AWTEvent.RESERVED_ID_MAX + 1) { /** */ private static final long serialVersionUID = 1L; }; EventListener[] listeners = examTypeListeners.getListeners(ExamTypeListener.class); for (int i = 0; i < listeners.length; i++) ((ExamTypeListener) listeners[i]).examTypeUpdated(event); } private JPanel jContentPane = null; private JPanel dataPanel = null; private JPanel buttonPanel = null; private JButton cancelButton = null; private JButton okButton = null; private JTextField descriptionTextField = null; private VoLimitedTextField codeTextField = null; private String lastdescription; private ExamType examType = null; private boolean insert; private JPanel jDataPanel = null; private JLabel jCodeLabel = null; private JPanel jCodeLabelPanel = null; private JPanel jDescriptionLabelPanel = null; private JLabel jDescripitonLabel = null; /** * This is the default constructor; we pass the arraylist and the selectedrow because we need to * update them */ public ExamTypeEdit(JFrame owner, ExamType old, boolean inserting) { super(owner, true); insert = inserting; examType = old; // disease will be used for every operation lastdescription = examType.getDescription(); initialize(); } /** * This method initializes this * * @return void */ private void initialize() { this.setBounds(300, 300, 350, 180); this.setContentPane(getJContentPane()); if (insert) { this.setTitle(MessageBundle.getMessage("angal.exatype.newexamtype") + " (" + VERSION + ")"); } else { this.setTitle(MessageBundle.getMessage("angal.exatype.editexamtype") + " (" + VERSION + ")"); } this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); } /** * This method initializes jContentPane * * @return javax.swing.JPanel */ private JPanel getJContentPane() { if (jContentPane == null) { jContentPane = new JPanel(); jContentPane.setLayout(new BorderLayout()); jContentPane.add(getDataPanel(), java.awt.BorderLayout.NORTH); // Generated jContentPane.add(getButtonPanel(), java.awt.BorderLayout.SOUTH); // Generated } return jContentPane; } /** * This method initializes dataPanel * * @return javax.swing.JPanel */ private JPanel getDataPanel() { if (dataPanel == null) { dataPanel = new JPanel(); // dataPanel.setLayout(new BoxLayout(getDataPanel(), BoxLayout.Y_AXIS)); // Generated dataPanel.add(getJDataPanel(), null); } return dataPanel; } /** * This method initializes buttonPanel * * @return javax.swing.JPanel */ private JPanel getButtonPanel() { if (buttonPanel == null) { buttonPanel = new JPanel(); buttonPanel.add(getOkButton(), null); // Generated buttonPanel.add(getCancelButton(), null); // Generated } return buttonPanel; } /** * This method initializes cancelButton * * @return javax.swing.JButton */ private JButton getCancelButton() { if (cancelButton == null) { cancelButton = new JButton(); cancelButton.setText(MessageBundle.getMessage("angal.common.cancel")); // Generated cancelButton.setMnemonic(KeyEvent.VK_C); cancelButton.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { dispose(); } }); } return cancelButton; } /** * This method initializes okButton * * @return javax.swing.JButton */ private JButton getOkButton() { if (okButton == null) { okButton = new JButton(); okButton.setText(MessageBundle.getMessage("angal.common.ok")); // Generated okButton.setMnemonic(KeyEvent.VK_O); okButton.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { String key = codeTextField.getText(); ExamTypeBrowserManager manager = new ExamTypeBrowserManager(); if (key.equals("")) { JOptionPane.showMessageDialog( null, MessageBundle.getMessage("angal.exatype.pleaseinsertacode"), MessageBundle.getMessage("angal.hospital"), JOptionPane.PLAIN_MESSAGE); return; } // System.out.print(key.length()); if (key.length() > 2) { JOptionPane.showMessageDialog( null, MessageBundle.getMessage("angal.exatype.codetoolongmaxchars"), MessageBundle.getMessage("angal.hospital"), JOptionPane.PLAIN_MESSAGE); return; } if (insert) { if (manager.codeControl(key)) { JOptionPane.showMessageDialog( null, MessageBundle.getMessage("angal.exatype.codealreadyinuse"), MessageBundle.getMessage("angal.hospital"), JOptionPane.PLAIN_MESSAGE); codeTextField.setText(""); return; } } ; if (descriptionTextField.getText().equals("")) { JOptionPane.showMessageDialog( null, MessageBundle.getMessage("angal.exatype.pleaseinsertavaliddescription"), MessageBundle.getMessage("angal.hospital"), JOptionPane.PLAIN_MESSAGE); return; } if (descriptionTextField.getText().equals(lastdescription)) { dispose(); } examType.setDescription(descriptionTextField.getText()); examType.setCode(codeTextField.getText()); boolean result = false; if (insert) { // inserting result = manager.newExamType(examType); if (result) { fireExamInserted(); } if (!result) JOptionPane.showMessageDialog( null, MessageBundle.getMessage("angal.exatype.thedatacouldnotbesaved")); else dispose(); } else { // updating if (descriptionTextField.getText().equals(lastdescription)) { dispose(); } else { result = manager.updateExamType(examType); if (result) { fireExamUpdated(); } if (!result) JOptionPane.showMessageDialog( null, MessageBundle.getMessage("angal.exatype.thedatacouldnotbesaved")); else dispose(); } } } }); } return okButton; } /** * This method initializes descriptionTextField * * @return javax.swing.JTextField */ private JTextField getDescriptionTextField() { if (descriptionTextField == null) { descriptionTextField = new JTextField(20); if (!insert) { descriptionTextField.setText(examType.getDescription()); lastdescription = examType.getDescription(); } } return descriptionTextField; } /** * This method initializes codeTextField * * @return javax.swing.JTextField */ private JTextField getCodeTextField() { if (codeTextField == null) { codeTextField = new VoLimitedTextField(2); if (!insert) { codeTextField.setText(examType.getCode()); codeTextField.setEnabled(false); } } return codeTextField; } /** * This method initializes jDataPanel * * @return javax.swing.JPanel */ private JPanel getJDataPanel() { if (jDataPanel == null) { jDataPanel = new JPanel(); jDataPanel.setLayout(new BoxLayout(getJDataPanel(), BoxLayout.Y_AXIS)); jDataPanel.add(getJCodeLabelPanel(), null); jDataPanel.add(getCodeTextField(), null); jDataPanel.add(getJDescriptionLabelPanel(), null); jDataPanel.add(getDescriptionTextField(), null); } return jDataPanel; } /** * This method initializes jCodeLabel * * @return javax.swing.JLabel */ private JLabel getJCodeLabel() { if (jCodeLabel == null) { jCodeLabel = new JLabel(); jCodeLabel.setText(MessageBundle.getMessage("angal.exatype.codemaxchars")); } return jCodeLabel; } /** * This method initializes jCodeLabelPanel * * @return javax.swing.JPanel */ private JPanel getJCodeLabelPanel() { if (jCodeLabelPanel == null) { jCodeLabelPanel = new JPanel(); // jCodeLabelPanel.setLayout(new BorderLayout()); jCodeLabelPanel.add(getJCodeLabel(), BorderLayout.CENTER); } return jCodeLabelPanel; } /** * This method initializes jDescriptionLabelPanel * * @return javax.swing.JPanel */ private JPanel getJDescriptionLabelPanel() { if (jDescriptionLabelPanel == null) { jDescripitonLabel = new JLabel(); jDescripitonLabel.setText(MessageBundle.getMessage("angal.exatype.description")); jDescriptionLabelPanel = new JPanel(); jDescriptionLabelPanel.add(jDescripitonLabel, null); } return jDescriptionLabelPanel; } } // @jve:decl-index=0:visual-constraint="146,61"
public class UserBrowsing extends ModalJFrame implements UserEdit.UserListener { /* // x cattura chiusura finestra e lancio evento quit public void windowActivated(WindowEvent e) {} public void windowClosed(WindowEvent e) { fireQuitInserted(); } public void windowClosing(WindowEvent e) { fireQuitInserted(); } public void windowDeactivated(WindowEvent e) {} public void windowDeiconified(WindowEvent e) {} public void windowIconified(WindowEvent e) {} public void windowOpened(WindowEvent e) {} // gestione evento quit _____________________________________ private EventListenerList quitListeners = new EventListenerList(); public void addQuitListener(QuitListener listener) { quitListeners.add(QuitListener.class, listener); } public void removeQuitListener(QuitListener listener) { quitListeners.remove(QuitListener.class, listener); } private void fireQuitInserted() { AWTEvent event = new AWTEvent(this, AWTEvent.RESERVED_ID_MAX + 1) {}; EventListener[] listeners = quitListeners.getListeners(QuitListener.class); for (int i = 0; i < listeners.length; i++) ((QuitListener)listeners[i]).quitInserted(event); } */ // messaggi raccolti da UserEdit_________________________________________ /** */ private static final long serialVersionUID = 1L; public void userInserted(AWTEvent e) { User u = (User) e.getSource(); pUser.add(0, u); ((UserBrowserModel) table.getModel()).fireTableDataChanged(); table.updateUI(); if (table.getRowCount() > 0) table.setRowSelectionInterval(0, 0); } public void userUpdated(AWTEvent e) { pUser.set(selectedrow, user); ((UserBrowserModel) table.getModel()).fireTableDataChanged(); table.updateUI(); if ((table.getRowCount() > 0) && selectedrow > -1) table.setRowSelectionInterval(selectedrow, selectedrow); } private static final int DEFAULT_WIDTH = 400; private static final int DEFAULT_HEIGHT = 200; private int pfrmWidth; private int pfrmHeight; private int selectedrow; private JLabel selectlabel; private JComboBox pbox; private ArrayList<User> pUser; // private String[] pColums = { MessageBundle.getMessage("angal.menu.userm"), // MessageBundle.getMessage("angal.menu.groupm"), MessageBundle.getMessage("angal.menu.passwdm"), // MessageBundle.getMessage("angal.menu.descm") }; private String[] pColums = { MessageBundle.getMessage("angal.menu.userm"), MessageBundle.getMessage("angal.menu.groupm"), MessageBundle.getMessage("angal.menu.descm") }; // private int[] pColumwidth = {70, 70, 70, 150 }; private int[] pColumwidth = {70, 70, 150}; private User user; private DefaultTableModel model; private JTable table; private JScrollPane scrollPane; // private final String MASQ = "xxxxxx"; private String pSelection; private UserBrowsing myFrame; private UserBrowsingManager manager = new UserBrowsingManager(); public UserBrowsing() { setTitle(MessageBundle.getMessage("angal.menu.usersbrowser")); myFrame = this; // addWindowListener(this); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); Toolkit kit = Toolkit.getDefaultToolkit(); Dimension screensize = kit.getScreenSize(); pfrmWidth = screensize.width / 2 + 100; pfrmHeight = screensize.height / 2; setBounds(screensize.width / 4, screensize.height / 4, pfrmWidth, pfrmHeight); model = new UserBrowserModel(); table = new JTable(model); table.getColumnModel().getColumn(0).setPreferredWidth(pColumwidth[0]); table.getColumnModel().getColumn(1).setPreferredWidth(pColumwidth[1]); table.getColumnModel().getColumn(2).setPreferredWidth(pColumwidth[2]); // table.getColumnModel().getColumn(3).setPreferredWidth(pColumwidth[3]); scrollPane = new JScrollPane(table); add(scrollPane, BorderLayout.CENTER); JPanel buttonPanel = new JPanel(); selectlabel = new JLabel(MessageBundle.getMessage("angal.menu.selectgroup")); buttonPanel.add(selectlabel); pbox = new JComboBox(); pbox.addItem(MessageBundle.getMessage("angal.menu.all")); ArrayList<UserGroup> group = manager.getUserGroup(); for (UserGroup elem : group) { pbox.addItem(elem); } pbox.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { pSelection = pbox.getSelectedItem().toString(); if (pSelection.compareTo("ALL") == 0) model = new UserBrowserModel(); else model = new UserBrowserModel(pSelection); model.fireTableDataChanged(); table.updateUI(); } }); buttonPanel.add(pbox); JButton buttonNew = new JButton(MessageBundle.getMessage("angal.common.new")); buttonNew.setMnemonic(KeyEvent.VK_N); buttonNew.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { user = new User("", "", "", ""); new UserEdit(myFrame, user, true); } }); buttonPanel.add(buttonNew); JButton buttonEdit = new JButton(MessageBundle.getMessage("angal.common.edit")); buttonEdit.setMnemonic(KeyEvent.VK_E); buttonEdit.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { if (table.getSelectedRow() < 0) { JOptionPane.showMessageDialog( null, MessageBundle.getMessage("angal.common.pleaseselectarow"), MessageBundle.getMessage("angal.hospital"), JOptionPane.PLAIN_MESSAGE); return; } else { selectedrow = table.getSelectedRow(); user = (User) (((UserBrowserModel) model).getValueAt(table.getSelectedRow(), -1)); new UserEdit(myFrame, user, false); } } }); buttonPanel.add(buttonEdit); JButton buttonResetPassword = new JButton(MessageBundle.getMessage("angal.menu.resetpassword")); buttonResetPassword.setMnemonic(KeyEvent.VK_R); buttonResetPassword.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { if (table.getSelectedRow() < 0) { JOptionPane.showMessageDialog( null, MessageBundle.getMessage("angal.common.pleaseselectarow"), MessageBundle.getMessage("angal.hospital"), JOptionPane.PLAIN_MESSAGE); return; } else { selectedrow = table.getSelectedRow(); user = (User) (((UserBrowserModel) model).getValueAt(table.getSelectedRow(), -1)); // 1. Insert new password JPasswordField pwd = new JPasswordField(10); pwd.addAncestorListener( new AncestorListener() { public void ancestorRemoved(AncestorEvent event) {} public void ancestorMoved(AncestorEvent event) {} public void ancestorAdded(AncestorEvent event) { event.getComponent().requestFocusInWindow(); } }); String newPassword = ""; while (newPassword.equals("")) { int action = JOptionPane.showConfirmDialog( UserBrowsing.this, pwd, MessageBundle.getMessage( "angal.menu.onepleaseinsertnewpassowrdminsixdigits"), JOptionPane.OK_CANCEL_OPTION); if (action == JOptionPane.CANCEL_OPTION) return; newPassword = new String(pwd.getPassword()); if (newPassword == null || newPassword.equals("") || newPassword.length() < 6) { JOptionPane.showMessageDialog( UserBrowsing.this, MessageBundle.getMessage( "angal.menu.pleaseinsertavalidpasswordminsixdigits")); newPassword = ""; pwd.setText(""); } } // 2. Retype new password pwd.setText(""); int action = JOptionPane.showConfirmDialog( UserBrowsing.this, pwd, MessageBundle.getMessage("angal.menu.twopleaserepeatpassword"), JOptionPane.OK_CANCEL_OPTION); if (action == JOptionPane.CANCEL_OPTION) return; String newPassword2 = new String(pwd.getPassword()); // 3. Check & Save if (!newPassword.equals(newPassword2)) { JOptionPane.showMessageDialog( UserBrowsing.this, MessageBundle.getMessage("angal.menu.retypeerrorpleaseretry")); return; } if (newPassword != null && !newPassword.equals("") && newPassword.length() >= 6) { String hashed = BCrypt.hashpw(new String(newPassword), BCrypt.gensalt()); user.setPasswd(hashed); if (manager.updatePassword(user)) JOptionPane.showMessageDialog( UserBrowsing.this, MessageBundle.getMessage("angal.menu.thepasswordhasbeenchanged")); } else { JOptionPane.showMessageDialog( UserBrowsing.this, MessageBundle.getMessage("angal.menu.pleaseinsertavalidpasswordminsixdigits")); } } } }); buttonPanel.add(buttonResetPassword); JButton buttonDelete = new JButton(MessageBundle.getMessage("angal.common.delete")); buttonDelete.setMnemonic(KeyEvent.VK_D); buttonDelete.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { if (table.getSelectedRow() < 0) { JOptionPane.showMessageDialog( null, MessageBundle.getMessage("angal.common.pleaseselectarow"), MessageBundle.getMessage("angal.hospital"), JOptionPane.PLAIN_MESSAGE); return; } else { UserBrowsingManager manager = new UserBrowsingManager(); User m = (User) (((UserBrowserModel) model).getValueAt(table.getSelectedRow(), -1)); int n = JOptionPane.showConfirmDialog( null, MessageBundle.getMessage("angal.menu.deleteuser") + " \"" + m.getUserName() + "\" ?", MessageBundle.getMessage("angal.hospital"), JOptionPane.YES_NO_OPTION); if ((n == JOptionPane.YES_OPTION) && (manager.deleteUser(m))) { pUser.remove(table.getSelectedRow()); model.fireTableDataChanged(); table.updateUI(); } } } }); buttonPanel.add(buttonDelete); JButton buttonClose = new JButton(MessageBundle.getMessage("angal.common.close")); buttonClose.setMnemonic(KeyEvent.VK_C); buttonClose.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { dispose(); } }); buttonPanel.add(buttonClose); add(buttonPanel, BorderLayout.SOUTH); setVisible(true); } class UserBrowserModel extends DefaultTableModel { /** */ private static final long serialVersionUID = 1L; public UserBrowserModel(String s) { UserBrowsingManager manager = new UserBrowsingManager(); pUser = manager.getUser(s); } public UserBrowserModel() { UserBrowsingManager manager = new UserBrowsingManager(); pUser = manager.getUser(); } public int getRowCount() { if (pUser == null) return 0; return pUser.size(); } public String getColumnName(int c) { return pColums[c]; } public int getColumnCount() { return pColums.length; } public Object getValueAt(int r, int c) { if (c == 0) { return pUser.get(r).getUserName(); } else if (c == -1) { return pUser.get(r); } else if (c == 1) { return pUser.get(r).getUserGroupName(); } else if (c == 2) { return pUser.get(r).getDesc(); } return null; } @Override public boolean isCellEditable(int arg0, int arg1) { // return super.isCellEditable(arg0, arg1); return false; } } }