-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjohnsCafeController.java
More file actions
815 lines (588 loc) · 27.2 KB
/
Copy pathjohnsCafeController.java
File metadata and controls
815 lines (588 loc) · 27.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
package com.example.fxpartcw;
import javafx.application.Platform;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.scene.control.*;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.*;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import static com.example.fxpartcw.Dealer.*;
import static com.example.fxpartcw.inventory.addingItemDetailsMap;
public class johnsCafeController {
@FXML
private Button addImageButtonInAddItems;
@FXML
private ImageView imageViewInAddImageInAdditemdetails;
@FXML
private ImageView ImageViewInUpdate;
@FXML
private Button addItemImageInUpdate;
@FXML
private TextField ContactNumberInDealer1;
@FXML
private TextField ContactNumberInDealer2;
@FXML
private TextField ContactNumberInDealer3;
@FXML
private TextField ContactNumberInDealer4;
@FXML
private Button backButtonInRandomDealers;
@FXML
private TextField locationInDealer1;
@FXML
private TextField locationInDealer2;
@FXML
private TextField locationInDealer3;
@FXML
private TextField locationInDealer4;
@FXML
private TextField nameInDealer1;
@FXML
private TextField nameInDealer2;
@FXML
private TextField nameInDealer3;
@FXML
private TextField nameInDealer4;
@FXML
private Button pathToItemDetailsFromDealerDetails;
@FXML
private TableView<HashMap<String, String>> viewItemTable;
@FXML
private TableColumn<HashMap<String, String>, String> imageViewInView;
@FXML
private TableColumn<HashMap<String, String>, String> itemBrandIdInView;
@FXML
private TableColumn<Map<String, String>, String> itemCategoryIdInView;
@FXML
private TableColumn<Map<String, String>, String> itemCodeIdInView;
@FXML
private TableColumn<Map<String, String>, String> itemNameIdInView;
@FXML
private TableColumn<Map<String, String>, String> itemPriceIdInView;
@FXML
private TableColumn<Map<String, String>, String> itemPurchasedDateIdInView;
@FXML
private TableColumn<Map<String, String>, String> itemQuantityIdInView;
@FXML
private TableView<HashMap<String, String>> dealerDetailsTable;
@FXML
private TableColumn<HashMap<String, String>, String> dealerNameInDisplay;
@FXML
private Button displayButton;
@FXML
private Button exitButtonInDisplay;
@FXML
private TableView<HashMap<String,String>> dealerItemDetailsTable;
@FXML
private TableColumn<HashMap<String, String>, String> itemBrandInViewdetails;
@FXML
private TableColumn<HashMap<String, String>, String> itemCodeInViewdetails;
@FXML
private TableColumn<HashMap<String, String>, String>itemNameInViewdetails;
@FXML
private TableColumn<HashMap<String, String>, String> itemPriceInViewdetails;
@FXML
private TableColumn<HashMap<String, String>, String> itemQuantityInViewdetails;
@FXML
private Button populatebtn;
@FXML
private TextField itemAddingTextfield;
@FXML
private TextField itemAddingTextfield1;
@FXML
private TextField itemAddingTextfield2;
@FXML
private TextField itemAddingTextfield3;
@FXML
private TextField itemAddingTextfield4;
@FXML
private TextField itemAddingTextfield6;
@FXML
private DatePicker itemAddingTextfield7;
@FXML
private Label itemcodeErrordisplayLabel;
@FXML
private AnchorPane mainAncorpane;
@FXML
private Button saveItemDetailsInAddItemClick;
@FXML
private Button ExitPartdeleteItem;
@FXML
private Button deleteButtonInDeleteItems;
@FXML
private Label deleteItemlabel5;
@FXML
private Label deleteItemlabel7;
@FXML
private Button deleteTextField;
@FXML
private Button deleteTextField1;
@FXML
private TextField deleteTextField4;
@FXML
private Label deleteitemlabel2;
@FXML
private Label deletelabel1;
@FXML
private TextField gettingTheItemCodeInUpdate;
@FXML
private TextField itemUpdatingTextfield;
@FXML
private TextField itemUpdatingTextfield1;
@FXML
private TextField itemUpdatingTextfield2;
@FXML
private TextField itemUpdatingTextfield3;
@FXML
private TextField itemUpdatingTextfield4;
@FXML
private TextField itemUpdatingTextfield5;
@FXML
private TextField itemUpdatingTextfield6;
@FXML
private Button saveDetailsInUpdate;
@FXML
private Button searchInUpdate;
@FXML
private DatePicker purchasingDateInUpdate;
public void onGetStartedButtonClick(ActionEvent actionEvent) throws IOException {
FXMLLoader dashboardLoader = new FXMLLoader(getClass().getResource("mainpage.fxml"));
Parent root = dashboardLoader.load();
Scene dashboardPage = new Scene(root);
Stage previousStage = (Stage) ((Node) actionEvent.getSource()).getScene().getWindow();
previousStage.setScene(dashboardPage);
}
public void backButtonInselectingRandomDealersClick(ActionEvent actionEvent) throws IOException {
FXMLLoader dashboardLoader = new FXMLLoader(getClass().getResource("mainpage.fxml"));
Parent root = dashboardLoader.load();
Scene dashboardPage = new Scene(root);
Stage previousStage = (Stage) ((Node) actionEvent.getSource()).getScene().getWindow();
previousStage.setScene(dashboardPage);
}
public void onbtnAdditemsButtonClick(ActionEvent actionEvent) throws IOException {
FXMLLoader dashboardLoader = new FXMLLoader(getClass().getResource("AddItemsfile.fxml"));
Parent root = dashboardLoader.load();
Scene dashboardPage = new Scene(root);
Stage previousStage = (Stage) ((Node) actionEvent.getSource()).getScene().getWindow();
previousStage.setScene(dashboardPage);
}
public void onbtnDeleteitemsButtonClick(ActionEvent actionEvent) throws IOException {
FXMLLoader dashboardLoader = new FXMLLoader(getClass().getResource("DeleteItems.fxml"));
Parent root = dashboardLoader.load();
Scene dashboardPage = new Scene(root);
Stage previousStage = (Stage) ((Node) actionEvent.getSource()).getScene().getWindow();
previousStage.setScene(dashboardPage);
}
public void onbtnUpdateitemsButtonClick(ActionEvent actionEvent) throws IOException {
FXMLLoader dashboardLoader = new FXMLLoader(getClass().getResource("updateitemdetails.fxml"));
Parent root = dashboardLoader.load();
Scene dashboardPage = new Scene(root);
Stage previousStage = (Stage) ((Node) actionEvent.getSource()).getScene().getWindow();
previousStage.setScene(dashboardPage);
}
public void onBackButtonInAddItemClick(ActionEvent actionEvent) throws IOException {
FXMLLoader dashboardLoader = new FXMLLoader(getClass().getResource("mainpage.fxml"));
Parent root = dashboardLoader.load();
Scene dashboardPage = new Scene(root);
Stage previousStage = (Stage) ((Node) actionEvent.getSource()).getScene().getWindow();
previousStage.setScene(dashboardPage);
}
public void exitButtonDisplayDealer(ActionEvent actionEvent) throws IOException {
FXMLLoader dashboardLoader = new FXMLLoader(getClass().getResource("mainpage.fxml"));
Parent root = dashboardLoader.load();
Scene dashboardPage = new Scene(root);
Stage previousStage = (Stage) ((Node) actionEvent.getSource()).getScene().getWindow();
previousStage.setScene(dashboardPage);
}
public void onClickToDealerItemDetails(ActionEvent actionEvent) throws IOException {
FXMLLoader dashboardLoader = new FXMLLoader(getClass().getResource("dealerItemDetails.fxml"));
Parent root = dashboardLoader.load();
Scene dashboardPage = new Scene(root);
Stage previousStage = (Stage) ((Node) actionEvent.getSource()).getScene().getWindow();
previousStage.setScene(dashboardPage);
}
public void exitButtonMain(ActionEvent actionEvent) {
// Exit the application
Platform.exit();
}
public void onViewItemButtonClick(ActionEvent actionEvent) throws IOException {
FXMLLoader dashboardLoader = new FXMLLoader(getClass().getResource("viewItemFile.fxml"));
Parent root = dashboardLoader.load();
Scene dashboardPage = new Scene(root);
Stage previousStage = (Stage) ((Node) actionEvent.getSource()).getScene().getWindow();
previousStage.setScene(dashboardPage);
}
public void onBackButtonInViewItemClick(ActionEvent actionEvent) throws IOException {
FXMLLoader dashboardLoader = new FXMLLoader(getClass().getResource("mainpage.fxml"));
Parent root = dashboardLoader.load();
Scene dashboardPage = new Scene(root);
Stage previousStage = (Stage) ((Node) actionEvent.getSource()).getScene().getWindow();
previousStage.setScene(dashboardPage);
}
public void onBackButtonInUpdateItemClick(ActionEvent actionEvent) throws IOException {
FXMLLoader dashboardLoader = new FXMLLoader(getClass().getResource("mainpage.fxml"));
Parent root = dashboardLoader.load();
Scene dashboardPage = new Scene(root);
Stage previousStage = (Stage) ((Node) actionEvent.getSource()).getScene().getWindow();
previousStage.setScene(dashboardPage);
}
public void exitForMainMenuInDeleteItemClick(ActionEvent actionEvent) throws IOException {
FXMLLoader dashboardLoader = new FXMLLoader(getClass().getResource("mainpage.fxml"));
Parent root = dashboardLoader.load();
Scene dashboardPage = new Scene(root);
Stage previousStage = (Stage) ((Node) actionEvent.getSource()).getScene().getWindow();
previousStage.setScene(dashboardPage);
}
public void selectDealersButtonInMainPage(ActionEvent actionEvent) throws IOException {
FXMLLoader dashboardLoader = new FXMLLoader(getClass().getResource("randomDealers.fxml"));
Parent root = dashboardLoader.load();
Scene dashboardPage = new Scene(root);
Stage previousStage = (Stage) ((Node) actionEvent.getSource()).getScene().getWindow();
previousStage.setScene(dashboardPage);
initializeDealersDetails();
displayRandomDealerDetails();
}
public void saveItemsInMain(ActionEvent actionEvent) throws IOException {
showAlert("Item Details Saved Successfully");
}
private void showAlert(String message) {
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("Success");
alert.setHeaderText(null);
alert.setContentText(message);
alert.showAndWait();
}
private List<Dealer> dealersList;
private Dealer dealer = new Dealer();
List<Dealer> selectedDealers = new ArrayList<>();
ObservableList<HashMap<String, String>> dataList;
public void initializeDealersDetails() {
final String filePath = System.getProperty("user.dir") + "/src/main/resources/com/example/fxpartcw/dealers.txt";
dealersList = dealer.readDealersFromFile(filePath);
displayRandomDealerDetails();
}
// Method to display the details (name, contact number, location) of a random Dealer.
private void displayDealerDetails() {
String filePath = System.getProperty("user.dir") + "/src/main/resources/com/example/fxpartcw/dealers.txt";
List<Dealer> dealersList = dealer.readDealersFromFile(filePath);
// Step 1: Select random dealers
selectedDealers = selectRandomDealers(dealersList, 4);
Dealer sunil = selectedDealers.get(0);
nameInDealer1.setText(sunil.getName());
ContactNumberInDealer1.setText(sunil.getContactNumber());
locationInDealer1.setText(sunil.getLocation());
Dealer nimal = selectedDealers.get(1);
nameInDealer2.setText(nimal.getName());
ContactNumberInDealer2.setText(nimal.getContactNumber());
locationInDealer2.setText(nimal.getLocation());
Dealer ashan = selectedDealers.get(2);
nameInDealer3.setText(ashan.getName());
ContactNumberInDealer3.setText(ashan.getContactNumber());
locationInDealer3.setText(ashan.getLocation());
Dealer kamal = selectedDealers.get(3);
nameInDealer4.setText(kamal.getName());
ContactNumberInDealer4.setText(kamal.getContactNumber());
locationInDealer4.setText(kamal.getLocation());
// Assuming dealer.displaySelectedDealersItemDetails(selectedDealers) returns ArrayList<HashMap<String, String>>
ArrayList<HashMap<String, String>> data = dealer.displaySelectedDealersItemDetails(selectedDealers);
if (data != null) {
dataList = FXCollections.observableArrayList(data);
System.out.println(dataList);
dealerDetailsTable.setItems(dataList);
} else {
// Handle the case when data is null (optional)
System.out.println("Error: The data list is null.");
}
}
public void displayItemDetails(){
// Bind the cell value factories to the HashMap keys
itemCodeInViewdetails.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().get("itemID")));
itemNameInViewdetails.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().get("itemName")));
itemBrandInViewdetails.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().get("itemBrand")));
itemPriceInViewdetails.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().get("itemPrice")));
itemQuantityInViewdetails.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().get("itemQuantity")));
System.out.println(dataList);
dealerDetailsTable.setItems(dataList);
}
public void displayDetailsButton(){
displayItemDetails();
}
inventory item = new inventory();
@FXML
void saveItemDetailsInAddItems(ActionEvent event) {
// Get the input values from text fields
String itemCodeText = itemAddingTextfield.getText();
String itemNameText = itemAddingTextfield3.getText();
String itemBrandText = itemAddingTextfield4.getText();
String itemPriceText = itemAddingTextfield2.getText();
String itemQuantityText = itemAddingTextfield1.getText();
String itemCategoryText = itemAddingTextfield6.getText();
String itemPurchasedDateText = String.valueOf(itemAddingTextfield7.getValue());
// Validate itemCode and itemQuantity
boolean isItemCodeValid = checkingValidPositiveInteger(itemCodeText);
boolean isItemQuantityValid = checkingValidPositiveInteger(itemQuantityText);
// Validate itemPrice
boolean isItemPriceValid = checkingValidDouble(itemPriceText);
// Validate itemName, itemBrand, and itemCategory
boolean areItemDetailsValid = checkingValidString(itemNameText)
&& checkingValidString(itemBrandText)
&& checkingValidString(itemCategoryText);
if (isItemCodeValid && isItemQuantityValid && isItemPriceValid && areItemDetailsValid) {
// If all inputs are valid, proceed with saving the item details
item.setItemCode(Integer.parseInt(itemCodeText));
item.setItemName(itemNameText);
item.setItemBrand(itemBrandText);
item.setItemPrice((int) Double.parseDouble(itemPriceText));
item.setItemQuantity(Integer.parseInt(itemQuantityText));
item.setItemCategory(itemCategoryText);
item.setItemPurchasedDate(itemPurchasedDateText);
item.addItemsToHashMap();
item.saveHashMapToTextFile();
} else {
// Show alert message and mark invalid fields with red border
if (!isItemCodeValid) {
checkingInvalidInput(itemAddingTextfield);
}
if (!isItemQuantityValid) {
checkingInvalidInput(itemAddingTextfield1);
}
if (!isItemPriceValid) {
checkingInvalidInput(itemAddingTextfield2);
}
if (!checkingValidString(itemNameText)) {
checkingInvalidInput(itemAddingTextfield3);
}
if (!checkingValidString(itemBrandText)) {
checkingInvalidInput(itemAddingTextfield4);
}
if (!checkingValidString(itemCategoryText)) {
checkingInvalidInput(itemAddingTextfield6);
}
// Display the alert message
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Invalid Input");
alert.setHeaderText("Please check the input");
alert.setContentText("Some fields have invalid input. Please correct them and try again.");
alert.showAndWait();
}
// Clear the text fields
itemAddingTextfield.setText("");
itemAddingTextfield1.setText("");
itemAddingTextfield2.setText("");
itemAddingTextfield3.setText("");
itemAddingTextfield4.setText("");
itemAddingTextfield6.setText("");
itemAddingTextfield7.setValue(null);
}
// Helper methods for input validation
private boolean checkingValidPositiveInteger(String input) {
try {
int value = Integer.parseInt(input);
return value > 0;
} catch (NumberFormatException e) {
return false;
}
}
private boolean checkingValidDouble(String input) {
try {
double value = Double.parseDouble(input);
return true;
} catch (NumberFormatException e) {
return false;
}
}
private boolean checkingValidString(String input) {
return !input.trim().isEmpty() && input.matches("[a-zA-Z]+") ;
}
private void checkingInvalidInput(TextField textField) {
textField.setStyle("-fx-border-color: red;");
}
@FXML
public void onDeleteButtonInDeleteItemDetails(ActionEvent actionEvent) {
String itemCodeText = deleteTextField4.getText();
// Check if the user input is a valid integer
try {
int itemCode = Integer.parseInt(itemCodeText);
// Call the method to delete item details
boolean deleted = item.deleteItemDetails(String.valueOf(itemCode));
if (deleted) {
// Show a success alert if the item was deleted successfully
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("Item Deletion");
alert.setHeaderText(null);
alert.setContentText("Item deleted successfully.");
alert.showAndWait();
} else {
// Show an alert if the item code was not found in the hashmap
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Alert");
alert.setHeaderText(null);
alert.setContentText("Item deleted successfully.");
alert.showAndWait();
}
} catch (NumberFormatException e) {
// Show an alert for invalid integer input
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error");
alert.setHeaderText(null);
alert.setContentText("Please input a valid item code (integer).");
alert.showAndWait();
redLineDelete();
// Set the border of the text field to red
}
deleteTextField4.setText("");
}
public void redLineDelete(){
deleteTextField4.setStyle("-fx-border-color: red;");
}
private HashMap<Integer, HashMap<String, String>> itemDetailsHashMap;
@FXML
public void searchButtonInUpdateClick(ActionEvent actionEvent) {
item.searchForUpdateDetails(gettingTheItemCodeInUpdate.getText(), itemUpdatingTextfield, itemUpdatingTextfield1,
itemUpdatingTextfield2, itemUpdatingTextfield6, itemUpdatingTextfield4, itemUpdatingTextfield3, purchasingDateInUpdate);
}
@FXML
public void saveDetailsInUpdateItemClick() {
item.updateData(gettingTheItemCodeInUpdate.getText(), itemUpdatingTextfield, itemUpdatingTextfield1,
itemUpdatingTextfield2, itemUpdatingTextfield6, itemUpdatingTextfield4, itemUpdatingTextfield3, purchasingDateInUpdate);
gettingTheItemCodeInUpdate.setText("");
itemUpdatingTextfield.setText("");
itemUpdatingTextfield1.setText("");
itemUpdatingTextfield2.setText("");
itemUpdatingTextfield3.setText("");
itemUpdatingTextfield4.setText("");
itemUpdatingTextfield6.setText("");
purchasingDateInUpdate.setValue(null);
}
public void initialize(ActionEvent event) {
}
public void showItemsButtonClick(){
populateTableView();
}
private void populateTableView() {
ArrayList<HashMap<String, String>> data = inventory.readData();
int n = data.size();
for (int i = 0; i < n - 1; i++) {
int minIndex = i;
for (int j = i + 1; j < n; j++) {
int itemCode1 = Integer.parseInt(data.get(j).get("itemCode"));
int itemCode2 = Integer.parseInt(data.get(minIndex).get("itemCode"));
if (itemCode1 < itemCode2) {
minIndex = j;
}
}
if (minIndex != i) {
HashMap<String, String> temp = data.get(i);
data.set(i, data.get(minIndex));
data.set(minIndex, temp);
}
}
// Bind columns to HashMap keys
itemBrandIdInView.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().get("itemBrand")));
itemCategoryIdInView.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().get("itemCategory")));
itemCodeIdInView.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().get("itemCode")));
itemNameIdInView.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().get("itemName")));
itemPriceIdInView.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().get("itemPrice")));
itemPurchasedDateIdInView.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().get("itemPurchasedDate")));
itemQuantityIdInView.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().get("itemQuantity")));
imageViewInView.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().get("itemImage")));
imageViewInView.setCellFactory(column -> new TableCell<>() {
private final ImageView imageView = new ImageView();
@Override
protected void updateItem(String imagePath, boolean empty) {
super.updateItem(imagePath, empty);
if (empty || imagePath == null) {
setGraphic(null);
} else {
// Load the image and set it in the ImageView
Image image = new Image(new File(imagePath).toURI().toString());
imageView.setImage(image);
imageView.setFitHeight(80); // Set the desired height of the image
imageView.setFitWidth(80); // Set the desired width of the image
setGraphic(imageView);
}
}});
// Add data to the table view
System.out.println(data);
// Add data to the table view
ObservableList<HashMap<String, String>> observableDataList = FXCollections.observableArrayList(data);
viewItemTable.setItems(observableDataList);
}
public void backButtonInselectingRandomDealersClick() {
}
public void DispalyDealerDetails() {
displayDealerDetails();
}
public void DealerDetailsButtonClick(ActionEvent actionEvent) throws IOException {
FXMLLoader dashboardLoader = new FXMLLoader(getClass().getResource("dealerItemDetails.fxml"));
Parent root = dashboardLoader.load();
Scene dashboardPage = new Scene(root);
Stage previousStage = (Stage) ((Node) actionEvent.getSource()).getScene().getWindow();
previousStage.setScene(dashboardPage);
}
public void exitForMainManuButtonClick(ActionEvent actionEvent) throws IOException{
FXMLLoader dashboardLoader = new FXMLLoader(getClass().getResource("mainpage.fxml"));
Parent root = dashboardLoader.load();
Scene dashboardPage = new Scene(root);
Stage previousStage = (Stage) ((Node) actionEvent.getSource()).getScene().getWindow();
previousStage.setScene(dashboardPage);
}
public void addImageButtonInAddItemsClick(ActionEvent actionEvent) {
FileChooser fileChooser = new FileChooser();
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Image Files", "*.png", "*.jpg", "*.gif"));
// Show open file dialog
File selectedFile = fileChooser.showOpenDialog(null);
if (selectedFile != null) {
try {
// Copy the selected image to a known directory (e.g., the working directory)
File destination = new File(selectedFile.getName());
Files.copy(selectedFile.toPath(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING);
// Display the image in the ImageView
Image image = new Image(destination.toURI().toString());
ImageView imageView;
imageViewInAddImageInAdditemdetails.setImage(image);
// Save the image file path in your HashMap
addingItemDetailsMap.put("itemImage", destination.getAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
}
}
}
public void addItemImageInUpdateClick(ActionEvent actionEvent) {
FileChooser file = new FileChooser();
file.getExtensionFilters().add(new FileChooser.ExtensionFilter("Image Files", "*.png", "*.jpg", "*.gif"));
// Show open file dialog
File selectedFile = file.showOpenDialog(null);
if (selectedFile != null) {
try {
// Copy the selected image to a known directory (e.g., the working directory)
File destination = new File(selectedFile.getName());
Files.copy(selectedFile.toPath(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING);
// Display the image in the ImageView
Image image = new Image(destination.toURI().toString());
ImageView imageView;
ImageViewInUpdate.setImage(image);
// Save the image file path in your HashMap
addingItemDetailsMap.put("itemImage", destination.getAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
}
}
}
public void onClickPopulateButton(ActionEvent actionEvent) {
}
}