From 19b19701ae7c348634d0d35fe111605731d1e97c Mon Sep 17 00:00:00 2001 From: ArnaudFofou Date: Wed, 11 Dec 2024 08:26:47 +0100 Subject: [PATCH 1/4] update InventoryEdit --- .../medicalinventory/gui/InventoryEdit.java | 52 +++++++++++++++++-- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryEdit.java b/src/main/java/org/isf/medicalinventory/gui/InventoryEdit.java index fd96f6dfb2..6fc6ebf609 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryEdit.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryEdit.java @@ -950,15 +950,12 @@ private JButton getCleanTableButton() { if (inventory != null) { List invRows = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventory.getId()); medicalInventoryRowManager.deleteMedicalInventoryRows(invRows); - inventoryRowSearchList.clear(); - } else { - inventoryRowSearchList.clear(); } } catch (OHServiceException e) { OHServiceExceptionUtil.showMessages(e); } - inventoryRowSearchList = new ArrayList<>(); + inventoryRowSearchList.clear(); DefaultTableModel model = (DefaultTableModel) jTableInventoryRow.getModel(); model.setRowCount(0); model.setColumnCount(0); @@ -2192,6 +2189,51 @@ private boolean areAllMedicalsInInventory() throws OHServiceException { } private void initializeActions() { + actions.put(radioButtonAll, () -> handleInventoryUpdate( + medicalTypeSelected.getDescription().equals(MessageBundle.getMessage("angal.common.all.txt")), + null, null, "angal.invetory.allmedicaladdedsuccessfully.msg" + )); + + actions.put(radioOnlyNonZero, () -> handleInventoryUpdate( + medicalTypeSelected.getDescription().equals(MessageBundle.getMessage("angal.common.all.txt")), + true, medicalTypeSelected, "angal.invetory.tablehasbeenupdated.msg" + )); + + actions.put(radioWithMovement, () -> handleInventoryUpdate( + medicalTypeSelected.getDescription().equals(MessageBundle.getMessage("angal.common.all.txt")), + null, medicalTypeSelected, "angal.invetory.tablehasbeenupdated.msg" + )); + } + + private void handleInventoryUpdate(boolean isAllSelected, Boolean withNoZeroQty, MedicalType medType, String successMessage) { + try { + if (areAllMedicalsInInventory()) { + MessageDialog.info(null, "angal.inventory.allmedicalsarealreadyin.msg"); + return; + } + + int info = (!inventoryRowSearchList.isEmpty()) + ? MessageDialog.yesNo(null, "angal.inventoryrow.doyouwanttoaddallnotyetlistedproducts.msg") + : JOptionPane.YES_OPTION; + + if (info == JOptionPane.YES_OPTION) { + InventoryRowModel model; + if (isAllSelected) { + model = new InventoryRowModel(withNoZeroQty != null ? withNoZeroQty : true); + } else { + model = new InventoryRowModel(medType, withNoZeroQty != null); + } + + jTableInventoryRow.setModel(model); + fireInventoryUpdated(); + adjustWidth(); + MessageDialog.info(null, successMessage); + } + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + } + } + /*private void initializeActions() { actions.put(radioButtonAll, () -> { if (medicalTypeSelected.getDescription().equals(MessageBundle.getMessage("angal.common.all.txt"))) { try { @@ -2310,5 +2352,5 @@ private void initializeActions() { } } }); - } + }*/ } From b2e259cac96d9efcfa602fe1830143c9c31d59e2 Mon Sep 17 00:00:00 2001 From: ArnaudFofou Date: Fri, 20 Dec 2024 10:03:00 +0100 Subject: [PATCH 2/4] enhance product selection --- .../medicalinventory/gui/InventoryEdit.java | 282 +++++------------- 1 file changed, 77 insertions(+), 205 deletions(-) diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryEdit.java b/src/main/java/org/isf/medicalinventory/gui/InventoryEdit.java index 6fc6ebf609..0e6d1e04ed 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryEdit.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryEdit.java @@ -243,6 +243,7 @@ private void fireInventoryUpdated() { private JComboBox medicalTypeComboBox; private List medicals = new ArrayList<>(); private Map actions = new HashMap<>(); + private boolean noData = false; private MedicalInventoryManager medicalInventoryManager = Context.getApplicationContext().getBean(MedicalInventoryManager.class); private MedicalInventoryRowManager medicalInventoryRowManager = Context.getApplicationContext().getBean(MedicalInventoryRowManager.class); private MedicalBrowsingManager medicalBrowsingManager = Context.getApplicationContext().getBean(MedicalBrowsingManager.class); @@ -1187,60 +1188,56 @@ class InventoryRowModel extends DefaultTableModel { private static final long serialVersionUID = 1L; - public InventoryRowModel(boolean add) throws OHServiceException { - inventoryRowList = loadNewInventoryTable(null, inventory, add); - if (!inventoryRowList.isEmpty()) { - for (MedicalInventoryRow invRow : inventoryRowList) { - addMedInRowInInventorySearchList(invRow); - } - } - } - public InventoryRowModel() throws OHServiceException { - inventoryRowSearchList.clear(); - if (inventory != null) { - inventoryRowList = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventory.getId()); - } - if (!inventoryRowList.isEmpty()) { - for (MedicalInventoryRow invRow : inventoryRowList) { - addMedInRowInInventorySearchList(invRow); - if (invRow.getId() == 0) { - inventoryRowListAdded.add(invRow); - } - } - } - } + this(null, false, false, false); + } - public InventoryRowModel(MedicalType medType) throws OHServiceException { - inventoryRowList = loadNewInventoryTableByMedicalType(medType); - if (!inventoryRowList.isEmpty()) { - for (MedicalInventoryRow invRow : inventoryRowList) { - addMedInRowInInventorySearchList(invRow); - } - } - } + public InventoryRowModel(boolean add) throws OHServiceException { + this(null, false, add, false); + } - public InventoryRowModel(boolean withNoZeroQty, MedicalType medType) throws OHServiceException { - inventoryRowList = loadNewInventoryTable(withNoZeroQty, medType); - if (!inventoryRowList.isEmpty()) { - for (MedicalInventoryRow invRow : inventoryRowList) { - addMedInRowInInventorySearchList(invRow); - } - } else { - MessageDialog.info(null, "angal.invetory.notdataforthatfilter.msg"); - } - } + public InventoryRowModel(MedicalType medType) throws OHServiceException { + this(medType, false, false, false); + } - public InventoryRowModel(MedicalType medType, boolean withMovement) throws OHServiceException { - inventoryRowList = loadNewInventoryTable(medType); - if (!inventoryRowList.isEmpty()) { - for (MedicalInventoryRow invRow : inventoryRowList) { - addMedInRowInInventorySearchList(invRow); - } - } else { - MessageDialog.info(null, "angal.invetory.notdataforthatfilter.msg"); - } - } + public InventoryRowModel(boolean withNoZeroQty, MedicalType medType) throws OHServiceException { + this(medType, withNoZeroQty, false, false); + } + + public InventoryRowModel(MedicalType medType, boolean withMovement) throws OHServiceException { + this(medType, false, false, withMovement); + } + + public InventoryRowModel(MedicalType medType, boolean withNoZeroQty, boolean add, boolean withMovement) throws OHServiceException { + if (add) { + inventoryRowList = loadNewInventoryTable(null, inventory, true); + } else if (withMovement) { + inventoryRowList = loadNewInventoryTable(medType); + } else if (withNoZeroQty) { + inventoryRowList = loadNewInventoryTable(withNoZeroQty, medType); + } else if (medType != null) { + inventoryRowList = loadNewInventoryTableByMedicalType(medType); + } else { + inventoryRowSearchList.clear(); + if (inventory != null) { + inventoryRowList = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventory.getId()); + } + } + + if (!inventoryRowList.isEmpty()) { + for (MedicalInventoryRow invRow : inventoryRowList) { + addMedInRowInInventorySearchList(invRow); + if (!add && invRow.getId() == 0) { + inventoryRowListAdded.add(invRow); + } + } + } else { + if (!mode.equals("new")) { + noData = true; + MessageDialog.info(null, "angal.invetory.notdataforthatfilter.msg"); + } + } + } public Class< ? > getColumnClass(int c) { if (c == 0) { @@ -2189,168 +2186,43 @@ private boolean areAllMedicalsInInventory() throws OHServiceException { } private void initializeActions() { - actions.put(radioButtonAll, () -> handleInventoryUpdate( - medicalTypeSelected.getDescription().equals(MessageBundle.getMessage("angal.common.all.txt")), - null, null, "angal.invetory.allmedicaladdedsuccessfully.msg" - )); - - actions.put(radioOnlyNonZero, () -> handleInventoryUpdate( - medicalTypeSelected.getDescription().equals(MessageBundle.getMessage("angal.common.all.txt")), - true, medicalTypeSelected, "angal.invetory.tablehasbeenupdated.msg" - )); - - actions.put(radioWithMovement, () -> handleInventoryUpdate( - medicalTypeSelected.getDescription().equals(MessageBundle.getMessage("angal.common.all.txt")), - null, medicalTypeSelected, "angal.invetory.tablehasbeenupdated.msg" - )); + actions.put(radioButtonAll, () -> handleInventoryUpdate(true, false, false)); + actions.put(radioOnlyNonZero, () -> handleInventoryUpdate(false, false, true)); + actions.put(radioWithMovement, () -> handleInventoryUpdate(false, true, false)); + noData = false; } - private void handleInventoryUpdate(boolean isAllSelected, Boolean withNoZeroQty, MedicalType medType, String successMessage) { - try { - if (areAllMedicalsInInventory()) { - MessageDialog.info(null, "angal.inventory.allmedicalsarealreadyin.msg"); - return; - } - - int info = (!inventoryRowSearchList.isEmpty()) - ? MessageDialog.yesNo(null, "angal.inventoryrow.doyouwanttoaddallnotyetlistedproducts.msg") - : JOptionPane.YES_OPTION; + private void handleInventoryUpdate(boolean includeAll, boolean withMovement, boolean nonZero) { + boolean isAllSelected = medicalTypeSelected.getDescription().equals(MessageBundle.getMessage("angal.common.all.txt")); + MedicalType medType = isAllSelected ? null : (MedicalType) medicalTypeComboBox.getSelectedItem(); - if (info == JOptionPane.YES_OPTION) { - InventoryRowModel model; - if (isAllSelected) { - model = new InventoryRowModel(withNoZeroQty != null ? withNoZeroQty : true); - } else { - model = new InventoryRowModel(medType, withNoZeroQty != null); + try { + if (!areAllMedicalsInInventory()) { + int userChoice = (!inventoryRowSearchList.isEmpty()) + ? MessageDialog.yesNo(null, "angal.inventoryrow.doyouwanttoaddallnotyetlistedproducts.msg") + : JOptionPane.YES_OPTION; + + if (userChoice == JOptionPane.YES_OPTION) { + jTableInventoryRow.setModel(new InventoryRowModel(medType, nonZero,includeAll, withMovement)); + fireInventoryUpdated(); + adjustWidth(); + showUpdateSuccessMessage(); } - - jTableInventoryRow.setModel(model); - fireInventoryUpdated(); - adjustWidth(); - MessageDialog.info(null, successMessage); + } else { + MessageDialog.info(null, "angal.inventory.youhavealreadyaddedallproduct.msg"); } } catch (OHServiceException e) { OHServiceExceptionUtil.showMessages(e); } } - /*private void initializeActions() { - actions.put(radioButtonAll, () -> { - if (medicalTypeSelected.getDescription().equals(MessageBundle.getMessage("angal.common.all.txt"))) { - try { - if (!areAllMedicalsInInventory()) { - int info = (!inventoryRowSearchList.isEmpty()) ? MessageDialog.yesNo(null, "angal.inventoryrow.doyouwanttoaddallnotyetlistedproducts.msg") : JOptionPane.YES_OPTION; - if (info == JOptionPane.YES_OPTION) { - jTableInventoryRow.setModel(new InventoryRowModel(true)); - } - fireInventoryUpdated(); - adjustWidth(); - MessageDialog.info(null, "angal.invetory.allmedicaladdedsuccessfully.msg"); - } else { - MessageDialog.info(null, "angal.inventory.youhavealreadyaddedallproduct.msg"); - } - } catch (OHServiceException e) { - OHServiceExceptionUtil.showMessages(e); - } - } else { - try { - if (!areAllMedicalsInInventory()) { - int info = (!inventoryRowSearchList.isEmpty()) ? MessageDialog.yesNo(null, "angal.inventoryrow.doyouwanttoaddallnotyetlistedproducts.msg") : JOptionPane.YES_OPTION; - if (info == JOptionPane.YES_OPTION) { - MedicalType medType = (MedicalType)medicalTypeComboBox.getSelectedItem(); - jTableInventoryRow.setModel(new InventoryRowModel(medType)); - } - fireInventoryUpdated(); - adjustWidth(); - MessageDialog.info(null, "angal.invetory.tablehasbeenupdated.msg"); - } else { - MessageDialog.info(null, "angal.inventory.youhavealreadyaddedallproduct.msg"); - } - } catch (OHServiceException e) { - OHServiceExceptionUtil.showMessages(e); - } - } - }); - - actions.put(radioOnlyNonZero, () -> { - if (medicalTypeSelected.getDescription().equals(MessageBundle.getMessage("angal.common.all.txt"))) { - try { - if (!areAllMedicalsInInventory()) { - int info = (!inventoryRowSearchList.isEmpty()) ? MessageDialog.yesNo(null, "angal.inventoryrow.doyouwanttoaddallnotyetlistedproducts.msg") : JOptionPane.YES_OPTION; - if (info == JOptionPane.YES_OPTION) { - jTableInventoryRow.setModel(new InventoryRowModel(true, null)); - } - fireInventoryUpdated(); - adjustWidth(); - if (!inventoryRowList.isEmpty()) { - MessageDialog.info(null, "angal.invetory.tablehasbeenupdated.msg"); - } - } else { - MessageDialog.info(null, "angal.inventory.youhavealreadyaddedallproduct.msg"); - } - } catch (OHServiceException e) { - OHServiceExceptionUtil.showMessages(e); - } - } else { - try { - if (!areAllMedicalsInInventory()) { - int info = (!inventoryRowSearchList.isEmpty()) ? MessageDialog.yesNo(null, "angal.inventoryrow.doyouwanttoaddallnotyetlistedproducts.msg") : JOptionPane.YES_OPTION; - if (info == JOptionPane.YES_OPTION) { - MedicalType medType = (MedicalType)medicalTypeComboBox.getSelectedItem(); - jTableInventoryRow.setModel(new InventoryRowModel(true, medType)); - fireInventoryUpdated(); - adjustWidth(); - if (!inventoryRowList.isEmpty()) { - MessageDialog.info(null, "angal.invetory.tablehasbeenupdated.msg"); - } - } - } else { - MessageDialog.info(null, "angal.inventory.youhavealreadyaddedallproduct.msg"); - } - } catch (OHServiceException e) { - OHServiceExceptionUtil.showMessages(e); - } - } - }); - - actions.put(radioWithMovement, () -> { - if (medicalTypeSelected.getDescription().equals(MessageBundle.getMessage("angal.common.all.txt"))) { - try { - if (!areAllMedicalsInInventory()) { - int info = (!inventoryRowSearchList.isEmpty()) ? MessageDialog.yesNo(null, "angal.inventoryrow.doyouwanttoaddallnotyetlistedproducts.msg") : JOptionPane.YES_OPTION; - if (info == JOptionPane.YES_OPTION) { - jTableInventoryRow.setModel(new InventoryRowModel(null, true)); - fireInventoryUpdated(); - adjustWidth(); - if (!inventoryRowList.isEmpty()) { - MessageDialog.info(null, "angal.invetory.tablehasbeenupdated.msg"); - } - } - } else { - MessageDialog.info(null, "angal.inventory.youhavealreadyaddedallproduct.msg"); - } - } catch (OHServiceException e) { - OHServiceExceptionUtil.showMessages(e); - } - } else { - try { - if (!areAllMedicalsInInventory()) { - int info = (!inventoryRowSearchList.isEmpty()) ? MessageDialog.yesNo(null, "angal.inventoryrow.doyouwanttoaddallnotyetlistedproducts.msg") : JOptionPane.YES_OPTION; - if (info == JOptionPane.YES_OPTION) { - MedicalType medType = (MedicalType)medicalTypeComboBox.getSelectedItem(); - jTableInventoryRow.setModel(new InventoryRowModel(medType, true)); - fireInventoryUpdated(); - adjustWidth(); - if (!inventoryRowList.isEmpty()) { - MessageDialog.info(null, "angal.invetory.tablehasbeenupdated.msg"); - } - } - } else { - MessageDialog.info(null, "angal.inventory.youhavealreadyaddedallproduct.msg"); - } - } catch (OHServiceException e) { - OHServiceExceptionUtil.showMessages(e); - } - } - }); - }*/ + + private void showUpdateSuccessMessage() { + if (!inventoryRowList.isEmpty()) { + MessageDialog.info(null, "angal.invetory.tablehasbeenupdated.msg"); + } else { + if (!noData) { + MessageDialog.info(null, "angal.invetory.allmedicaladdedsuccessfully.msg"); + } + } + } } From 7fa3d5dcb52819bfc75daa8b239d96af7c85b429 Mon Sep 17 00:00:00 2001 From: ArnaudFofou Date: Fri, 20 Dec 2024 11:50:42 +0100 Subject: [PATCH 3/4] update src/main/java/org/isf/medicalinventory/gui/InventoryEdit.java --- .../medicalinventory/gui/InventoryEdit.java | 153 ++++++++++++++++-- 1 file changed, 137 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryEdit.java b/src/main/java/org/isf/medicalinventory/gui/InventoryEdit.java index 0e6d1e04ed..9648801a45 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryEdit.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryEdit.java @@ -243,7 +243,6 @@ private void fireInventoryUpdated() { private JComboBox medicalTypeComboBox; private List medicals = new ArrayList<>(); private Map actions = new HashMap<>(); - private boolean noData = false; private MedicalInventoryManager medicalInventoryManager = Context.getApplicationContext().getBean(MedicalInventoryManager.class); private MedicalInventoryRowManager medicalInventoryRowManager = Context.getApplicationContext().getBean(MedicalInventoryRowManager.class); private MedicalBrowsingManager medicalBrowsingManager = Context.getApplicationContext().getBean(MedicalBrowsingManager.class); @@ -1207,16 +1206,22 @@ public InventoryRowModel(boolean withNoZeroQty, MedicalType medType) throws OHSe public InventoryRowModel(MedicalType medType, boolean withMovement) throws OHServiceException { this(medType, false, false, withMovement); } - - public InventoryRowModel(MedicalType medType, boolean withNoZeroQty, boolean add, boolean withMovement) throws OHServiceException { - if (add) { - inventoryRowList = loadNewInventoryTable(null, inventory, true); + + public InventoryRowModel(MedicalType medType, boolean withNoZeroQty, boolean includeAll, boolean withMovement) throws OHServiceException { + if (includeAll) { + if (medType == null) { + inventoryRowList = loadNewInventoryTable(null, inventory, true); + } else { + inventoryRowList = loadNewInventoryTableByMedicalType(medType); + } } else if (withMovement) { - inventoryRowList = loadNewInventoryTable(medType); + inventoryRowList = loadNewInventoryTable(medType); } else if (withNoZeroQty) { - inventoryRowList = loadNewInventoryTable(withNoZeroQty, medType); - } else if (medType != null) { - inventoryRowList = loadNewInventoryTableByMedicalType(medType); + if (medType == null) { + inventoryRowList = loadNewInventoryTable(true, null); + } else { + inventoryRowList = loadNewInventoryTable(true, medType); + } } else { inventoryRowSearchList.clear(); if (inventory != null) { @@ -1227,13 +1232,12 @@ public InventoryRowModel(MedicalType medType, boolean withNoZeroQty, boolean add if (!inventoryRowList.isEmpty()) { for (MedicalInventoryRow invRow : inventoryRowList) { addMedInRowInInventorySearchList(invRow); - if (!add && invRow.getId() == 0) { + if (!includeAll && invRow.getId() == 0) { inventoryRowListAdded.add(invRow); } } } else { if (!mode.equals("new")) { - noData = true; MessageDialog.info(null, "angal.invetory.notdataforthatfilter.msg"); } } @@ -2189,7 +2193,6 @@ private void initializeActions() { actions.put(radioButtonAll, () -> handleInventoryUpdate(true, false, false)); actions.put(radioOnlyNonZero, () -> handleInventoryUpdate(false, false, true)); actions.put(radioWithMovement, () -> handleInventoryUpdate(false, true, false)); - noData = false; } private void handleInventoryUpdate(boolean includeAll, boolean withMovement, boolean nonZero) { @@ -2203,7 +2206,7 @@ private void handleInventoryUpdate(boolean includeAll, boolean withMovement, boo : JOptionPane.YES_OPTION; if (userChoice == JOptionPane.YES_OPTION) { - jTableInventoryRow.setModel(new InventoryRowModel(medType, nonZero,includeAll, withMovement)); + jTableInventoryRow.setModel(new InventoryRowModel(medType, nonZero, includeAll, withMovement)); fireInventoryUpdated(); adjustWidth(); showUpdateSuccessMessage(); @@ -2220,9 +2223,127 @@ private void showUpdateSuccessMessage() { if (!inventoryRowList.isEmpty()) { MessageDialog.info(null, "angal.invetory.tablehasbeenupdated.msg"); } else { - if (!noData) { - MessageDialog.info(null, "angal.invetory.allmedicaladdedsuccessfully.msg"); - } + MessageDialog.info(null, "angal.invetory.notdataforthatfilter.msg"); } } + /*private void initializeActions() { + actions.put(radioButtonAll, () -> { + if (medicalTypeSelected.getDescription().equals(MessageBundle.getMessage("angal.common.all.txt"))) { + try { + if (!areAllMedicalsInInventory()) { + int info = (!inventoryRowSearchList.isEmpty()) ? MessageDialog.yesNo(null, "angal.inventoryrow.doyouwanttoaddallnotyetlistedproducts.msg") : JOptionPane.YES_OPTION; + if (info == JOptionPane.YES_OPTION) { + jTableInventoryRow.setModel(new InventoryRowModel(true)); + } + fireInventoryUpdated(); + adjustWidth(); + MessageDialog.info(null, "angal.invetory.allmedicaladdedsuccessfully.msg"); + } else { + MessageDialog.info(null, "angal.inventory.youhavealreadyaddedallproduct.msg"); + } + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + } + } else { + try { + if (!areAllMedicalsInInventory()) { + int info = (!inventoryRowSearchList.isEmpty()) ? MessageDialog.yesNo(null, "angal.inventoryrow.doyouwanttoaddallnotyetlistedproducts.msg") : JOptionPane.YES_OPTION; + if (info == JOptionPane.YES_OPTION) { + MedicalType medType = (MedicalType)medicalTypeComboBox.getSelectedItem(); + jTableInventoryRow.setModel(new InventoryRowModel(medType)); + } + fireInventoryUpdated(); + adjustWidth(); + MessageDialog.info(null, "angal.invetory.tablehasbeenupdated.msg"); + } else { + MessageDialog.info(null, "angal.inventory.youhavealreadyaddedallproduct.msg"); + } + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + } + } + }); + + actions.put(radioOnlyNonZero, () -> { + if (medicalTypeSelected.getDescription().equals(MessageBundle.getMessage("angal.common.all.txt"))) { + try { + if (!areAllMedicalsInInventory()) { + int info = (!inventoryRowSearchList.isEmpty()) ? MessageDialog.yesNo(null, "angal.inventoryrow.doyouwanttoaddallnotyetlistedproducts.msg") : JOptionPane.YES_OPTION; + if (info == JOptionPane.YES_OPTION) { + jTableInventoryRow.setModel(new InventoryRowModel(true, null)); + } + fireInventoryUpdated(); + adjustWidth(); + if (!inventoryRowList.isEmpty()) { + MessageDialog.info(null, "angal.invetory.tablehasbeenupdated.msg"); + } + } else { + MessageDialog.info(null, "angal.inventory.youhavealreadyaddedallproduct.msg"); + } + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + } + } else { + try { + if (!areAllMedicalsInInventory()) { + int info = (!inventoryRowSearchList.isEmpty()) ? MessageDialog.yesNo(null, "angal.inventoryrow.doyouwanttoaddallnotyetlistedproducts.msg") : JOptionPane.YES_OPTION; + if (info == JOptionPane.YES_OPTION) { + MedicalType medType = (MedicalType)medicalTypeComboBox.getSelectedItem(); + jTableInventoryRow.setModel(new InventoryRowModel(true, medType)); + fireInventoryUpdated(); + adjustWidth(); + if (!inventoryRowList.isEmpty()) { + MessageDialog.info(null, "angal.invetory.tablehasbeenupdated.msg"); + } + } + } else { + MessageDialog.info(null, "angal.inventory.youhavealreadyaddedallproduct.msg"); + } + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + } + } + }); + + actions.put(radioWithMovement, () -> { + if (medicalTypeSelected.getDescription().equals(MessageBundle.getMessage("angal.common.all.txt"))) { + try { + if (!areAllMedicalsInInventory()) { + int info = (!inventoryRowSearchList.isEmpty()) ? MessageDialog.yesNo(null, "angal.inventoryrow.doyouwanttoaddallnotyetlistedproducts.msg") : JOptionPane.YES_OPTION; + if (info == JOptionPane.YES_OPTION) { + jTableInventoryRow.setModel(new InventoryRowModel(null, true)); + fireInventoryUpdated(); + adjustWidth(); + if (!inventoryRowList.isEmpty()) { + MessageDialog.info(null, "angal.invetory.tablehasbeenupdated.msg"); + } + } + } else { + MessageDialog.info(null, "angal.inventory.youhavealreadyaddedallproduct.msg"); + } + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + } + } else { + try { + if (!areAllMedicalsInInventory()) { + int info = (!inventoryRowSearchList.isEmpty()) ? MessageDialog.yesNo(null, "angal.inventoryrow.doyouwanttoaddallnotyetlistedproducts.msg") : JOptionPane.YES_OPTION; + if (info == JOptionPane.YES_OPTION) { + MedicalType medType = (MedicalType)medicalTypeComboBox.getSelectedItem(); + jTableInventoryRow.setModel(new InventoryRowModel(medType, true)); + fireInventoryUpdated(); + adjustWidth(); + if (!inventoryRowList.isEmpty()) { + MessageDialog.info(null, "angal.invetory.tablehasbeenupdated.msg"); + } + } + } else { + MessageDialog.info(null, "angal.inventory.youhavealreadyaddedallproduct.msg"); + } + } catch (OHServiceException e) { + OHServiceExceptionUtil.showMessages(e); + } + } + }); + }*/ } From f0fc4aaae6504721349a2c2f264a26bef77dae7f Mon Sep 17 00:00:00 2001 From: ArnaudFofou Date: Fri, 20 Dec 2024 11:59:30 +0100 Subject: [PATCH 4/4] enhance code and avoid duplicated instruction --- .../medicalinventory/gui/InventoryEdit.java | 121 ------------------ 1 file changed, 121 deletions(-) diff --git a/src/main/java/org/isf/medicalinventory/gui/InventoryEdit.java b/src/main/java/org/isf/medicalinventory/gui/InventoryEdit.java index 0ba2b208db..a3e4bf4073 100644 --- a/src/main/java/org/isf/medicalinventory/gui/InventoryEdit.java +++ b/src/main/java/org/isf/medicalinventory/gui/InventoryEdit.java @@ -2194,7 +2194,6 @@ private void handleInventoryUpdate(boolean includeAll, boolean withMovement, boo if (userChoice == JOptionPane.YES_OPTION) { jTableInventoryRow.setModel(new InventoryRowModel(medType, nonZero, includeAll, withMovement)); fireInventoryUpdated(); - adjustWidth(); showUpdateSuccessMessage(); } } else { @@ -2212,124 +2211,4 @@ private void showUpdateSuccessMessage() { MessageDialog.info(null, "angal.invetory.notdataforthatfilter.msg"); } } - /*private void initializeActions() { - actions.put(radioButtonAll, () -> { - if (medicalTypeSelected.getDescription().equals(MessageBundle.getMessage("angal.common.all.txt"))) { - try { - if (!areAllMedicalsInInventory()) { - int info = (!inventoryRowSearchList.isEmpty()) ? MessageDialog.yesNo(null, "angal.inventoryrow.doyouwanttoaddallnotyetlistedproducts.msg") : JOptionPane.YES_OPTION; - if (info == JOptionPane.YES_OPTION) { - jTableInventoryRow.setModel(new InventoryRowModel(true)); - } - fireInventoryUpdated(); - adjustWidth(); - MessageDialog.info(null, "angal.invetory.allmedicaladdedsuccessfully.msg"); - } else { - MessageDialog.info(null, "angal.inventory.youhavealreadyaddedallproduct.msg"); - } - } catch (OHServiceException e) { - OHServiceExceptionUtil.showMessages(e); - } - } else { - try { - if (!areAllMedicalsInInventory()) { - int info = (!inventoryRowSearchList.isEmpty()) ? MessageDialog.yesNo(null, "angal.inventoryrow.doyouwanttoaddallnotyetlistedproducts.msg") : JOptionPane.YES_OPTION; - if (info == JOptionPane.YES_OPTION) { - MedicalType medType = (MedicalType)medicalTypeComboBox.getSelectedItem(); - jTableInventoryRow.setModel(new InventoryRowModel(medType)); - } - fireInventoryUpdated(); - adjustWidth(); - MessageDialog.info(null, "angal.invetory.tablehasbeenupdated.msg"); - } else { - MessageDialog.info(null, "angal.inventory.youhavealreadyaddedallproduct.msg"); - } - } catch (OHServiceException e) { - OHServiceExceptionUtil.showMessages(e); - } - } - }); - - actions.put(radioOnlyNonZero, () -> { - if (medicalTypeSelected.getDescription().equals(MessageBundle.getMessage("angal.common.all.txt"))) { - try { - if (!areAllMedicalsInInventory()) { - int info = (!inventoryRowSearchList.isEmpty()) ? MessageDialog.yesNo(null, "angal.inventoryrow.doyouwanttoaddallnotyetlistedproducts.msg") : JOptionPane.YES_OPTION; - if (info == JOptionPane.YES_OPTION) { - jTableInventoryRow.setModel(new InventoryRowModel(true, null)); - } - fireInventoryUpdated(); - adjustWidth(); - if (!inventoryRowList.isEmpty()) { - MessageDialog.info(null, "angal.invetory.tablehasbeenupdated.msg"); - } - } else { - MessageDialog.info(null, "angal.inventory.youhavealreadyaddedallproduct.msg"); - } - } catch (OHServiceException e) { - OHServiceExceptionUtil.showMessages(e); - } - } else { - try { - if (!areAllMedicalsInInventory()) { - int info = (!inventoryRowSearchList.isEmpty()) ? MessageDialog.yesNo(null, "angal.inventoryrow.doyouwanttoaddallnotyetlistedproducts.msg") : JOptionPane.YES_OPTION; - if (info == JOptionPane.YES_OPTION) { - MedicalType medType = (MedicalType)medicalTypeComboBox.getSelectedItem(); - jTableInventoryRow.setModel(new InventoryRowModel(true, medType)); - fireInventoryUpdated(); - adjustWidth(); - if (!inventoryRowList.isEmpty()) { - MessageDialog.info(null, "angal.invetory.tablehasbeenupdated.msg"); - } - } - } else { - MessageDialog.info(null, "angal.inventory.youhavealreadyaddedallproduct.msg"); - } - } catch (OHServiceException e) { - OHServiceExceptionUtil.showMessages(e); - } - } - }); - - actions.put(radioWithMovement, () -> { - if (medicalTypeSelected.getDescription().equals(MessageBundle.getMessage("angal.common.all.txt"))) { - try { - if (!areAllMedicalsInInventory()) { - int info = (!inventoryRowSearchList.isEmpty()) ? MessageDialog.yesNo(null, "angal.inventoryrow.doyouwanttoaddallnotyetlistedproducts.msg") : JOptionPane.YES_OPTION; - if (info == JOptionPane.YES_OPTION) { - jTableInventoryRow.setModel(new InventoryRowModel(null, true)); - fireInventoryUpdated(); - adjustWidth(); - if (!inventoryRowList.isEmpty()) { - MessageDialog.info(null, "angal.invetory.tablehasbeenupdated.msg"); - } - } - } else { - MessageDialog.info(null, "angal.inventory.youhavealreadyaddedallproduct.msg"); - } - } catch (OHServiceException e) { - OHServiceExceptionUtil.showMessages(e); - } - } else { - try { - if (!areAllMedicalsInInventory()) { - int info = (!inventoryRowSearchList.isEmpty()) ? MessageDialog.yesNo(null, "angal.inventoryrow.doyouwanttoaddallnotyetlistedproducts.msg") : JOptionPane.YES_OPTION; - if (info == JOptionPane.YES_OPTION) { - MedicalType medType = (MedicalType)medicalTypeComboBox.getSelectedItem(); - jTableInventoryRow.setModel(new InventoryRowModel(medType, true)); - fireInventoryUpdated(); - adjustWidth(); - if (!inventoryRowList.isEmpty()) { - MessageDialog.info(null, "angal.invetory.tablehasbeenupdated.msg"); - } - } - } else { - MessageDialog.info(null, "angal.inventory.youhavealreadyaddedallproduct.msg"); - } - } catch (OHServiceException e) { - OHServiceExceptionUtil.showMessages(e); - } - } - }); - }*/ }