-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSellerGUI.java
642 lines (593 loc) · 34 KB
/
SellerGUI.java
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
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
/**
* Project 5 - SellerGUI.java
*
* The interface associated with a seller in the application.
*
* @author Shafer Anthony Hofmann, Qihang Gan, Shreyas Viswanathan, Nathan Pasic
* Miller, Oliver Long
*
* @version December 8, 2023
*/
public class SellerGUI extends JComponent {
private DisplayDashboardGUI displayDashboard = new DisplayDashboardGUI();
private final String[] sortOrderChoices = {"Ascending", "Descending"};
private SellerClient sellerClient;
private JFrame sellerFrame;
private JLabel welcomeUserLabel;
private JButton editEmailButton;
private JButton editPasswordButton;
private JButton deleteAccountButton;
private JButton signOutButton;
// Related to seller permissions
private JButton createStoreButton;
private JButton editStoreButton;
private JButton deleteStoreButton;
private JButton createProductButton;
private JButton editProductButton;
private JButton deleteProductButton;
private JButton importProductsButton;
private JButton exportProductsButton;
private JButton viewCustomerShoppingCartsButton;
private JButton viewSalesByStoreButton;
private JButton viewCustomerDashboardButton;
private JButton viewProductDashboardButton;
private JButton viewProductReviewsButton;
/**
* Invokes the error message dialog to display a custom error message when an action taken by this seller fails.
*
* @param errorMessage The custom error message retrieved through the client
*/
public void displayErrorDialog(String errorMessage) {
new ErrorMessageGUI(errorMessage);
}
/**
* Invokes the dashboard GUI to display the two dashboards that this seller is capable of viewing
*
* @param dashboardType The type of the dashboard the seller elects to view
* @param scrollPane The pane containing the data to be displayed on the dashboard
*/
public void displayDashboard(String dashboardType, JScrollPane scrollPane) {
displayDashboard.showDashboard(dashboardType, scrollPane);
}
/*
* Add event listeners for all buttons in the GUI
*/
@SuppressWarnings("unchecked")
ActionListener actionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Perform certain actions based on which button is clicked
if (e.getSource() == createStoreButton) {
String newStoreName = JOptionPane.showInputDialog(null, "What is the new store\'s name?",
"New Store Name", JOptionPane.QUESTION_MESSAGE);
if (newStoreName == null) {
return;
}
Object[] createStoreResult = sellerClient.createNewStore(newStoreName);
if (createStoreResult[0].equals("SUCCESS")) {
JOptionPane.showMessageDialog(null, createStoreResult[1], "Create Store",
JOptionPane.INFORMATION_MESSAGE);
} else {
displayErrorDialog((String) createStoreResult[1]);
}
} else if (e.getSource() == editStoreButton) {
Object[] getStoresResult = sellerClient.getStores();
// If this seller doesn't have any stores, display error message
if (getStoresResult[0].equals("ERROR")) {
String errorMessage = (String) getStoresResult[1];
displayErrorDialog(errorMessage);
return;
} else if (getStoresResult[0].equals("SUCCESS")) {
ArrayList<String> storeNames = (ArrayList<String>) getStoresResult[1];
String prevStoreName = (String) JOptionPane.showInputDialog(null,
"Which store\'s name would you like to edit?", "Stores",
JOptionPane.QUESTION_MESSAGE, null, storeNames.toArray(), storeNames.get(0));
if (prevStoreName == null) {
return;
}
String newStoreName = JOptionPane.showInputDialog(null, "What is the new name of the store?",
"New Store Name", JOptionPane.QUESTION_MESSAGE);
if (newStoreName == null) {
return;
}
Object[] modifyStoreResult = sellerClient.modifyStoreName(prevStoreName, newStoreName);
if (modifyStoreResult[0].equals("SUCCESS")) {
JOptionPane.showMessageDialog(null, modifyStoreResult[1], "Edit Store",
JOptionPane.INFORMATION_MESSAGE);
} else {
displayErrorDialog((String) modifyStoreResult[1]);
}
}
} else if (e.getSource() == deleteStoreButton) {
Object[] getStoresResult = sellerClient.getStores();
// If this seller doesn't have any stores, display error message
if (getStoresResult[0].equals("ERROR")) { // Error
String errorMessage = (String) getStoresResult[1];
displayErrorDialog(errorMessage);
return;
} else if (getStoresResult[0].equals("SUCCESS")) {
ArrayList<String> storeNames = (ArrayList<String>) getStoresResult[1];
String storeName = (String) JOptionPane.showInputDialog(null,
"Which store would you like to delete?", "Stores",
JOptionPane.QUESTION_MESSAGE, null, storeNames.toArray(), storeNames.get(0));
if (storeName == null) {
return;
}
Object[] deleteStoreResult = sellerClient.deleteStore(storeName);
if (deleteStoreResult[0].equals("SUCCESS")) {
JOptionPane.showMessageDialog(null, deleteStoreResult[1], "Delete Store",
JOptionPane.INFORMATION_MESSAGE);
} else {
displayErrorDialog((String) deleteStoreResult[1]);
}
}
} else if (e.getSource() == createProductButton) {
Object[] getStoresResult = sellerClient.getStores();
// If this seller doesn't have any stores, display error message
if (getStoresResult[0].equals("ERROR")) { // Error
String errorMessage = (String) getStoresResult[1];
displayErrorDialog(errorMessage);
return;
} else if (getStoresResult[0].equals("SUCCESS")) {
ArrayList<String> storeNames = (ArrayList<String>) getStoresResult[1];
String storeName = (String) JOptionPane.showInputDialog(null,
"Which store would you like to add the product to?", "Stores",
JOptionPane.QUESTION_MESSAGE, null, storeNames.toArray(), storeNames.get(0));
if (storeName == null) {
return;
} else {
new CreateProductGUI(sellerClient, storeName);
}
}
} else if (e.getSource() == editProductButton) {
Object[] getStoresResult = sellerClient.getStores();
// If this seller doesn't have any stores, display error message
if (getStoresResult[0].equals("ERROR")) { // Error
String errorMessage = (String) getStoresResult[1];
displayErrorDialog(errorMessage);
return;
} else if (getStoresResult[0].equals("SUCCESS")) {
ArrayList<String> storeNames = (ArrayList<String>) getStoresResult[1];
String storeName = (String) JOptionPane.showInputDialog(null,
"Which store contains the product you\'d like to edit?", "Stores",
JOptionPane.QUESTION_MESSAGE, null, storeNames.toArray(), storeNames.get(0));
if (storeName == null) {
return;
}
// Get the products associated with the selected store
Object[] getProductsResult = sellerClient.getStoreProducts(storeName);
if (getProductsResult[0].equals("ERROR")) {
String errorMessage = (String) getProductsResult[1];
displayErrorDialog(errorMessage);
return;
} else if (getProductsResult[0].equals("SUCCESS")) {
ArrayList<String> productNames = (ArrayList<String>) getProductsResult[1];
String productName = (String) JOptionPane.showInputDialog(null,
"Which product would you like to edit?", "Products",
JOptionPane.QUESTION_MESSAGE, null, productNames.toArray(), productNames.get(0));
if (productName == null) {
return;
}
String[] editParameters = {"Name", "Price", "Description", "Quantity", "Order Limit", "Sale Quantity, Sale Price"};
String editParam = (String) JOptionPane.showInputDialog(null,
"Which parameter would you like to edit?", "Edit Parameter",
JOptionPane.QUESTION_MESSAGE, null, editParameters, editParameters[0]);
if (editParam == null) {
return;
}
String newValue = JOptionPane.showInputDialog(null, "What is the new value?", "New Value",
JOptionPane.QUESTION_MESSAGE);
if (newValue == null) {
return;
}
Object[] editProductResult = sellerClient.editProduct(storeName, productName,
editParam.toLowerCase(), newValue);
if (editProductResult[0].equals("SUCCESS")) {
JOptionPane.showMessageDialog(null, editProductResult[1],
"Edit Product", JOptionPane.INFORMATION_MESSAGE);
} else {
displayErrorDialog((String) editProductResult[1]);
}
}
}
} else if (e.getSource() == deleteProductButton) {
Object[] getStoresResult = sellerClient.getStores();
// If this seller doesn't have any stores, display error message
if (getStoresResult[0].equals("ERROR")) { // Error
String errorMessage = (String) getStoresResult[1];
displayErrorDialog(errorMessage);
return;
} else if (getStoresResult[0].equals("SUCCESS")) {
ArrayList<String> storeNames = (ArrayList<String>) getStoresResult[1];
String storeName = (String) JOptionPane.showInputDialog(null,
"Which store contains the product you\'d like to delete?", "Stores",
JOptionPane.QUESTION_MESSAGE, null, storeNames.toArray(), storeNames.get(0));
if (storeName == null) {
return;
}
// Get the products associated with the selected store
Object[] getProductsResult = sellerClient.getStoreProducts(storeName);
if (getProductsResult[0].equals("ERROR")) {
String errorMessage = (String) getProductsResult[1];
displayErrorDialog(errorMessage);
return;
} else if (getProductsResult[0].equals("SUCCESS")) {
ArrayList<String> productNames = (ArrayList<String>) getProductsResult[1];
String productName = (String) JOptionPane.showInputDialog(null,
"Which product would you like to delete?", "Products",
JOptionPane.QUESTION_MESSAGE, null, productNames.toArray(), productNames.get(0));
if (productName == null) {
return;
}
Object[] deleteProductResult = sellerClient.deleteProduct(storeName, productName);
if (deleteProductResult[0].equals("SUCCESS")) {
JOptionPane.showMessageDialog(null, deleteProductResult[1],
"Delete Product", JOptionPane.INFORMATION_MESSAGE);
} else {
displayErrorDialog((String) deleteProductResult[1]);
}
}
}
} else if (e.getSource() == importProductsButton) {
Object[] getStoresResult = sellerClient.getStores();
// If this seller doesn't have any stores, display error message
if (getStoresResult[0].equals("ERROR")) { // Error
String errorMessage = (String) getStoresResult[1];
displayErrorDialog(errorMessage);
return;
} else if (getStoresResult[0].equals("SUCCESS")) {
String filePath = JOptionPane.showInputDialog(null,
"What is the name of the file that contains the products?", "File Name",
JOptionPane.QUESTION_MESSAGE);
if (filePath == null) {
return;
}
ArrayList<String> storeNames = (ArrayList<String>) getStoresResult[1];
String storeName = (String) JOptionPane.showInputDialog(null,
"Which store would you like to import the products into?", "Stores",
JOptionPane.QUESTION_MESSAGE, null, storeNames.toArray(), storeNames.get(0));
if (storeName == null) {
return;
}
Object[] importProductsResult = sellerClient.importProducts(filePath, storeName);
if (importProductsResult[0].equals("SUCCESS")) {
JOptionPane.showMessageDialog(null, importProductsResult[1],
"Import Products", JOptionPane.INFORMATION_MESSAGE);
} else {
displayErrorDialog((String) importProductsResult[1]);
}
}
} else if (e.getSource() == exportProductsButton) {
Object[] getStoresResult = sellerClient.getStores();
// If this seller doesn't have any stores, display error message
if (getStoresResult[0].equals("ERROR")) { // Error
String errorMessage = (String) getStoresResult[1];
displayErrorDialog(errorMessage);
return;
} else if (getStoresResult[0].equals("SUCCESS")) {
ArrayList<String> storeNames = (ArrayList<String>) getStoresResult[1];
String storeName = (String) JOptionPane.showInputDialog(null,
"Which store would you like to export the products from?", "Stores",
JOptionPane.QUESTION_MESSAGE, null, storeNames.toArray(), storeNames.get(0));
if (storeName == null) {
return;
}
Object[] exportProductsResult = sellerClient.exportProducts(storeName);
if (exportProductsResult[0].equals("SUCCESS")) {
JOptionPane.showMessageDialog(null, exportProductsResult[1],
"Export Products", JOptionPane.INFORMATION_MESSAGE);
} else {
displayErrorDialog((String) exportProductsResult[1]);
}
}
} else if (e.getSource() == viewProductReviewsButton) {
Object[] getStoresResult = sellerClient.getStores();
// If this seller doesn't have any stores, display error message
if (getStoresResult[0].equals("ERROR")) { // Error
String errorMessage = (String) getStoresResult[1];
displayErrorDialog(errorMessage);
return;
} else if (getStoresResult[0].equals("SUCCESS")) {
ArrayList<String> storeNames = (ArrayList<String>) getStoresResult[1];
String storeName = (String) JOptionPane.showInputDialog(null,
"Which store contains the product you\'d like to view the review for?", "Stores",
JOptionPane.QUESTION_MESSAGE, null, storeNames.toArray(), storeNames.get(0));
if (storeName == null) {
return;
}
// Get the products associated with the selected store
Object[] getProductsResult = sellerClient.getStoreProducts(storeName);
if (getProductsResult[0].equals("ERROR")) {
String errorMessage = (String) getProductsResult[1];
displayErrorDialog(errorMessage);
return;
} else if (getProductsResult[0].equals("SUCCESS")) {
ArrayList<String> productNames = (ArrayList<String>) getProductsResult[1];
String productName = (String) JOptionPane.showInputDialog(null,
"Which product\'s review would you like to view?", "Products",
JOptionPane.QUESTION_MESSAGE, null, productNames.toArray(), productNames.get(0));
if (productName == null) {
return;
}
Object[] viewProductReviewResult = sellerClient.viewProductReviews(storeName, productName);
if (viewProductReviewResult[0].equals("SUCCESS")) {
HashMap<String, ArrayList<String>> productReviews =
(HashMap<String, ArrayList<String>>) viewProductReviewResult[1];
String info = "";
for (String customerEmail : productReviews.keySet()) {
info += customerEmail + "\n";
for (String review : productReviews.get(customerEmail)) {
info += "\t" + review + "\n";
}
}
JOptionPane.showMessageDialog(null, info, "Product Reviews",
JOptionPane.INFORMATION_MESSAGE);
} else {
displayErrorDialog((String) viewProductReviewResult[1]);
}
}
}
} else if (e.getSource() == viewCustomerShoppingCartsButton) {
Object[] getCustomerShoppingCartsResult = sellerClient.viewCustomerShoppingCarts();
if (getCustomerShoppingCartsResult[0].equals("ERROR")) {
String errorMessage = (String) getCustomerShoppingCartsResult[1];
displayErrorDialog(errorMessage);
return;
} else if (getCustomerShoppingCartsResult[0].equals("SUCCESS")) {
HashMap<String, ArrayList<String>> shoppingCarts =
(HashMap<String, ArrayList<String>>) getCustomerShoppingCartsResult[1];
String info = "";
for (String store : shoppingCarts.keySet()) {
info += store + "\n";
for (String saleInformation : shoppingCarts.get(store)) {
info += "\t" + saleInformation + "\n";
}
}
JOptionPane.showMessageDialog(null, info, "Customer Shopping Carts",
JOptionPane.INFORMATION_MESSAGE);
}
} else if (e.getSource() == viewSalesByStoreButton) {
Object[] getSalesByStoreResult = sellerClient.viewSalesByStore();
if (getSalesByStoreResult[0].equals("ERROR")) {
String errorMessage = (String) getSalesByStoreResult[1];
displayErrorDialog(errorMessage);
return;
} else if (getSalesByStoreResult[0].equals("SUCCESS")) {
HashMap<String, ArrayList<String>> salesByStore =
(HashMap<String, ArrayList<String>>) getSalesByStoreResult[1];
String info = "";
for (String store : salesByStore.keySet()) {
info += store + "\n";
for (String saleInformation : salesByStore.get(store)) {
info += "\t" + saleInformation + "\n";
}
}
JOptionPane.showMessageDialog(null, info, "Sales by Store",
JOptionPane.INFORMATION_MESSAGE);
}
} else if (e.getSource() == viewCustomerDashboardButton) {
Object[] getAllCustomersResult = sellerClient.fetchAllCustomers();
if (getAllCustomersResult[0].equals("ERROR")) {
displayErrorDialog((String) getAllCustomersResult[1]);
return;
} else {
String[] sortChoices = {"Customer Email", "Quantity Purchased", "Money Spent"};
String sortChoice = (String) JOptionPane.showInputDialog(null,
"How would you like to sort the dashboard?", "Dashboard Sort Choice",
JOptionPane.QUESTION_MESSAGE, null, sortChoices, sortChoices[0]);
if (sortChoice == null) {
return;
}
String orderChoice = (String) JOptionPane.showInputDialog(null,
"In what order would you like to sort the dashboard?", "Sorting Order",
JOptionPane.QUESTION_MESSAGE, null, sortOrderChoices, sortOrderChoices[0]);
if (orderChoice == null) {
return;
}
boolean ascending = orderChoice.equals("Ascending") ? true : false;
int sortSelection = Arrays.binarySearch(sortChoices, sortChoice) + 1;
Object[] customerDashboardResult =
sellerClient.sellerGetCustomersDashboard(sortSelection, ascending);
if (customerDashboardResult[0].equals("ERROR")) {
String errorMessage = (String) customerDashboardResult[1];
displayErrorDialog(errorMessage);
return;
} else if (customerDashboardResult[0].equals("SUCCESS")) {
ArrayList<String> customerDashboard = (ArrayList<String>) customerDashboardResult[1];
Object[][] data = new Object[customerDashboard.size()][3];
for (int i = 0; i < customerDashboard.size(); i++) {
String[] elems = customerDashboard.get(i).split(",");
System.arraycopy(elems, 0, data[i], 0, elems.length);
}
JTable table = new JTable(data, sortChoices);
JScrollPane scrollPane = new JScrollPane(table);
displayDashboard("Customers", scrollPane);
}
}
} else if (e.getSource() == viewProductDashboardButton) {
Object[] getAllProductsResult = sellerClient.fetchAllProducts();
if (getAllProductsResult[0].equals("ERROR")) {
displayErrorDialog((String) getAllProductsResult[1]);
return;
} else {
String[] sortChoices = {"Product Name", "Quantity Sold", "Total revenue"};
String sortChoice = (String) JOptionPane.showInputDialog(null,
"How would you like to sort the dashboard?", "Dashboard Sort Choice",
JOptionPane.QUESTION_MESSAGE, null, sortChoices, sortChoices[0]);
if (sortChoice == null) {
return;
}
String orderChoice = (String) JOptionPane.showInputDialog(null,
"In what order would you like to sort the dashboard?", "Sorting Order",
JOptionPane.QUESTION_MESSAGE, null, sortOrderChoices, sortOrderChoices[0]);
if (orderChoice == null) {
return;
}
boolean ascending = orderChoice.equals("Ascending") ? true : false;
int sortSelection = Arrays.binarySearch(sortChoices, sortChoice) + 1;
Object[] productDashboardResult = sellerClient.sellerGetProductsDashboard(sortSelection, ascending);
if (productDashboardResult[0].equals("ERROR")) {
String errorMessage = (String) productDashboardResult[1];
displayErrorDialog(errorMessage);
return;
} else if (productDashboardResult[0].equals("SUCCESS")) {
ArrayList<String> productDashboard = (ArrayList<String>) productDashboardResult[1];
Object[][] data = new Object[productDashboard.size()][3];
for (int i = 0; i < productDashboard.size(); i++) {
String[] elems = productDashboard.get(i).split(",");
System.arraycopy(elems, 0, data[i], 0, elems.length);
}
JTable table = new JTable(data, sortChoices);
JScrollPane scrollPane = new JScrollPane(table);
displayDashboard("Products", scrollPane);
}
}
} else if (e.getSource() == editEmailButton) {
String newEmail = JOptionPane.showInputDialog(null, "What is the new email?", "Edit Email",
JOptionPane.QUESTION_MESSAGE);
if (newEmail == null) {
return;
}
Object[] editEmailResult = sellerClient.editEmail(newEmail);
// editEmailResult[1] now contains the modified email
if (editEmailResult[0].equals("SUCCESS")) {
JOptionPane.showMessageDialog(null, "Email edited successfully!", "Edit Email",
JOptionPane.INFORMATION_MESSAGE);
sellerFrame.dispose();
sellerClient.homepage((String) editEmailResult[1]);
} else {
displayErrorDialog((String) editEmailResult[1]);
}
} else if (e.getSource() == editPasswordButton) {
String newPassword = JOptionPane.showInputDialog(null, "What is the new password?", "Edit Password",
JOptionPane.QUESTION_MESSAGE);
if (newPassword == null) {
return;
}
Object[] editPasswordResult = sellerClient.editPassword(newPassword);
if (editPasswordResult[0].equals("SUCCESS")) {
JOptionPane.showMessageDialog(null, editPasswordResult[1], "Edit Password",
JOptionPane.INFORMATION_MESSAGE);
} else {
displayErrorDialog((String) editPasswordResult[1]);
}
} else if (e.getSource() == deleteAccountButton) {
int deleteAccount = JOptionPane.showOptionDialog(null,
"Are you sure you want to delete your account?", "Delete Account",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new Object[]{"Yes", "No"}, null);
if (deleteAccount == JOptionPane.YES_OPTION) {
Object[] deleteAccountResult = sellerClient.deleteAccount();
if (deleteAccountResult[0].equals("SUCCESS")) {
try {
sellerFrame.dispose();
sellerClient.handleAccountState();
} catch (IOException ex) {
return;
}
} else {
displayErrorDialog((String) deleteAccountResult[1]);
}
}
} else if (e.getSource() == signOutButton) {
int signOut = JOptionPane.showOptionDialog(null,
"Are you sure you want to sign out?", "Sign out", JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE, null, new Object[]{"Yes", "No"}, null);
if (signOut == JOptionPane.YES_OPTION) {
Object[] signOutResult = sellerClient.signOut();
if (signOutResult[0].equals("SUCCESS")) {
try {
sellerFrame.dispose();
sellerClient.handleAccountState();
} catch (IOException ex) {
return;
}
} else {
displayErrorDialog((String) signOutResult[1]);
}
}
}
}
};
/**
* Constructs the GUI for a Seller and displays it
*
* @param customerClient The client to handle this seller GUI's communication with the server
* @param email The current seller's email
*/
public SellerGUI(SellerClient sellerClient, String email) {
this.sellerClient = sellerClient;
sellerFrame = new JFrame(email + "\'s" + " Home Page");
JPanel buttonPanel = new JPanel(new GridLayout(8, 2, 5, 5));
buttonPanel.setBorder(new EmptyBorder(20, 20, 20, 20));
sellerFrame.setSize(650, 750);
sellerFrame.setLocationRelativeTo(null);
sellerFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Welcome message label initialization
welcomeUserLabel = new JLabel("Welcome " + email + "!", SwingConstants.CENTER);
welcomeUserLabel.setBorder(new EmptyBorder(10, 0, 0, 0));
welcomeUserLabel.setFont(new Font("Serif", Font.BOLD, 20));
// Seller permission button initialization
createStoreButton = new JButton("Create Store");
createStoreButton.addActionListener(actionListener);
editStoreButton = new JButton("Edit Store");
editStoreButton.addActionListener(actionListener);
deleteStoreButton = new JButton("Delete Store");
deleteStoreButton.addActionListener(actionListener);
createProductButton = new JButton("Add Product");
createProductButton.addActionListener(actionListener);
editProductButton = new JButton("Edit Product");
editProductButton.addActionListener(actionListener);
deleteProductButton = new JButton("Delete Product");
deleteProductButton.addActionListener(actionListener);
importProductsButton = new JButton("Import Products");
importProductsButton.addActionListener(actionListener);
exportProductsButton = new JButton("Export Products");
exportProductsButton.addActionListener(actionListener);
viewProductReviewsButton = new JButton("View Product Reviews");
viewProductReviewsButton.addActionListener(actionListener);
viewCustomerShoppingCartsButton = new JButton("View Customer Shopping Carts");
viewCustomerShoppingCartsButton.addActionListener(actionListener);
viewSalesByStoreButton = new JButton("View Sales by Store");
viewSalesByStoreButton.addActionListener(actionListener);
viewCustomerDashboardButton = new JButton("View Customers Dashboard");
viewCustomerDashboardButton.addActionListener(actionListener);
viewProductDashboardButton = new JButton("View Products Dashboard");
viewProductDashboardButton.addActionListener(actionListener);
editEmailButton = new JButton("Edit Email");
editEmailButton.addActionListener(actionListener);
editPasswordButton = new JButton("Edit Password");
editPasswordButton.addActionListener(actionListener);
deleteAccountButton = new JButton("Delete Account");
deleteAccountButton.addActionListener(actionListener);
signOutButton = new JButton("Sign Out");
signOutButton.addActionListener(actionListener);
buttonPanel.add(createStoreButton);
buttonPanel.add(editStoreButton);
buttonPanel.add(deleteStoreButton);
buttonPanel.add(createProductButton);
buttonPanel.add(editProductButton);
buttonPanel.add(deleteProductButton);
buttonPanel.add(importProductsButton);
buttonPanel.add(exportProductsButton);
buttonPanel.add(viewProductReviewsButton);
buttonPanel.add(viewCustomerShoppingCartsButton);
buttonPanel.add(viewSalesByStoreButton);
buttonPanel.add(viewCustomerDashboardButton);
buttonPanel.add(viewProductDashboardButton);
buttonPanel.add(editEmailButton);
buttonPanel.add(editPasswordButton);
buttonPanel.add(deleteAccountButton);
buttonPanel.add(signOutButton);
sellerFrame.add(welcomeUserLabel, BorderLayout.NORTH);
sellerFrame.add(buttonPanel, BorderLayout.CENTER);
sellerFrame.setVisible(true);
}
}