Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
fix transient or serializable code smell (java:S1948)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhdcruz committed Dec 14, 2022
1 parent 650ad7c commit 556b1ac
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 123 deletions.
27 changes: 13 additions & 14 deletions src/main/java/com/pharmacy/views/CustomerPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,12 @@

public class CustomerPage extends javax.swing.JPanel {

CustomerController customerController;
int id;
private final int id;

public CustomerPage(int id) {
this.id = id;

initComponents();

customerController = new CustomerController(id);
loadDataSet();
}

Expand Down Expand Up @@ -326,7 +323,7 @@ private void updateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
customerModel.setPhone(phoneText.getText());

EventQueue.invokeLater(() -> {
customerController.updateCustomer(customerModel);
new CustomerController(id).updateCustomer(customerModel);
loadDataSet();
});
}
Expand All @@ -343,11 +340,13 @@ private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
"Confirmation",
JOptionPane.YES_NO_OPTION);
if (opt == JOptionPane.YES_OPTION) {
int customerId = (int) custTable.getValueAt(custTable.getSelectedRow(), 0);
String customerName = (String) custTable.getValueAt(custTable.getSelectedRow(), 2);
EventQueue.invokeLater(() -> {
int customerId = (int) custTable.getValueAt(custTable.getSelectedRow(), 0);
String customerName = (String) custTable.getValueAt(custTable.getSelectedRow(), 2);
new CustomerController(id).deleteCustomer(customerId, customerName);

customerController.deleteCustomer(customerId, customerName);
loadDataSet();
loadDataSet();
});
}
}
}//GEN-LAST:event_deleteButtonActionPerformed
Expand Down Expand Up @@ -377,7 +376,7 @@ private void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN
loadDataSet();
}//GEN-LAST:event_refreshButtonActionPerformed

