updated write to CSV and Edit dialogue for address, also added attributes to handle CSV format of address and human-readable format for address, so that it is readable on the JRadioButton for humans and saved to the CSV correctly.

This commit is contained in:
bobbert committed 2025-04-03 11:22:46 +01:00
1 parent 45ef4df0d1
commit 3101374e43
4 files changed
+145 -12

No files matched your search

+43 -3
View File
@@ -1,6 +1,7 @@
package cvbuilder.view;
import cvbuilder.controller.CsvExportSettings;
import cvbuilder.model.Address;
import cvbuilder.model.User;
import cvbuilder.model.UserGroup;
@@ -140,7 +141,12 @@ public class MainViewer {
JButton editButton = new JButton("Edit");
final int userIndex = i;
editButton.addActionListener(e -> {
String newValue = showDialog("Edit " + panelName, value);
String newValue;
if (panelName.equalsIgnoreCase("address")) {
newValue = showAddressDialog("Edit " + panelName, value);
} else {
newValue = showDialog("Edit " + panelName, value);
}
if (newValue != null && !newValue.isEmpty()) {
// Update the user attribute
switch (panelName.toLowerCase()) {
@@ -281,6 +287,39 @@ public class MainViewer {
return null;
}
private String showAddressDialog(String title, String initialValue) {
JTextField flatField = new JTextField();
JTextField addressLine1Field = new JTextField();
JTextField addressLine2Field = new JTextField();
JTextField postcodeField = new JTextField();
Address address = new Address(initialValue);
flatField.setText(address.getFlat());
addressLine1Field.setText(address.getAddressLine1());
addressLine2Field.setText(address.getAddressLine2());
postcodeField.setText(address.getPostcode());
JPanel panel = new JPanel(new GridLayout(0, 1));
panel.add(new JLabel("Flat (optional):"));
panel.add(flatField);
panel.add(new JLabel("Address line 1:"));
panel.add(addressLine1Field);
panel.add(new JLabel("Address line 2 (optional):"));
panel.add(addressLine2Field);
panel.add(new JLabel("Postcode:"));
panel.add(postcodeField);
int result = JOptionPane.showConfirmDialog(null, panel, title, JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
if (result == JOptionPane.OK_OPTION) {
String flat = flatField.getText().trim();
String addressLine1 = addressLine1Field.getText().trim();
String addressLine2 = addressLine2Field.getText().trim();
String postcode = postcodeField.getText().trim();
return (flat.isEmpty() ? "" : flat + "////") + addressLine1 + (addressLine2.isEmpty() ? "" : "%%%%" + addressLine2) + "%%%%" + postcode;
}
return null;
}
private JPanel createFooter(JTabbedPane tabbedPane) {
JPanel footer = new JPanel(new BorderLayout());
footer.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
@@ -505,7 +544,7 @@ public class MainViewer {
titleData[i] = user.getTitle();
emailData[i] = user.getEmail();
phoneData[i] = user.getPhone();
addressData[i] = user.getAddress();
addressData[i] = user.getAddress().getCsvFormat();
}
// Process and write each section based on inclusion settings
@@ -555,4 +594,5 @@ public class MainViewer {
}
}
}
}