mirror of
https://github.com/tiennm99/BSK-All-in-One-Clinic-Management-System.git
synced 2026-10-11 03:12:53 +00:00
[refactor] Improve MedicineDialog and ServiceDialog to prevent unnecessary filtering during programmatic updates
This commit is contained in:
1 parent
6fbdff4007
commit
d2db80bf73
3 files changed
+42
-21
No files matched your search
+22
-11
@@ -45,6 +45,7 @@ public class MedicineDialog extends JDialog {
|
||||
private HashMap<String, Boolean> selectedMedicine = new HashMap<>();
|
||||
private JTable medicineTable;
|
||||
private JTable selectedTable;
|
||||
private boolean isProgrammaticallySettingMedicineNameField = false;
|
||||
|
||||
private String[][] medicinePrescription;
|
||||
private static final Logger logger = LoggerFactory.getLogger(MedicineDialog.class);
|
||||
@@ -344,9 +345,21 @@ public class MedicineDialog extends JDialog {
|
||||
add(bottomButtonPanel, BorderLayout.SOUTH);
|
||||
|
||||
medicineNameField.getDocument().addDocumentListener(new DocumentListener() {
|
||||
public void changedUpdate(DocumentEvent e) { SwingUtilities.invokeLater(() -> filterMedicineTable()); }
|
||||
public void removeUpdate(DocumentEvent e) { SwingUtilities.invokeLater(() -> filterMedicineTable()); }
|
||||
public void insertUpdate(DocumentEvent e) { SwingUtilities.invokeLater(() -> filterMedicineTable()); }
|
||||
public void changedUpdate(DocumentEvent e) {
|
||||
if (!isProgrammaticallySettingMedicineNameField) {
|
||||
SwingUtilities.invokeLater(() -> filterMedicineTable());
|
||||
}
|
||||
}
|
||||
public void removeUpdate(DocumentEvent e) {
|
||||
if (!isProgrammaticallySettingMedicineNameField) {
|
||||
SwingUtilities.invokeLater(() -> filterMedicineTable());
|
||||
}
|
||||
}
|
||||
public void insertUpdate(DocumentEvent e) {
|
||||
if (!isProgrammaticallySettingMedicineNameField) {
|
||||
SwingUtilities.invokeLater(() -> filterMedicineTable());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
medicineTable.addMouseListener(new MouseAdapter() {
|
||||
@@ -359,13 +372,6 @@ public class MedicineDialog extends JDialog {
|
||||
handleMedicineTableRowSelection(selectedRow);
|
||||
}
|
||||
});
|
||||
} else if (e.getClickCount() == 2) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
int selectedRow = medicineTable.getSelectedRow();
|
||||
if (selectedRow != -1) {
|
||||
addSelectedMedicine();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -462,12 +468,17 @@ public class MedicineDialog extends JDialog {
|
||||
return;
|
||||
}
|
||||
int modelRow = medicineTable.convertRowIndexToModel(viewRow);
|
||||
|
||||
isProgrammaticallySettingMedicineNameField = true;
|
||||
medicineNameField.setText(tableModel.getValueAt(modelRow, 1).toString());
|
||||
isProgrammaticallySettingMedicineNameField = false;
|
||||
|
||||
medicineCompanyField.setText(tableModel.getValueAt(modelRow, 2).toString());
|
||||
medicineDescriptionField.setText(tableModel.getValueAt(modelRow, 3).toString());
|
||||
quantityLeftField.setText(tableModel.getValueAt(modelRow, 4).toString());
|
||||
UnitComboBox.setSelectedItem(tableModel.getValueAt(modelRow, 5).toString());
|
||||
priceField.setText(tableModel.getValueAt(modelRow, 6).toString());
|
||||
medicineNameField.setText(tableModel.getValueAt(modelRow, 1).toString());
|
||||
|
||||
quantitySpinner.setValue(1);
|
||||
morningSpinner.setValue(0);
|
||||
noonSpinner.setValue(0);
|
||||
|
||||
+20
-10
@@ -39,6 +39,7 @@ public class ServiceDialog extends JDialog {
|
||||
private TableColumnModel columnModel;
|
||||
private JTable serviceTable;
|
||||
private JTable selectedTable;
|
||||
private boolean isProgrammaticallySettingNameField = false;
|
||||
|
||||
private String[][] servicePrescription;
|
||||
private static final Logger logger = LoggerFactory.getLogger(ServiceDialog.class);
|
||||
@@ -236,9 +237,21 @@ public class ServiceDialog extends JDialog {
|
||||
add(bottomButtonPanel, BorderLayout.SOUTH);
|
||||
|
||||
serviceNameField.getDocument().addDocumentListener(new DocumentListener() {
|
||||
public void changedUpdate(DocumentEvent e) { SwingUtilities.invokeLater(() -> filterServiceTable()); }
|
||||
public void removeUpdate(DocumentEvent e) { SwingUtilities.invokeLater(() -> filterServiceTable()); }
|
||||
public void insertUpdate(DocumentEvent e) { SwingUtilities.invokeLater(() -> filterServiceTable()); }
|
||||
public void changedUpdate(DocumentEvent e) {
|
||||
if (!isProgrammaticallySettingNameField) {
|
||||
SwingUtilities.invokeLater(() -> filterServiceTable());
|
||||
}
|
||||
}
|
||||
public void removeUpdate(DocumentEvent e) {
|
||||
if (!isProgrammaticallySettingNameField) {
|
||||
SwingUtilities.invokeLater(() -> filterServiceTable());
|
||||
}
|
||||
}
|
||||
public void insertUpdate(DocumentEvent e) {
|
||||
if (!isProgrammaticallySettingNameField) {
|
||||
SwingUtilities.invokeLater(() -> filterServiceTable());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
serviceTable.addMouseListener(new MouseAdapter() {
|
||||
@@ -251,13 +264,6 @@ public class ServiceDialog extends JDialog {
|
||||
handleServiceTableRowSelection(selectedRow);
|
||||
}
|
||||
});
|
||||
} else if (e.getClickCount() == 2) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
int selectedRow = serviceTable.getSelectedRow();
|
||||
if (selectedRow != -1) {
|
||||
addSelectedService();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -363,7 +369,11 @@ public class ServiceDialog extends JDialog {
|
||||
return;
|
||||
}
|
||||
int modelRow = serviceTable.convertRowIndexToModel(viewRow);
|
||||
|
||||
isProgrammaticallySettingNameField = true;
|
||||
serviceNameField.setText(tableModel.getValueAt(modelRow, 1).toString());
|
||||
isProgrammaticallySettingNameField = false;
|
||||
|
||||
priceField.setText(tableModel.getValueAt(modelRow, 2).toString());
|
||||
quantitySpinner.setValue(1);
|
||||
noteField.setText("");
|
||||
|
||||
Reference in new issue
Block a user