public void processColums() {
public void processColumns() {
// hide pid
custTable.getColumnModel().getColumn(0).setMinWidth(0);
custTable.getColumnModel().getColumn(0).setMaxWidth(0);
Expand All @@ -386,8 +385,8 @@ public void processColums() {
public void loadDataSet() {
EventQueue.invokeLater(() -> {
try {
custTable.setModel(new DataTableModel().buildTableModel(customerController.getCustomers()));
processColums();
custTable.setModel(new DataTableModel().buildTableModel(new CustomerController(id).getCustomers()));
processColumns();
} catch (SQLException e) {
e.printStackTrace();
}
Expand All @@ -397,8 +396,8 @@ public void loadDataSet() {
public void loadSearchData(String text) {
EventQueue.invokeLater(() -> {
try {
custTable.setModel(new DataTableModel().buildTableModel(customerController.getCustomerSearch(text)));
processColums();
custTable.setModel(new DataTableModel().buildTableModel(new CustomerController(id).getCustomerSearch(text)));
processColumns();
} catch (SQLException e) {
e.printStackTrace();
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/pharmacy/views/Dashboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

public class Dashboard extends javax.swing.JFrame {

UserModel userModel;
CardLayout layout;
private final CardLayout layout;

String username;
LocalDateTime outTime;
int id;
private final String username;
private LocalDateTime outTime;

private final UserModel userModel;

public Dashboard(String username, String userType, UserModel userModel) {
initComponents();
Expand All @@ -38,7 +38,7 @@ public Dashboard(String username, String userType, UserModel userModel) {

// TODO: Inherit `id` from login instead to reduce
// the number of queries to the database
id = new UserController(id).getUserId(username);
int id = new UserController(0).getUserId(username);

// Panel Layout set to Card Layout to allow switching between different sections
displayPanel.setLayout(layout);
Expand Down
36 changes: 17 additions & 19 deletions src/main/java/com/pharmacy/views/HomePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,34 @@

import com.pharmacy.controllers.UserController;
import com.pharmacy.models.UserModel;

import javax.swing.JOptionPane;
import java.awt.Cursor;
import java.awt.EventQueue;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import javax.swing.JOptionPane;

// Welcome page for the application
public class HomePage extends javax.swing.JPanel {

ResultSet resultSet = null;

UserController userController;
UserModel userModel;

String username;
int id;
private final UserModel userModel;
private final String username;
private final int id;

/**
* Creates new form HomePage
*/
public HomePage(String username, int logId) {
this.username = username;
this.id = logId;
this.username = username;
userModel = new UserModel();

initComponents();

userController = new UserController(id);
getUser();
greetUser(userModel.getName());
setupDateTime();
displayDateTime();
}

/**
Expand Down Expand Up @@ -203,7 +197,7 @@ private void updateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
updatedUserModel.setUsername(usernameText.getText());

EventQueue.invokeLater(() -> {
userController.updateUser(updatedUserModel);
new UserController(id).updateUser(updatedUserModel);
});
}
}//GEN-LAST:event_updateButtonActionPerformed
Expand All @@ -218,14 +212,14 @@ private void changePasswordActionPerformed(java.awt.event.ActionEvent evt) {//GE

if (verify != null) {
// password contains the decrypted password
boolean match = userController.matchPasswords(username, verify);
boolean match = new UserController(id).matchPasswords(username, verify);

// if matches, change password to the new one
if (match) {
String newPassword = JOptionPane.showInputDialog(this, "Enter new password for " + username + ":", "Change Password", JOptionPane.PLAIN_MESSAGE);

if (newPassword != null) {
userController.updatePass(userModel.getId(), userModel.getUsername(), newPassword);
new UserController(id).updatePass(userModel.getId(), userModel.getUsername(), newPassword);
JOptionPane.showMessageDialog(this, "Password changed successfully.", "Success", JOptionPane.INFORMATION_MESSAGE);
}
} else {
Expand All @@ -239,8 +233,10 @@ private void changePasswordActionPerformed(java.awt.event.ActionEvent evt) {//GE
}//GEN-LAST:event_changePasswordActionPerformed

private void getUser() {
try {
resultSet = userController.findUser(username);
ResultSet resultSet = new UserController(id).findUser(username);

try (resultSet) {
assert resultSet != null;

if (resultSet.next()) {
// save to user model
Expand All @@ -259,7 +255,10 @@ private void getUser() {
}
}

private void setupDateTime() {
/**
* Display date and time in the top right corner
*/
private void displayDateTime() {
// set date and time
new Thread(() -> {
while (true) {
Expand Down Expand Up @@ -288,7 +287,6 @@ private void greetUser(String name) {
}
}


// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton changePassword;
private javax.swing.JLabel dateLabel;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/pharmacy/views/LoginPage.form
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
<Color blue="99" green="99" red="99" type="rgb"/>
</Property>
<Property name="horizontalAlignment" type="int" value="0"/>
<Property name="text" type="java.lang.String" value="&#xa9; D&amp;D Pharmacy System v2.0.0"/>
<Property name="text" type="java.lang.String" value="&#xa9; D&amp;D Pharmacy System v3.1.0"/>
</Properties>
</Component>
</SubComponents>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/pharmacy/views/LoginPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
jLabel4.setFont(new java.awt.Font("Liberation Sans", 0, 14)); // NOI18N
jLabel4.setForeground(new java.awt.Color(153, 153, 153));
jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel4.setText("© D&D Pharmacy System v2.0.0");
jLabel4.setText("© D&D Pharmacy System v3.1.0");

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
Expand Down
38 changes: 19 additions & 19 deletions src/main/java/com/pharmacy/views/MedicinePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,30 @@
import com.pharmacy.utils.DataTableModel;
import com.pharmacy.utils.StringFormatting;
import com.pharmacy.views.dialogs.AddMedicineDialog;

import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import java.awt.Cursor;
import java.awt.EventQueue;
import java.sql.SQLException;
import java.util.Objects;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;

public class MedicinePage extends javax.swing.JPanel {

Dashboard dashboard;
MedicineModel medicineModel;
MedicineController medicineController;
private final Dashboard dashboard;

int id;
private final int id;

public MedicinePage(Dashboard dashboard, int id) {
this.id = id;
this.dashboard = dashboard;

initComponents();

medicineController = new MedicineController(id);
loadDataSet();
loadComboBox();

// We're not using invokeLater inside combobox since
// suppComboBoxPopupMenuWillBecomeVisible will be stuck and not show
EventQueue.invokeLater(this::loadComboBox);
}

/**
Expand Down Expand Up @@ -372,7 +370,8 @@ private void editButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI
if (medicineTable.getSelectedRow() < 0)
JOptionPane.showMessageDialog(this, "Please select medicine from the table.");
else {
medicineModel = new MedicineModel();
MedicineModel medicineModel = new MedicineModel();

if (nameText.getText().equals("") || costText.getText().equals("")
|| sellText.getText().equals("") || quantityText.getText().equals("")) {
JOptionPane.showMessageDialog(this, "Please enter all the required details.");
Expand All @@ -390,7 +389,7 @@ private void editButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI
medicineModel.setSuppliedBy(Objects.requireNonNull(suppCombo.getSelectedItem()).toString());

EventQueue.invokeLater(() -> {
medicineController.updateMedicine(medicineModel);
new MedicineController(id).updateMedicine(medicineModel);
loadDataSet();
});
}
Expand All @@ -410,8 +409,9 @@ private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
"Are you sure you want to delete this medicine?",
"Confirmation",
JOptionPane.YES_NO_OPTION);

if (opt == JOptionPane.YES_OPTION) {
medicineController.deleteMedicine(
new MedicineController(id).deleteMedicine(
(Integer) medicineTable.getValueAt(
medicineTable.getSelectedRow(), 0));
loadDataSet();
Expand Down Expand Up @@ -482,12 +482,12 @@ private void processColumns() {

// resize column widths
medicineTable.getColumnModel().getColumn(1).setPreferredWidth(111);
medicineTable.getColumnModel().getColumn(2).setPreferredWidth(121);
medicineTable.getColumnModel().getColumn(3).setPreferredWidth(151);
medicineTable.getColumnModel().getColumn(2).setPreferredWidth(131);
medicineTable.getColumnModel().getColumn(3).setPreferredWidth(161);
medicineTable.getColumnModel().getColumn(4).setPreferredWidth(81);
medicineTable.getColumnModel().getColumn(5).setPreferredWidth(81);
medicineTable.getColumnModel().getColumn(6).setPreferredWidth(81);
medicineTable.getColumnModel().getColumn(7).setPreferredWidth(101);
medicineTable.getColumnModel().getColumn(7).setPreferredWidth(111);
medicineTable.getColumnModel().getColumn(8).setPreferredWidth(121);
medicineTable.getColumnModel().getColumn(9).setPreferredWidth(171);
}
Expand All @@ -496,7 +496,7 @@ private void processColumns() {
public void loadDataSet() {
EventQueue.invokeLater(() -> {
try {
medicineTable.setModel(new DataTableModel().buildTableModel(medicineController.getMedicines()));
medicineTable.setModel(new DataTableModel().buildTableModel(new MedicineController(id).getMedicines()));

processColumns();
loadComboBox();
Expand All @@ -510,7 +510,7 @@ public void loadDataSet() {
public void loadSearchData(String text) {
EventQueue.invokeLater(() -> {
try {
medicineTable.setModel(new DataTableModel().buildTableModel(medicineController.getMedicineSearch(text)));
medicineTable.setModel(new DataTableModel().buildTableModel(new MedicineController(id).getMedicineSearch(text)));

processColumns();
} catch (SQLException throwables) {
Expand Down
Loading

0 comments on commit 556b1ac

Please sign in to comment.