diff --git a/bundle/language_en.properties b/bundle/language_en.properties index 60b5303403..05138573b9 100644 --- a/bundle/language_en.properties +++ b/bundle/language_en.properties @@ -373,6 +373,9 @@ angal.common.days.txt angal.common.delete = Delete angal.common.delete.btn = Delete angal.common.delete.btn.key = D +angal.common.deleted.col = Deleted +angal.common.deleted.label = Deleted +angal.common.denied.msg = This operation is not allowed. angal.common.description.txt = Description angal.common.discharge.txt = Discharge angal.common.documenthasnopages.msg = The document has no pages. @@ -634,6 +637,7 @@ angal.exatype.examtypebrowser.title angal.exatype.newexamtype.title = New Exam Type angal.genericreportbill.doyouwanttoprintreceipt.msg = Do you want to print a receipt? angal.groupsbrowser.deletegroup.fmt.msg = Delete group: {0}? +angal.groupsbrowser.softdeletegroup.fmt.msg = Could not delete the group '{0}' because it is used somewhere. Do you want to mark it as deleted ? angal.groupsbrowser.description.label = Description: angal.groupsbrowser.editgroup.title = Edit Group angal.groupsbrowser.groupmenu.btn = GroupMenu @@ -643,6 +647,7 @@ angal.groupsbrowser.mainmenu.txt angal.groupsbrowser.menuitembrowser.title = Menu Item Browser angal.groupsbrowser.newgroup.title = New Group angal.groupsbrowser.pleaseinsertavalidusergroupname.msg = Please insert a valid user group name. +angal.groupsbrowser.alreadysoftdeleted.msg = The group is already set as deleted. angal.groupsbrowser.theadmingroupcannotbedeleted.msg = The "admin" group cannot be deleted. angal.groupsbrowser.thegroupalreadyexists.fmt.msg = The group "{0}" already exists. angal.groupsbrowser.thisgrouphasusersandcannotbedeleted.msg = This group has users and cannot be deleted. @@ -1686,7 +1691,6 @@ angal.stat.weeklyepidemsurveilover5 angal.stat.weeklyepidemsurveilunder5 = HMIS 33b - Weekly epidem. surveil. under 5 y.o. angal.stat.year = Year angal.supplier.deleted = Deleted -angal.supplier.deleted.col = Deleted angal.supplier.deletesupplier.fmt.msg = Delete supplier: {0}? angal.supplier.editsupplier.title = Edit Supplier angal.supplier.email = E-mail @@ -1778,6 +1782,7 @@ angal.therapy.worksheet.btn angal.therapy.worksheet.btn.key = W angal.userbrowser.addnewuser.title = Add New User angal.userbrowser.deleteuser.fmt.msg = Delete user: {0}? +angal.userbrowser.softdeleteuser.fmt.msg = Could not delete the user '{0}' because it is used somewhere. Do you want to mark it as deleted ? angal.userbrowser.description.label = Description: angal.userbrowser.edituser.title = Edit User angal.userbrowser.group.label = Group: @@ -1800,6 +1805,7 @@ angal.userbrowser.resetpassword.btn.key angal.userbrowser.resetpassword.title = Reset Password angal.userbrowser.retype.password.label = Retype Password: angal.userbrowser.selectgroup.label = Select group: +angal.userbrowser.alreadysoftdeleted.msg = The user is already set as deleted. angal.userbrowser.step1.pleaseinsertanew.password.msg = Please insert a new password. angal.userbrowser.step1.pleaseinsertanew.password.fmt.msg = Please insert a new password (minimum of {0} characters). angal.userbrowser.step2.pleaserepeatthenewpassword.label = Please repeat the new password. diff --git a/src/main/java/org/isf/menu/gui/GroupEdit.java b/src/main/java/org/isf/menu/gui/GroupEdit.java index dee1db1321..5e17a2098a 100644 --- a/src/main/java/org/isf/menu/gui/GroupEdit.java +++ b/src/main/java/org/isf/menu/gui/GroupEdit.java @@ -25,6 +25,7 @@ import java.util.EventListener; import javax.swing.JButton; +import javax.swing.JCheckBox; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JPanel; @@ -45,23 +46,38 @@ public class GroupEdit extends JDialog { private static final long serialVersionUID = 1L; - private EventListenerList groupListeners = new EventListenerList(); + private final EventListenerList groupListeners = new EventListenerList(); - private UserBrowsingManager userBrowsingManager = Context.getApplicationContext().getBean(UserBrowsingManager.class); - - public interface GroupListener extends EventListener { - void groupUpdated(AWTEvent e); - void groupInserted(AWTEvent e); - } - - public void addGroupListener(GroupListener l) { - groupListeners.add(GroupListener.class, l); - } - - public void removeGroupListener(GroupListener listener) { - groupListeners.remove(GroupListener.class, listener); - } + private final UserBrowsingManager userBrowsingManager = Context.getApplicationContext().getBean(UserBrowsingManager.class); + private final UserGroup group; + private final boolean insert; + private JPanel jContentPane; + private JPanel dataPanel; + private JPanel buttonPanel; + private JButton cancelButton; + private JButton okButton; + private JTextField descriptionTextField; + private JTextField nameTextField; + private JCheckBox isDeletedCheck; + /** + * This is the default constructor; we pass the arraylist and the selectedrow because we need to update them + */ + public GroupEdit(UserGroupBrowsing parent, UserGroup old, boolean inserting) { + super(parent, inserting + ? MessageBundle.getMessage("angal.groupsbrowser.newgroup.title") + : MessageBundle.getMessage("angal.groupsbrowser.editgroup.title"), true); + addGroupListener(parent); + insert = inserting; + group = old; + initialize(); + } + public void addGroupListener(GroupListener l) { + groupListeners.add(GroupListener.class, l); + } + public void removeGroupListener(GroupListener listener) { + groupListeners.remove(GroupListener.class, listener); + } private void fireGroupInserted(UserGroup aGroup) { AWTEvent event = new AWTEvent(aGroup, AWTEvent.RESERVED_ID_MAX + 1) { @@ -73,7 +89,6 @@ private void fireGroupInserted(UserGroup aGroup) { ((GroupListener) listener).groupInserted(event); } } - private void fireGroupUpdated() { AWTEvent event = new AWTEvent(new Object(), AWTEvent.RESERVED_ID_MAX + 1) { @@ -85,46 +100,17 @@ private void fireGroupUpdated() { ((GroupListener) listener).groupUpdated(event); } } - - private JPanel jContentPane; - private JPanel dataPanel; - private JPanel buttonPanel; - private JButton cancelButton; - private JButton okButton; - private JTextField descriptionTextField; - private JTextField nameTextField; - - private UserGroup group; - private boolean insert; - - /** - * This is the default constructor; we pass the arraylist and the selectedrow - * because we need to update them - */ - public GroupEdit(UserGroupBrowsing parent, UserGroup old, boolean inserting) { - super(parent, inserting - ? MessageBundle.getMessage("angal.groupsbrowser.newgroup.title") - : MessageBundle.getMessage("angal.groupsbrowser.editgroup.title"), true); - addGroupListener(parent); - insert = inserting; - group = old; - initialize(); - } - /** * This method initializes this */ private void initialize() { - - this.setBounds(300, 300, 450, 150); this.setContentPane(getJContentPane()); - this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); setResizable(false); + pack(); setLocationRelativeTo(null); setVisible(true); } - /** * This method initializes jContentPane * @@ -139,10 +125,9 @@ private JPanel getJContentPane() { } return jContentPane; } - /** * This method initializes dataPanel - * + * * @return javax.swing.JPanel */ private JPanel getDataPanel() { @@ -152,32 +137,36 @@ private JPanel getDataPanel() { dataPanel = new JPanel(new SpringLayout()); dataPanel.add(nameLabel); dataPanel.add(getNameTextField()); - + dataPanel.add(descLabel); dataPanel.add(getDescriptionTextField()); - SpringUtilities.makeCompactGrid(dataPanel, 2, 2, 5, 5, 5, 5); + + dataPanel.add(new JLabel(MessageBundle.getMessage("angal.common.deleted.label"))); + isDeletedCheck = new JCheckBox(); + isDeletedCheck.setSelected(group.isDeleted()); + dataPanel.add(isDeletedCheck); + + SpringUtilities.makeCompactGrid(dataPanel, 3, 2, 5, 5, 5, 5); } return dataPanel; } - /** - * This method initializes buttonPanel - * - * @return javax.swing.JPanel + * This method initializes buttonPanel + * + * @return javax.swing.JPanel */ private JPanel getButtonPanel() { if (buttonPanel == null) { buttonPanel = new JPanel(); - buttonPanel.add(getOkButton(), null); - buttonPanel.add(getCancelButton(), null); + buttonPanel.add(getOkButton(), null); + buttonPanel.add(getCancelButton(), null); } return buttonPanel; } - /** - * This method initializes cancelButton - * - * @return javax.swing.JButton + * This method initializes cancelButton + * + * @return javax.swing.JButton */ private JButton getCancelButton() { if (cancelButton == null) { @@ -187,11 +176,10 @@ private JButton getCancelButton() { } return cancelButton; } - /** - * This method initializes okButton - * - * @return javax.swing.JButton + * This method initializes okButton + * + * @return javax.swing.JButton */ private JButton getOkButton() { if (okButton == null) { @@ -204,9 +192,10 @@ private JButton getOkButton() { } group.setCode(nameTextField.getText()); - group.setDesc(descriptionTextField.getText()); - if (insert) { // inserting + group.setDeleted(isDeletedCheck.isSelected()); + + if (insert) { // inserting try { userBrowsingManager.newUserGroup(group); fireGroupInserted(group); @@ -215,7 +204,7 @@ private JButton getOkButton() { MessageDialog.error(null, "angal.common.datacouldnotbesaved.msg"); OHServiceExceptionUtil.showMessages(e1); } - } else { // updating + } else { // updating try { userBrowsingManager.updateUserGroup(group); fireGroupUpdated(); @@ -229,27 +218,25 @@ private JButton getOkButton() { } return okButton; } - /** - * This method initializes descriptionTextField - * - * @return javax.swing.JTextField + * This method initializes descriptionTextField + * + * @return javax.swing.JTextField */ private JTextField getDescriptionTextField() { if (descriptionTextField == null) { if (insert) { - descriptionTextField = new JTextField(); + descriptionTextField = new JTextField(15); } else { descriptionTextField = new JTextField(group.getDesc()); } } return descriptionTextField; } - private JTextField getNameTextField() { if (nameTextField == null) { if (insert) { - nameTextField = new JTextField(); + nameTextField = new JTextField(15); } else { nameTextField = new JTextField(group.getCode()); nameTextField.setEditable(false); @@ -258,4 +245,10 @@ private JTextField getNameTextField() { return nameTextField; } + public interface GroupListener extends EventListener { + + void groupUpdated(AWTEvent e); + void groupInserted(AWTEvent e); + } + } diff --git a/src/main/java/org/isf/menu/gui/UserBrowsing.java b/src/main/java/org/isf/menu/gui/UserBrowsing.java index eb56b27671..54f4937c73 100644 --- a/src/main/java/org/isf/menu/gui/UserBrowsing.java +++ b/src/main/java/org/isf/menu/gui/UserBrowsing.java @@ -46,6 +46,7 @@ import org.isf.menu.model.User; import org.isf.menu.model.UserGroup; import org.isf.utils.db.BCrypt; +import org.isf.utils.exception.OHDataIntegrityViolationException; import org.isf.utils.exception.OHServiceException; import org.isf.utils.exception.gui.OHServiceExceptionUtil; import org.isf.utils.jobjects.MessageDialog; @@ -55,46 +56,23 @@ public class UserBrowsing extends ModalJFrame implements UserListener { private static final long serialVersionUID = 1L; private static final String ALL_STR = MessageBundle.getMessage("angal.common.all.txt").toUpperCase(); - - @Override - public void userInserted(AWTEvent e) { - User u = (User) e.getSource(); - userList.add(0, u); - ((UserBrowserModel) table.getModel()).fireTableDataChanged(); - table.updateUI(); - if (table.getRowCount() > 0) { - table.setRowSelectionInterval(0, 0); - } - } - - @Override - public void userUpdated(AWTEvent e) { - userList.set(selectedrow, user); - ((UserBrowserModel) table.getModel()).fireTableDataChanged(); - table.updateUI(); - if ((table.getRowCount() > 0) && (selectedrow > -1)) { - table.setRowSelectionInterval(selectedrow, selectedrow); - } - } - + private final JComboBox userGroupFilter; + private final String[] pColumns = { + MessageBundle.getMessage("angal.userbrowser.user.col").toUpperCase(), + MessageBundle.getMessage("angal.common.group.txt").toUpperCase(), + MessageBundle.getMessage("angal.common.description.txt").toUpperCase(), + MessageBundle.getMessage("angal.userbrowser.locked.col").toUpperCase(), + MessageBundle.getMessage("angal.common.deleted.col").toUpperCase() }; + private final int[] pColumnWidth = { 70, 70, 150, 20, 20 }; + private final JTable table; + private final UserBrowsing myFrame; + private final UserBrowsingManager userBrowsingManager = Context.getApplicationContext().getBean(UserBrowsingManager.class); private int selectedrow; - private JComboBox userGroupFilter; private List userList; - private String[] pColumns = { - MessageBundle.getMessage("angal.userbrowser.user.col").toUpperCase(), - MessageBundle.getMessage("angal.common.group.txt").toUpperCase(), - MessageBundle.getMessage("angal.common.description.txt").toUpperCase(), - MessageBundle.getMessage("angal.userbrowser.locked.col").toUpperCase()}; - private int[] pColumnWidth = {70, 70, 150, 20}; private User user; private DefaultTableModel model; - private JTable table; - private String pSelection; - private UserBrowsing myFrame; - private UserBrowsingManager userBrowsingManager = Context.getApplicationContext().getBean(UserBrowsingManager.class); - public UserBrowsing() { setTitle(MessageBundle.getMessage("angal.userbrowser.title")); @@ -106,6 +84,7 @@ public UserBrowsing() { table.getColumnModel().getColumn(1).setPreferredWidth(pColumnWidth[1]); table.getColumnModel().getColumn(2).setPreferredWidth(pColumnWidth[2]); table.getColumnModel().getColumn(3).setPreferredWidth(pColumnWidth[3]); + table.getColumnModel().getColumn(4).setPreferredWidth(pColumnWidth[4]); JScrollPane scrollPane = new JScrollPane(table); add(scrollPane, BorderLayout.CENTER); @@ -190,7 +169,8 @@ public void ancestorAdded(AncestorEvent event) { String newPassword = ""; JPanel stepPanel = new JPanel(new GridLayout(2, 1, 5, 5)); if (GeneralData.STRONGLENGTH != 0) { - stepPanel.add(new JLabel(MessageBundle.formatMessage("angal.userbrowser.step1.pleaseinsertanew.password.fmt.msg", GeneralData.STRONGLENGTH))); + stepPanel.add( + new JLabel(MessageBundle.formatMessage("angal.userbrowser.step1.pleaseinsertanew.password.fmt.msg", GeneralData.STRONGLENGTH))); } else { stepPanel.add(new JLabel(MessageBundle.formatMessage("angal.userbrowser.step1.pleaseinsertanew.password.msg"))); } @@ -199,8 +179,8 @@ public void ancestorAdded(AncestorEvent event) { while (newPassword.isEmpty()) { int action = JOptionPane - .showConfirmDialog(this, stepPanel, MessageBundle.getMessage("angal.userbrowser.resetpassword.title"), - JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); + .showConfirmDialog(this, stepPanel, MessageBundle.getMessage("angal.userbrowser.resetpassword.title"), + JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); if (JOptionPane.CANCEL_OPTION == action) { return; } @@ -230,8 +210,8 @@ public void ancestorAdded(AncestorEvent event) { stepPanel.add(new JLabel(MessageBundle.getMessage("angal.userbrowser.step2.pleaserepeatthenewpassword.label"))); stepPanel.add(pwd); int action = JOptionPane - .showConfirmDialog(this, stepPanel, MessageBundle.getMessage("angal.userbrowser.resetpassword.title"), - JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); + .showConfirmDialog(this, stepPanel, MessageBundle.getMessage("angal.userbrowser.resetpassword.title"), + JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); if (JOptionPane.CANCEL_OPTION == action) { return; } @@ -258,7 +238,7 @@ public void ancestorAdded(AncestorEvent event) { newPassword2 = null; user.setPasswd(hashed); try { - if (userBrowsingManager.updatePassword(user)) { + if (userBrowsingManager.updatePassword(user) != null) { MessageDialog.info(this, "angal.userbrowser.thepasswordhasbeenchanged.msg"); } } catch (OHServiceException e) { @@ -283,6 +263,24 @@ public void ancestorAdded(AncestorEvent event) { model.fireTableDataChanged(); table.updateUI(); } + } catch (OHDataIntegrityViolationException ex) { + try { + User oldUser = userBrowsingManager.getUserByName(selectedUser.getUserName(), true); + if (oldUser.isDeleted()) { + MessageDialog.error(null, "angal.userbrowser.alreadysoftdeleted.msg"); + } else { + answer = MessageDialog.yesNo(null, "angal.userbrowser.softdeleteuser.fmt.msg", selectedUser.getUserName()); + if (answer == JOptionPane.YES_OPTION) { + selectedUser.setDeleted(true); + userBrowsingManager.updateUser(selectedUser); + model.fireTableDataChanged(); + table.updateUI(); + } + } + } catch (OHServiceException e) { + selectedUser.setDeleted(false); + OHServiceExceptionUtil.showMessages(e); + } } catch (OHServiceException e) { OHServiceExceptionUtil.showMessages(e); } @@ -302,6 +300,27 @@ public void ancestorAdded(AncestorEvent event) { setVisible(true); } + @Override + public void userInserted(AWTEvent e) { + User u = (User) e.getSource(); + userList.add(0, u); + ((UserBrowserModel) table.getModel()).fireTableDataChanged(); + table.updateUI(); + if (table.getRowCount() > 0) { + table.setRowSelectionInterval(0, 0); + } + } + + @Override + public void userUpdated(AWTEvent e) { + userList.set(selectedrow, user); + ((UserBrowserModel) table.getModel()).fireTableDataChanged(); + table.updateUI(); + if ((table.getRowCount() > 0) && (selectedrow > -1)) { + table.setRowSelectionInterval(selectedrow, selectedrow); + } + } + class UserBrowserModel extends DefaultTableModel { private static final long serialVersionUID = 1L; @@ -324,7 +343,7 @@ public UserBrowserModel() { @Override public Class getColumnClass(int column) { - return (column == 3) ? Boolean.class : String.class; + return (column == 3 || column == 4) ? Boolean.class : String.class; } @Override @@ -357,6 +376,8 @@ public Object getValueAt(int r, int c) { return userList.get(r).getDesc(); } else if (c == 3) { return userList.get(r).isAccountLocked(); + } else if (c == 4) { + return userList.get(r).isDeleted(); } return null; } diff --git a/src/main/java/org/isf/menu/gui/UserEdit.java b/src/main/java/org/isf/menu/gui/UserEdit.java index f9a2bb175a..2c444058bd 100644 --- a/src/main/java/org/isf/menu/gui/UserEdit.java +++ b/src/main/java/org/isf/menu/gui/UserEdit.java @@ -55,21 +55,39 @@ public class UserEdit extends JDialog { private static final long serialVersionUID = 1L; - private EventListenerList userListeners = new EventListenerList(); - - public interface UserListener extends EventListener { - void userUpdated(AWTEvent e); - void userInserted(AWTEvent e); - } - - public void addUserListener(UserListener l) { - userListeners.add(UserListener.class, l); - } - - public void removeUserListener(UserListener listener) { - userListeners.remove(UserListener.class, listener); - } - + private final EventListenerList userListeners = new EventListenerList(); + private final User user; + private final boolean insert; + private final UserBrowsingManager userBrowsingManager = Context.getApplicationContext().getBean(UserBrowsingManager.class); + private JPanel jContentPane; + private JPanel dataPanel; + private JPanel buttonPanel; + private JButton cancelButton; + private JButton okButton; + private JTextField descriptionTextField; + private JTextField nameTextField; + private JPasswordField pwdTextField; + private JPasswordField pwd2TextField; + private JComboBox userGroupComboBox; + private JCheckBox accountLocked; + private JCheckBox isDeletedCheck; + /** + * This is the default constructor; we pass the arraylist and the selectedrow because we need to update them + */ + public UserEdit(UserBrowsing parent, User old, boolean inserting) { + super(parent, (inserting ? MessageBundle.getMessage("angal.userbrowser.addnewuser.title") + : MessageBundle.getMessage("angal.userbrowser.edituser.title")), true); + addUserListener(parent); + insert = inserting; + user = old; + initialize(); + } + public void addUserListener(UserListener l) { + userListeners.add(UserListener.class, l); + } + public void removeUserListener(UserListener listener) { + userListeners.remove(UserListener.class, listener); + } private void fireUserInserted(User aUser) { AWTEvent event = new AWTEvent(aUser, AWTEvent.RESERVED_ID_MAX + 1) { @@ -81,7 +99,6 @@ private void fireUserInserted(User aUser) { ((UserListener) listener).userInserted(event); } } - private void fireUserUpdated() { AWTEvent event = new AWTEvent(new Object(), AWTEvent.RESERVED_ID_MAX + 1) { @@ -93,37 +110,6 @@ private void fireUserUpdated() { ((UserListener) listener).userUpdated(event); } } - - private JPanel jContentPane; - private JPanel dataPanel; - private JPanel buttonPanel; - private JButton cancelButton; - private JButton okButton; - private JTextField descriptionTextField; - private JTextField nameTextField; - private JPasswordField pwdTextField; - private JPasswordField pwd2TextField; - private JComboBox userGroupComboBox; - private JCheckBox accountLocked; - - private User user; - private boolean insert; - - private UserBrowsingManager userBrowsingManager = Context.getApplicationContext().getBean(UserBrowsingManager.class); - - /** - * This is the default constructor; we pass the arraylist and the selectedrow - * because we need to update them - */ - public UserEdit(UserBrowsing parent, User old, boolean inserting) { - super(parent, (inserting ? MessageBundle.getMessage("angal.userbrowser.addnewuser.title") - : MessageBundle.getMessage("angal.userbrowser.edituser.title")), true); - addUserListener(parent); - insert = inserting; - user = old; - initialize(); - } - /** * This method initializes this */ @@ -134,10 +120,8 @@ private void initialize() { setLocationRelativeTo(null); setVisible(true); } - /** * This method initializes jContentPane - * * @return javax.swing.JPanel */ private JPanel getJContentPane() { @@ -149,16 +133,9 @@ private JPanel getJContentPane() { } return jContentPane; } - /** * This method initializes dataPanel - * - * @return javax.swing.JPanel - * tipo combo - * nome text - * desc text - * pwd text - * pwd2 text + * @return javax.swing.JPanel tipo combo nome text desc text pwd text pwd2 text */ private JPanel getDataPanel() { if (dataPanel == null) { @@ -181,17 +158,21 @@ private JPanel getDataPanel() { accountLocked.setSelected(user.isAccountLocked()); dataPanel.add(accountLocked); } + + dataPanel.add(new JLabel(MessageBundle.getMessage("angal.common.deleted.label"))); + isDeletedCheck = new JCheckBox(); + isDeletedCheck.setSelected(user.isDeleted()); + dataPanel.add(isDeletedCheck); + SpringUtilities.makeCompactGrid(dataPanel, - insert ? 5 : 4, 2, - 5, 5, - 5, 5); + insert ? 6 : 5, 2, + 5, 5, + 5, 5); } return dataPanel; } - /** * This method initializes buttonPanel - * * @return javax.swing.JPanel */ private JPanel getButtonPanel() { @@ -202,10 +183,8 @@ private JPanel getButtonPanel() { } return buttonPanel; } - /** * This method initializes cancelButton - * * @return javax.swing.JButton */ private JButton getCancelButton() { @@ -216,10 +195,8 @@ private JButton getCancelButton() { } return cancelButton; } - /** * This method initializes okButton - * * @return javax.swing.JButton */ private JButton getOkButton() { @@ -232,8 +209,11 @@ private JButton getOkButton() { MessageDialog.error(null, "angal.userbrowser.pleaseprovideavalidusername.msg"); return; } + user.setUserName(userName); user.setDesc(descriptionTextField.getText()); + user.setDeleted(isDeletedCheck.isSelected()); + if (insert) { char[] password = pwdTextField.getPassword(); char[] repeatPassword = pwd2TextField.getPassword(); @@ -278,9 +258,11 @@ private JButton getOkButton() { Arrays.fill(repeatPassword, '0'); return; } + String hashed = BCrypt.hashpw(new String(password), BCrypt.gensalt()); user.setPasswd(hashed); user.setUserGroupName((UserGroup) userGroupComboBox.getSelectedItem()); + try { userBrowsingManager.newUser(user); fireUserInserted(user); @@ -311,10 +293,8 @@ private JButton getOkButton() { } return okButton; } - /** * This method initializes descriptionTextField - * * @return javax.swing.JTextField */ private JTextField getDescriptionTextField() { @@ -328,8 +308,6 @@ private JTextField getDescriptionTextField() { } return descriptionTextField; } - - private JTextField getNameTextField() { if (nameTextField == null) { if (insert) { @@ -342,24 +320,20 @@ private JTextField getNameTextField() { } return nameTextField; } - private JPasswordField getPwdTextField() { if (pwdTextField == null) { pwdTextField = new JPasswordField(15); } return pwdTextField; } - private JTextField getPwd2TextField() { if (pwd2TextField == null) { pwd2TextField = new JPasswordField(15); } return pwd2TextField; } - /** * This method initializes userGroupComboBox - * * @return javax.swing.JComboBox */ private JComboBox getUserGroupComboBox() { @@ -400,4 +374,10 @@ private JComboBox getUserGroupComboBox() { return userGroupComboBox; } + public interface UserListener extends EventListener { + + void userUpdated(AWTEvent e); + void userInserted(AWTEvent e); + } + } diff --git a/src/main/java/org/isf/menu/gui/UserGroupBrowsing.java b/src/main/java/org/isf/menu/gui/UserGroupBrowsing.java index 62eb3d93be..8790512cdb 100644 --- a/src/main/java/org/isf/menu/gui/UserGroupBrowsing.java +++ b/src/main/java/org/isf/menu/gui/UserGroupBrowsing.java @@ -39,6 +39,7 @@ import org.isf.menu.manager.Context; import org.isf.menu.manager.UserBrowsingManager; import org.isf.menu.model.UserGroup; +import org.isf.utils.exception.OHDataIntegrityViolationException; import org.isf.utils.exception.OHServiceException; import org.isf.utils.exception.gui.OHServiceExceptionUtil; import org.isf.utils.jobjects.MessageDialog; @@ -47,60 +48,39 @@ public class UserGroupBrowsing extends ModalJFrame implements GroupListener { private static final long serialVersionUID = 1L; - - @Override - public void groupInserted(AWTEvent e) { - pGroup.add(0, group); - ((UserGroupBrowserModel) table.getModel()).fireTableDataChanged(); - table.updateUI(); - if (table.getRowCount() > 0) { - table.setRowSelectionInterval(0, 0); - } - } - - @Override - public void groupUpdated(AWTEvent e) { - pGroup.set(selectedrow, group); - ((UserGroupBrowserModel) table.getModel()).fireTableDataChanged(); - table.updateUI(); - if (table.getRowCount() > 0 && selectedrow > -1) { - table.setRowSelectionInterval(selectedrow, selectedrow); - } - } - private static final int DEFAULT_WIDTH = 200; private static final int DEFAULT_HEIGHT = 150; + private final String[] pColumns = { + MessageBundle.getMessage("angal.common.group.txt").toUpperCase(), + MessageBundle.getMessage("angal.common.description.txt").toUpperCase(), + MessageBundle.getMessage("angal.common.deleted.col").toUpperCase() + }; + private final int[] pColumnWidth = { 70, 100, 20 }; + private final DefaultTableModel model; + private final JTable table; + private final UserGroupBrowsing myFrame; + private final UserBrowsingManager userBrowsingManager = Context.getApplicationContext().getBean(UserBrowsingManager.class); private int selectedrow; private List pGroup; - private String[] pColumns = { - MessageBundle.getMessage("angal.common.group.txt").toUpperCase(), - MessageBundle.getMessage("angal.common.description.txt").toUpperCase() - }; - private int[] pColumnWidth = {70, 100}; private UserGroup group; - private DefaultTableModel model; - private JTable table; - - private UserGroupBrowsing myFrame; - - private UserBrowsingManager userBrowsingManager = Context.getApplicationContext().getBean(UserBrowsingManager.class); public UserGroupBrowsing() { myFrame = this; setTitle(MessageBundle.getMessage("angal.groupsbrowser.title")); - + setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); Toolkit kit = Toolkit.getDefaultToolkit(); Dimension screensize = kit.getScreenSize(); int pfrmWidth = screensize.width / 2; int pfrmHeight = screensize.height / 4; setBounds(screensize.width / 4, screensize.height / 4, pfrmWidth, pfrmHeight); - + model = new UserGroupBrowserModel(); table = new JTable(model); table.getColumnModel().getColumn(0).setPreferredWidth(pColumnWidth[0]); table.getColumnModel().getColumn(1).setPreferredWidth(pColumnWidth[1]); - + table.getColumnModel().getColumn(2).setPreferredWidth(pColumnWidth[2]); + add(new JScrollPane(table), BorderLayout.CENTER); JPanel buttonPanel = new JPanel(); @@ -153,6 +133,24 @@ public UserGroupBrowsing() { model.fireTableDataChanged(); table.updateUI(); } + } catch (OHDataIntegrityViolationException ex) { + UserGroup oldUserGroup = userBrowsingManager.findUserGroupByCode(userGroup.getCode(), true); + if (oldUserGroup.isDeleted()) { + MessageDialog.error(null, "angal.groupsbrowser.alreadysoftdeleted.msg"); + } else { + answer = MessageDialog.yesNo(null, "angal.groupsbrowser.softdeletegroup.fmt.msg", userGroup.getCode()); + if (answer == JOptionPane.YES_OPTION) { + try { + userGroup.setDeleted(true); + userBrowsingManager.updateUserGroup(userGroup); + model.fireTableDataChanged(); + table.updateUI(); + } catch (OHServiceException e) { + userGroup.setDeleted(false); + OHServiceExceptionUtil.showMessages(e); + } + } + } } catch (OHServiceException e) { OHServiceExceptionUtil.showMessages(e); } @@ -170,17 +168,37 @@ public UserGroupBrowsing() { setVisible(true); } + @Override + public void groupInserted(AWTEvent e) { + pGroup.add(0, group); + ((UserGroupBrowserModel) table.getModel()).fireTableDataChanged(); + table.updateUI(); + if (table.getRowCount() > 0) { + table.setRowSelectionInterval(0, 0); + } + } + + @Override + public void groupUpdated(AWTEvent e) { + pGroup.set(selectedrow, group); + ((UserGroupBrowserModel) table.getModel()).fireTableDataChanged(); + table.updateUI(); + if (table.getRowCount() > 0 && selectedrow > -1) { + table.setRowSelectionInterval(selectedrow, selectedrow); + } + } + class UserGroupBrowserModel extends DefaultTableModel { private static final long serialVersionUID = 1L; public UserGroupBrowserModel() { - try { - pGroup = userBrowsingManager.getUserGroup(); - } catch (OHServiceException e) { - OHServiceExceptionUtil.showMessages(e); - } - } + try { + pGroup = userBrowsingManager.getUserGroup(); + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + } + } @Override public int getRowCount() { @@ -189,7 +207,7 @@ public int getRowCount() { } return pGroup.size(); } - + @Override public String getColumnName(int c) { return pColumns[c]; @@ -208,10 +226,17 @@ public Object getValueAt(int r, int c) { return pGroup.get(r); } else if (c == 1) { return pGroup.get(r).getDesc(); - } + } else if (c == 2) { + return pGroup.get(r).isDeleted(); + } return null; } - + + @Override + public Class getColumnClass(int column) { + return (column == 2) ? Boolean.class : String.class; + } + @Override public boolean isCellEditable(int arg0, int arg1) { return false; diff --git a/src/main/java/org/isf/supplier/gui/SupplierBrowser.java b/src/main/java/org/isf/supplier/gui/SupplierBrowser.java index a3bfbb3c2e..491e49ee56 100644 --- a/src/main/java/org/isf/supplier/gui/SupplierBrowser.java +++ b/src/main/java/org/isf/supplier/gui/SupplierBrowser.java @@ -95,7 +95,7 @@ public void supplierUpdated(AWTEvent e) { MessageBundle.getMessage("angal.common.fax.txt").toUpperCase(), MessageBundle.getMessage("angal.common.email.txt").toUpperCase(), MessageBundle.getMessage("angal.common.note.txt").toUpperCase(), - MessageBundle.getMessage("angal.supplier.deleted.col").toUpperCase() + MessageBundle.getMessage("angal.common.deleted.col").toUpperCase() }; private int[] pColumnWidth = {45, 80, 60, 60, 80, 30, 30, 30, 30}; private int selectedrow;