Skip to content

Commit

Permalink
Reducing differences for future refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mwithi committed Jan 28, 2025
1 parent 5275d45 commit 9c183d1
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 222 deletions.
6 changes: 1 addition & 5 deletions bundle/language_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,6 @@ angal.common.update.btn.key
angal.common.user.col = User
angal.common.userid = User
angal.common.userid.label = User:
angal.common.view.btn = View
angal.common.view.btn.key = V
angal.common.ward.txt = Ward
angal.common.ward.col = Ward
angal.common.weight.txt = Weight
Expand Down Expand Up @@ -749,7 +747,7 @@ angal.inventoryrow.lotinformation.title
angal.inventoryrow.medicaltype.txt = Medical Type
angal.inventory.medicalwithmovementonly.btn = With movement only
angal.inventory.medicalwithonlynonzeroqty.btn = Only non zero quantyties
angal.inventory.nextarrow.btn = >
angal.inventory.arrownext.btn = >
angal.inventory.arrowprevious.btn = <
angal.inventory.product.col = Products
angal.inventory.productalreadyexist.msg = {0} already exists in the list. Do you still like to add it?
Expand Down Expand Up @@ -827,7 +825,6 @@ angal.inventory.lotcode.col
angal.inventory.managementward.title = Manage Ward Inventory
angal.inventory.medical.col = Medical
angal.inventory.mustenterareference.msg = You must enter a reference.
angal.inventory.nextarrow.btn = >
angal.inventory.new.title = New inventory
angal.inventory.newlot.col = New lot
angal.inventory.newlotshavebeenaddedforsomemedicalward.fmt.msg = New lot(s) have been found by new movement(s) in ward store for: {0}
Expand All @@ -845,7 +842,6 @@ angal.inventory.pleasevalidateinventoryagainsbeforeconfirmation.msg
angal.inventory.pleaseselectatleastoneinventoryrow.msg = Please select at least one inventory row.
angal.inventory.pleaseselectonlyoneinventory.msg = Please select only one inventory.
angal.inventory.pleaseselectinventory.msg = Please select inventory.
angal.inventory.previousarrow.btn = <
angal.inventory.productalreadyexist.msg = {0} already exist in the table with the lot code {1}. Please choose another lot.
angal.inventory.productcode.text = Product's code
angal.inventory.realqty.col = Real quantity
Expand Down
68 changes: 30 additions & 38 deletions src/main/java/org/isf/medicalinventory/gui/InventoryBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.List;

