diff --git a/bundle/language_en.properties b/bundle/language_en.properties index f83dc048c0..944147802b 100644 --- a/bundle/language_en.properties +++ b/bundle/language_en.properties @@ -372,6 +372,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. @@ -1698,7 +1703,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 @@ -1790,6 +1794,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: @@ -1812,6 +1817,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/accounting/gui/BillDataLoader.java b/src/main/java/org/isf/accounting/gui/BillDataLoader.java index 81b816e08f..05618b065c 100644 --- a/src/main/java/org/isf/accounting/gui/BillDataLoader.java +++ b/src/main/java/org/isf/accounting/gui/BillDataLoader.java @@ -47,19 +47,12 @@ public BillDataLoader(List billPeriod, List billFromPayments, Patien } public List loadBills(String status, String username) throws OHServiceException { - List tableArray = new ArrayList<>(); - - switch (status) { - case "O": - tableArray = getPendingBills(status, username); - break; - case "ALL": - tableArray = getAllBills(username); - break; - case "C": - tableArray = getClosedBills(status, username); - break; - } + List tableArray = switch (status) { + case "O" -> getPendingBills(status, username); + case "ALL" -> getAllBills(username); + case "C" -> getClosedBills(status, username); + default -> new ArrayList<>(); + }; tableArray.sort(Collections.reverseOrder()); return tableArray; diff --git a/src/main/java/org/isf/admission/gui/AdmittedPatientBrowser.java b/src/main/java/org/isf/admission/gui/AdmittedPatientBrowser.java index 0e2aa065c8..fb611a04cf 100644 --- a/src/main/java/org/isf/admission/gui/AdmittedPatientBrowser.java +++ b/src/main/java/org/isf/admission/gui/AdmittedPatientBrowser.java @@ -1206,15 +1206,11 @@ else if (patientClassBox.getSelectedItem().equals(patientClassItems[1])) { } // sex patient type - Character sex = null; - switch (patientSexBox.getSelectedIndex()) { - case 1: - sex = 'M'; - break; - case 2: - sex = 'F'; - break; - } + Character sex = switch (patientSexBox.getSelectedIndex()) { + case 1 -> 'M'; + case 2 -> 'F'; + default -> null; + }; if (sex != null && !sex.equals(ap.getPatient().getSex())) { continue; diff --git a/src/main/java/org/isf/admission/gui/PatientFolderBrowser.java b/src/main/java/org/isf/admission/gui/PatientFolderBrowser.java index ec84046472..6420b94444 100644 --- a/src/main/java/org/isf/admission/gui/PatientFolderBrowser.java +++ b/src/main/java/org/isf/admission/gui/PatientFolderBrowser.java @@ -452,19 +452,16 @@ public void mouseClicked(MouseEvent mouseEvent) { } } - if (selectedObject instanceof Admission) { + if (selectedObject instanceof Admission ad) { - Admission ad = (Admission) selectedObject; startDate = ad.getAdmDate(); endDate = ad.getDisDate(); - } else if (selectedObject instanceof Opd) { + } else if (selectedObject instanceof Opd opd) { - Opd opd = (Opd) selectedObject; startDate = opd.getDate(); - } else if (selectedObject instanceof PatientExamination) { - PatientExamination exam = (PatientExamination) selectedObject; + } else if (selectedObject instanceof PatientExamination exam) { startDate = exam.getPex_date(); } diff --git a/src/main/java/org/isf/medicalstock/gui/MovStockMultipleCharging.java b/src/main/java/org/isf/medicalstock/gui/MovStockMultipleCharging.java index 6fc884994c..90e5937876 100644 --- a/src/main/java/org/isf/medicalstock/gui/MovStockMultipleCharging.java +++ b/src/main/java/org/isf/medicalstock/gui/MovStockMultipleCharging.java @@ -140,7 +140,7 @@ public class MovStockMultipleCharging extends JDialog { }; private JComboBox comboBoxUnits = new JComboBox(qtyOption); private int optionSelected = UNITS; - private List updateLots = new ArrayList(); + private List updateLots = new ArrayList<>(); private final String[] lotSelectionColumnNames = { MessageBundle.getMessage("angal.medicalstock.lotid").toUpperCase(), MessageBundle.getMessage("angal.medicalstock.prepdate.col").toUpperCase(), 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/opd/gui/OpdEditExtended.java b/src/main/java/org/isf/opd/gui/OpdEditExtended.java index 4602a078bd..3c44beac58 100644 --- a/src/main/java/org/isf/opd/gui/OpdEditExtended.java +++ b/src/main/java/org/isf/opd/gui/OpdEditExtended.java @@ -445,8 +445,7 @@ private void setAttendance() { return; } Object selectedObject = diseaseBox1.getSelectedItem(); - if (selectedObject instanceof Disease) { - Disease disease = (Disease) selectedObject; + if (selectedObject instanceof Disease disease) { if (lastOPDDisease1 != null && disease.getCode().equals(lastOPDDisease1.getCode())) { rePatientButton.setSelected(true); } else { diff --git a/src/main/java/org/isf/patient/gui/PatientInsert.java b/src/main/java/org/isf/patient/gui/PatientInsert.java index 28878c1e3a..cd0d1f8a71 100644 --- a/src/main/java/org/isf/patient/gui/PatientInsert.java +++ b/src/main/java/org/isf/patient/gui/PatientInsert.java @@ -263,14 +263,11 @@ private JButton getJOkButton() { String name = jFirstNameTextField.getText() + ' ' + jSecondNameTextField.getText(); try { if (patientBrowserManager.isNamePresent(name)) { - switch (MessageDialog.yesNo(null, "angal.patient.thepatientisalreadypresent.msg")) { - case JOptionPane.OK_OPTION: - ok = true; - break; - case JOptionPane.NO_OPTION: - ok = false; - break; - } + ok = switch (MessageDialog.yesNo(null, "angal.patient.thepatientisalreadypresent.msg")) { + case JOptionPane.OK_OPTION -> true; + case JOptionPane.NO_OPTION -> false; + default -> ok; + }; } } catch (OHServiceException ex) { OHServiceExceptionUtil.showMessages(ex); @@ -320,14 +317,11 @@ private JButton getJOkButton() { if (!patient.getName().equals(name)) { try { if (patientBrowserManager.isNamePresent(name)) { - switch (MessageDialog.yesNo(null, "angal.patient.thepatientisalreadypresent.msg")) { - case JOptionPane.OK_OPTION: - ok = true; - break; - case JOptionPane.NO_OPTION: - ok = false; - break; - } + ok = switch (MessageDialog.yesNo(null, "angal.patient.thepatientisalreadypresent.msg")) { + case JOptionPane.OK_OPTION -> true; + case JOptionPane.NO_OPTION -> false; + default -> ok; + }; } } catch (OHServiceException ex) { OHServiceExceptionUtil.showMessages(ex); diff --git a/src/main/java/org/isf/patient/gui/PatientInsertExtended.java b/src/main/java/org/isf/patient/gui/PatientInsertExtended.java index 53a8a9901c..da5a0829c5 100644 --- a/src/main/java/org/isf/patient/gui/PatientInsertExtended.java +++ b/src/main/java/org/isf/patient/gui/PatientInsertExtended.java @@ -444,14 +444,11 @@ private JButton getJOkButton() { String name = firstName + ' ' + secondName; try { if (patientBrowserManager.isNamePresent(name)) { - switch (MessageDialog.yesNo(null, "angal.patient.thepatientisalreadypresent.msg")) { - case JOptionPane.OK_OPTION: - ok = true; - break; - case JOptionPane.NO_OPTION: - ok = false; - break; - } + ok = switch (MessageDialog.yesNo(null, "angal.patient.thepatientisalreadypresent.msg")) { + case JOptionPane.OK_OPTION -> true; + case JOptionPane.NO_OPTION -> false; + default -> ok; + }; } } catch (OHServiceException ex) { OHServiceExceptionUtil.showMessages(ex); diff --git a/src/main/java/org/isf/session/LoginEventListener.java b/src/main/java/org/isf/session/LoginEventListener.java index 54029aa21f..aec980cf45 100644 --- a/src/main/java/org/isf/session/LoginEventListener.java +++ b/src/main/java/org/isf/session/LoginEventListener.java @@ -30,8 +30,7 @@ public class LoginEventListener implements LoginListener { @Override public void loginInserted(AWTEvent e) { - if (e.getSource() instanceof User) { - User myUser = (User) e.getSource(); + if (e.getSource() instanceof User myUser) { RestartUserSession.setUser(myUser); RestartUserSession.getTimer().startTimer(); } 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; diff --git a/src/main/java/org/isf/therapy/gui/TherapyEdit.java b/src/main/java/org/isf/therapy/gui/TherapyEdit.java index 1e6855e163..1c1b612976 100644 --- a/src/main/java/org/isf/therapy/gui/TherapyEdit.java +++ b/src/main/java/org/isf/therapy/gui/TherapyEdit.java @@ -1142,14 +1142,12 @@ public void mouseClicked(MouseEvent e) { model = list.getModel(); for (int i = 0; i < model.getSize(); i++) { Object iteratedItem = model.getElementAt(i); - if (iteratedItem instanceof Therapy) { - Therapy aTherapy = (Therapy) iteratedItem; + if (iteratedItem instanceof Therapy aTherapy) { if (therapyID != 0 && aTherapy.getTherapyID() == therapyID) { list.setSelectedIndex(i); } } - if (iteratedItem instanceof Visit) { - Visit aVisit = (Visit) iteratedItem; + if (iteratedItem instanceof Visit aVisit) { if (visitID != 0 && aVisit.getVisitID() == visitID) { list.setSelectedIndex(i); } diff --git a/src/main/java/org/isf/utils/jobjects/OhTableDrugsModel.java b/src/main/java/org/isf/utils/jobjects/OhTableDrugsModel.java index 4d1d50b63f..ebfe1b2b8f 100644 --- a/src/main/java/org/isf/utils/jobjects/OhTableDrugsModel.java +++ b/src/main/java/org/isf/utils/jobjects/OhTableDrugsModel.java @@ -97,8 +97,7 @@ public Object getValueAt(int rowIndex, int columnIndex) { String value = ""; if (rowIndex >= 0 && rowIndex < this.filteredList.size()) { T obj = this.filteredList.get(rowIndex); - if (obj instanceof MovementWard) { - MovementWard drugObj = (MovementWard) obj; + if (obj instanceof MovementWard drugObj) { switch (columnIndex) { case 0: String dt; diff --git a/src/main/java/org/isf/utils/jobjects/OhTableModel.java b/src/main/java/org/isf/utils/jobjects/OhTableModel.java index d2780e654b..6ce43fc84c 100644 --- a/src/main/java/org/isf/utils/jobjects/OhTableModel.java +++ b/src/main/java/org/isf/utils/jobjects/OhTableModel.java @@ -67,8 +67,7 @@ public T filter(String searchQuery) throws OHException { for (T t : this.dataList) { Object object = t; - if (object instanceof Price) { - Price price = (Price) object; + if (object instanceof Price price) { String strItem = price.getItem() + price.getDesc(); if (allowSearchByCode && searchQuery.equalsIgnoreCase(price.getItem())) { T resPbj = (T) object; @@ -83,8 +82,7 @@ public T filter(String searchQuery) throws OHException { } } - if (object instanceof MedicalWard) { - MedicalWard mdw = (MedicalWard) object; + if (object instanceof MedicalWard mdw) { String strItem = mdw.getMedical().getProdCode() + mdw.getMedical().getDescription(); if (allowSearchByCode && searchQuery.equalsIgnoreCase(mdw.getMedical().getProdCode())) { @@ -101,8 +99,7 @@ public T filter(String searchQuery) throws OHException { } } - if (object instanceof PricesOthers) { - PricesOthers priceO = (PricesOthers) object; + if (object instanceof PricesOthers priceO) { String strItem = priceO.getCode() + priceO.getDescription(); if (allowSearchByCode && searchQuery.equalsIgnoreCase(priceO.getCode())) { @@ -119,8 +116,7 @@ public T filter(String searchQuery) throws OHException { } } - if (object instanceof BillItems) { - BillItems priceO = (BillItems) object; + if (object instanceof BillItems priceO) { String strItem = priceO.getItemDisplayCode() + priceO.getItemDescription(); if (allowSearchByCode && searchQuery.equalsIgnoreCase(priceO.getItemDisplayCode())) { @@ -188,24 +184,21 @@ public Object getValueAt(int rowIndex, int columnIndex) { String value = ""; if (rowIndex >= 0 && rowIndex < this.filteredList.size()) { T obj = this.filteredList.get(rowIndex); - if (obj instanceof Price) { - Price priceObj = (Price) obj; + if (obj instanceof Price priceObj) { if (columnIndex == 0) { value = priceObj.getItem() != null ? priceObj.getItem() : String.valueOf(priceObj.getId()); } else { value = priceObj.getDesc(); } } - if (obj instanceof MedicalWard) { - MedicalWard mdwObj = (MedicalWard) obj; + if (obj instanceof MedicalWard mdwObj) { if (columnIndex == 0) { value = mdwObj.getMedical().getProdCode() != null ? mdwObj.getMedical().getProdCode() : String.valueOf(mdwObj.getMedical().getCode()); } else { value = mdwObj.getMedical().getDescription(); } } - if (obj instanceof PricesOthers) { - PricesOthers mdwObj = (PricesOthers) obj; + if (obj instanceof PricesOthers mdwObj) { if (columnIndex == 0) { value = mdwObj.getCode() != null ? mdwObj.getCode() : String.valueOf(mdwObj.getId()); } else { @@ -213,8 +206,7 @@ public Object getValueAt(int rowIndex, int columnIndex) { } } - if (obj instanceof BillItems) { - BillItems mdwObj = (BillItems) obj; + if (obj instanceof BillItems mdwObj) { if (columnIndex == 0) { value = mdwObj.getItemDisplayCode() != null ? mdwObj.getItemDisplayCode() : String.valueOf(mdwObj.getId()); } else { diff --git a/src/main/java/org/isf/utils/jobjects/OhTableOperationModel.java b/src/main/java/org/isf/utils/jobjects/OhTableOperationModel.java index 812c360f46..6946646975 100644 --- a/src/main/java/org/isf/utils/jobjects/OhTableOperationModel.java +++ b/src/main/java/org/isf/utils/jobjects/OhTableOperationModel.java @@ -63,8 +63,7 @@ public int filter(String searchQuery) { for (T t : this.dataList) { Object object = t; - if (object instanceof OperationRow) { - OperationRow price = (OperationRow) object; + if (object instanceof OperationRow price) { String strItem = price.getOperation().getCode() + price.getOpResult(); strItem = strItem.toLowerCase(); searchQuery = searchQuery.toLowerCase(); @@ -126,8 +125,7 @@ public Object getValueAt(int rowIndex, int columnIndex) { String value = ""; if (rowIndex >= 0 && rowIndex < this.filteredList.size()) { T obj = this.filteredList.get(rowIndex); - if (obj instanceof OperationRow) { - OperationRow opdObj = (OperationRow) obj; + if (obj instanceof OperationRow opdObj) { switch (columnIndex) { case -1: return opdObj; diff --git a/src/main/java/org/isf/video/PhotoboothTester.java b/src/main/java/org/isf/video/PhotoboothTester.java index 994f13453e..878383f5ed 100644 --- a/src/main/java/org/isf/video/PhotoboothTester.java +++ b/src/main/java/org/isf/video/PhotoboothTester.java @@ -46,16 +46,14 @@ public static void main(final String[] args) { final PhotoboothPanelPresentationModel presentationModel = new PhotoboothPanelPresentationModel(); presentationModel.addBeanPropertyChangeListener(PhotoboothPanelModel.PROPERTY_IMAGE, propertyChangeEvent -> { final Object newValue = propertyChangeEvent.getNewValue(); - if (newValue instanceof BufferedImage) { - final BufferedImage bufferedImage = (BufferedImage) newValue; - LOGGER.info("New image is being set {}x{}", bufferedImage.getWidth(), bufferedImage.getHeight()); + if (newValue instanceof BufferedImage bufferedImage) { + LOGGER.info("New image is being set {}x{}", bufferedImage.getWidth(), bufferedImage.getHeight()); } }); presentationModel.addBeanPropertyChangeListener(PhotoboothPanelModel.PROPERTY_RESOLUTION, propertyChangeEvent -> { Object newValue = propertyChangeEvent.getNewValue(); - if (newValue instanceof Dimension) { - final Dimension newDimension = (Dimension) newValue; - LOGGER.info("New dimension is {}x{}", newDimension.getWidth(), newDimension.getHeight()); + if (newValue instanceof Dimension newDimension) { + LOGGER.info("New dimension is {}x{}", newDimension.getWidth(), newDimension.getHeight()); } }); diff --git a/src/main/java/org/isf/video/gui/PhotoboothComponentImpl.java b/src/main/java/org/isf/video/gui/PhotoboothComponentImpl.java index 644e091074..25c71ad390 100644 --- a/src/main/java/org/isf/video/gui/PhotoboothComponentImpl.java +++ b/src/main/java/org/isf/video/gui/PhotoboothComponentImpl.java @@ -58,9 +58,8 @@ public Component getListCellRendererComponent(final JList list, final boolean isSelected, final boolean cellHasFocus) { final Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); - if (value instanceof Dimension) { - final Dimension valueAsDimension = (Dimension) value; - setText(String.format("%d x %d", (int) valueAsDimension.getWidth(), (int) valueAsDimension.getHeight())); + if (value instanceof Dimension valueAsDimension) { + setText(String.format("%d x %d", (int) valueAsDimension.getWidth(), (int) valueAsDimension.getHeight())); } return component; } @@ -73,9 +72,8 @@ public Component getListCellRendererComponent(final JList list, final boolean isSelected, final boolean cellHasFocus) { final Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); - if (value instanceof Webcam) { - final Webcam webcam = (Webcam) value; - setText(webcam.getName()); + if (value instanceof Webcam webcam) { + setText(webcam.getName()); } return component; }