import javax.swing.JButton;
Expand Down Expand Up @@ -73,10 +71,11 @@
public class InventoryBrowser extends ModalJFrame implements InventoryListener {

private static final long serialVersionUID = 1L;

private GoodDateChooser jCalendarTo;
private GoodDateChooser jCalendarFrom;
private LocalDateTime dateFrom = TimeTools.getNow();
private LocalDateTime dateTo = TimeTools.getNow();
private LocalDateTime dateFrom = TimeTools.getDateToday0();
private LocalDateTime dateTo = TimeTools.getDateToday24();
private JLabel jLabelTo;
private JLabel jLabelFrom;
private JPanel panelHeader;
Expand All @@ -93,10 +92,11 @@ public class InventoryBrowser extends ModalJFrame implements InventoryListener {
MessageBundle.getMessage("angal.common.reference.label").toUpperCase(),
MessageBundle.getMessage("angal.common.date.txt").toUpperCase(),
MessageBundle.getMessage("angal.common.status.txt").toUpperCase(),
MessageBundle.getMessage("angal.common.user.col").toUpperCase() };
MessageBundle.getMessage("angal.common.user.col").toUpperCase()
};
private int[] columwidth = { 150, 150, 150, 200 };
private boolean[] columnCentered = { false, true, true, true };
private Class[] columnClasses = { String.class, String.class, String.class, String.class };
private boolean[] columnCentered = { false, true, true, true };
private JComboBox<String> statusComboBox;
private JLabel statusLabel;
private JButton next;
Expand Down Expand Up @@ -163,7 +163,6 @@ public void windowClosing(WindowEvent e) {
pagesComboBox.setSelectedItem(page);
});
pagesComboBox.addItemListener(itemEvent -> {

int eventID = itemEvent.getStateChange();

if (eventID == ItemEvent.SELECTED) {
Expand Down Expand Up @@ -257,7 +256,7 @@ private JPanel getPanelContent() {
private JPanel getPanelFooter() {
if (panelFooter == null) {
panelFooter = new JPanel();
next = new JButton(MessageBundle.getMessage("angal.inventory.nextarrow.btn"));
next = new JButton(MessageBundle.getMessage("angal.inventory.arrownext.btn"));
next.setMnemonic(KeyEvent.VK_RIGHT);
previous = new JButton(MessageBundle.getMessage("angal.inventory.arrowprevious.btn"));
next.setMnemonic(KeyEvent.VK_LEFT);
Expand All @@ -268,20 +267,20 @@ private JPanel getPanelFooter() {
panelFooter.add(next);

panelFooter.add(getNewButton());
panelFooter.add(getUpdateButton());
panelFooter.add(getViewButton());
panelFooter.add(getEditButton());
panelFooter.add(getDeleteButton());
panelFooter.add(getCloseButton());
}
initializePagesCombo();
return panelFooter;
}

private GoodDateChooser getJCalendarTo() {
if (jCalendarTo == null) {
jCalendarTo = new GoodDateChooser(LocalDate.now(), false, false);
jCalendarTo.addDateChangeListener(event -> {
dateTo = jCalendarTo.getDateEndOfDay();
private GoodDateChooser getJCalendarFrom() {
if (jCalendarFrom == null) {
jCalendarFrom = new GoodDateChooser(LocalDate.now(), false, false);
jCalendarFrom.addDateChangeListener(event -> {
dateFrom = jCalendarFrom.getDateStartOfDay();
totalRows = medicalInventoryManager.getInventoryCount(InventoryType.main.toString());
startIndex = 0;
previous.setEnabled(false);
Expand All @@ -294,14 +293,14 @@ private GoodDateChooser getJCalendarTo() {
initializePagesCombo();
});
}
return jCalendarTo;
return jCalendarFrom;
}

private GoodDateChooser getJCalendarFrom() {
if (jCalendarFrom == null) {
jCalendarFrom = new GoodDateChooser(LocalDate.now(), false, false);
jCalendarFrom.addDateChangeListener(event -> {
dateFrom = jCalendarFrom.getDateStartOfDay();
private GoodDateChooser getJCalendarTo() {
if (jCalendarTo == null) {
jCalendarTo = new GoodDateChooser(LocalDate.now(), false, false);
jCalendarTo.addDateChangeListener(event -> {
dateTo = jCalendarTo.getDateEndOfDay();
totalRows = medicalInventoryManager.getInventoryCount(InventoryType.main.toString());
startIndex = 0;
previous.setEnabled(false);
Expand All @@ -314,7 +313,7 @@ private GoodDateChooser getJCalendarFrom() {
initializePagesCombo();
});
}
return jCalendarFrom;
return jCalendarTo;
}

private JLabel getJLabelTo() {
Expand All @@ -325,6 +324,7 @@ private JLabel getJLabelTo() {
}
return jLabelTo;
}

private JLabel getJLabelFrom() {
if (jLabelFrom == null) {
jLabelFrom = new JLabel();
Expand Down Expand Up @@ -357,11 +357,11 @@ private JButton getNewButton() {
MessageDialog.error(null, "angal.inventory.cannotcreateanotherinventorywithstatusdraft.msg");
return;
}

});
return jButtonNew;
}
private JButton getUpdateButton() {

private JButton getEditButton() {
jButtonEdit = new JButton(MessageBundle.getMessage("angal.common.edit.btn"));
jButtonEdit.setMnemonic(MessageBundle.getMnemonic("angal.common.edit.btn.key"));
jButtonEdit.setEnabled(false);
Expand Down Expand Up @@ -394,8 +394,8 @@ private JButton getUpdateButton() {
}

private JButton getViewButton() {
jButtonView = new JButton(MessageBundle.getMessage("angal.common.view.btn"));
jButtonView.setMnemonic(MessageBundle.getMnemonic("angal.common.view.btn.key"));
jButtonView = new JButton(MessageBundle.getMessage("angal.inventory.view.btn"));
jButtonView.setMnemonic(MessageBundle.getMnemonic("angal.inventory.view.btn.key"));
jButtonView.setEnabled(false);
jButtonView.addActionListener(actionEvent -> {
MedicalInventory inventory = new MedicalInventory();
Expand Down Expand Up @@ -456,9 +456,7 @@ private JButton getDeleteButton() {
private JButton getCloseButton() {
jButtonClose = new JButton(MessageBundle.getMessage("angal.common.close.btn"));
jButtonClose.setMnemonic(MessageBundle.getMnemonic("angal.common.close.btn.key"));
jButtonClose.addActionListener(actionEvent -> {
dispose();
});
jButtonClose.addActionListener(actionEvent -> dispose());
return jButtonClose;
}

Expand Down Expand Up @@ -520,10 +518,10 @@ class InventoryBrowsingModel extends DefaultTableModel {

public InventoryBrowsingModel(int page, int pageSize) {
inventoryList = new ArrayList<>();
String state = statusComboBox.getSelectedIndex() > 0 ? statusComboBox.getSelectedItem().toString().toLowerCase() : null;
String status = statusComboBox.getSelectedIndex() > 0 ? statusComboBox.getSelectedItem().toString().toLowerCase() : null;
String type = InventoryType.main.toString();
try {
Page<MedicalInventory> medInventorypage = medicalInventoryManager.getMedicalInventoryByParamsPageable(dateFrom, dateTo, state, type, page,
Page<MedicalInventory> medInventorypage = medicalInventoryManager.getMedicalInventoryByParamsPageable(dateFrom, dateTo, status, type, page,
pageSize);
inventoryList = medInventorypage.getContent();
} catch (OHServiceException e) {
Expand Down Expand Up @@ -578,18 +576,12 @@ public boolean isCellEditable(int arg0, int arg1) {

}

public String formatDateTime(GregorianCalendar time) {
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yy"); //$NON-NLS-1$
return format.format(time.getTime());
}

private JComboBox<String> getComboBox() {
if (statusComboBox == null) {
statusComboBox = new JComboBox<>();
statusComboBox.addItem(MessageBundle.getMessage("angal.common.all.txt"));
List<String> statusList = medicalInventoryManager.getStatusList();
for (String status : statusList) {
statusComboBox.addItem(status);
for (InventoryStatus currentStatus : InventoryStatus.values()) {
statusComboBox.addItem(MessageBundle.getMessage("angal.inventory." + currentStatus));
}
statusComboBox.addActionListener(actionEvent -> {
totalRows = medicalInventoryManager.getInventoryCount(InventoryType.main.toString());
Expand Down
33 changes: 14 additions & 19 deletions src/main/java/org/isf/medicalinventory/gui/InventoryEdit.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,49 +123,45 @@ public class InventoryEdit extends ModalJFrame {

public interface InventoryListener extends EventListener {

public void InventoryInserted(AWTEvent e);
void InventoryInserted(AWTEvent e);

public void InventoryUpdated(AWTEvent e);
void InventoryUpdated(AWTEvent e);

public void InventoryCancelled(AWTEvent e);
void InventoryCancelled(AWTEvent e);
}

public static void addInventoryListener(InventoryListener listener) {
InventoryListeners.add(InventoryListener.class, listener);
}

public static void removeInventoryListener(InventoryListener listener) {
InventoryListeners.remove(InventoryListener.class, listener);
}

private void fireInventoryInserted() {
private void fireInventoryUpdated() {
AWTEvent event = new AWTEvent(new Object(), AWTEvent.RESERVED_ID_MAX + 1) {

private static final long serialVersionUID = 1L;
};

EventListener[] listeners = InventoryListeners.getListeners(InventoryListener.class);
for (int i = 0; i < listeners.length; i++) {
((InventoryListener) listeners[i]).InventoryInserted(event);
}
if (jTableInventoryRow != null) {
jTableInventoryRow.updateUI();
for (EventListener listener : listeners) {
((InventoryListener) listener).InventoryUpdated(event);
}
jTableInventoryRow.updateUI();
}

private void fireInventoryUpdated() {
private void fireInventoryInserted() {
AWTEvent event = new AWTEvent(new Object(), AWTEvent.RESERVED_ID_MAX + 1) {

private static final long serialVersionUID = 1L;
};

EventListener[] listeners = InventoryListeners.getListeners(InventoryListener.class);
for (int i = 0; i < listeners.length; i++) {
((InventoryListener) listeners[i]).InventoryUpdated(event);
}
if (jTableInventoryRow != null) {
jTableInventoryRow.updateUI();
for (EventListener listener : listeners) {
((InventoryListener) listener).InventoryInserted(event);
}
jTableInventoryRow.updateUI();
}

private GoodDateChooser jCalendarInventory;
Expand Down Expand Up @@ -501,6 +497,7 @@ private JPanel getPanelFooter() {

private GoodDateChooser getJCalendarFrom() {
if (jCalendarInventory == null) {

jCalendarInventory = new GoodDateChooser(LocalDate.now(), false, false);
if (inventory != null) {
jCalendarInventory.setDate(inventory.getInventoryDate().toLocalDate());
Expand Down Expand Up @@ -595,16 +592,14 @@ private JButton getSaveButton() {
medicalInventoryRowManager.updateMedicalInventoryRow(invRow);
movStockInsertingManager.deleteLot(entry.getValue());
}

}
medicalInventoryRowManager.deleteMedicalInventoryRows(inventoryRowsToDelete);
}
ListIterator<MedicalInventoryRow> inventoryRowSearchListIterator = inventoryRowSearchList.listIterator();
List<MedicalInventoryRow> newMedicalInventoryRows = new ArrayList<>();
if (mode.equals("new")) {
newReference = referenceTextField.getText().trim();
boolean refExist = false;
refExist = medicalInventoryManager.referenceExists(newReference);
boolean refExist = medicalInventoryManager.referenceExists(newReference);
boolean referenceExistonMovementStock = movStockInsertingManager.refNoExists(newReference);
if (refExist || referenceExistonMovementStock) {
MessageDialog.error(null, "angal.inventory.referencealreadyused.msg");
Expand Down
Loading

0 comments on commit 9c183d1

Please sign in to comment.