· 9 years ago · Sep 15, 2017, 12:38 PM
1/**
2 * @author Marcel Bieler
3 */
4
5package userInterface;
6
7import java.awt.BorderLayout;
8import java.awt.EventQueue;
9import java.awt.event.MouseAdapter;
10import java.awt.event.MouseEvent;
11import java.io.*;
12import java.net.*;
13import java.util.*;
14import javax.swing.*;
15import com.jgoodies.forms.factories.FormFactory;
16import com.jgoodies.forms.layout.ColumnSpec;
17import com.jgoodies.forms.layout.FormLayout;
18import com.jgoodies.forms.layout.RowSpec;
19
20
21import appLogic.Article;
22import appLogic.AuctionArticle;
23import appLogic.Bid;
24import appLogic.Category;
25import appLogic.Message;
26import appLogic.SalesItem;
27import appLogic.User;
28import appLogicAccess.MyTableModel;
29
30import java.awt.event.ActionListener;
31import java.awt.event.ActionEvent;
32import javax.swing.event.ListSelectionListener;
33import javax.swing.event.ListSelectionEvent;
34import javax.swing.table.TableColumn;
35import javax.swing.table.TableModel;
36
37public class GUI {
38
39 private ArrayList<Article> articleList = new ArrayList<Article>();
40 private ArrayList<User> userList = new ArrayList<User>();
41 private ArrayList<Message> messageList = new ArrayList<Message>();
42 private ArrayList<Category> categoryList = new ArrayList<Category>();
43 private ArrayList<Category> changeCategoryList = new ArrayList<Category>();
44
45 private Article editArticle;
46
47 private boolean loginBool;
48 private boolean regBool;
49 private boolean changeBool;
50 private boolean deleteBool;
51 private boolean setNewPrice;
52 private boolean changeSoldFlagBool;
53 private boolean buyBool;
54 private boolean bidBool;
55 private boolean lockBool;
56 private boolean unlockBool;
57 private boolean deleteArticleBool;
58
59 private double currentlyHightestBidOnArticle;
60
61 private int newSetArticleNo = -1;
62
63 private ObjectOutputStream oos = null;
64 private ObjectInputStream ois = null;
65 private Socket socket = null;
66
67 private String usernameTempSaved = null;
68 private String befehl = null;
69 private String antwort = null;
70
71 private DefaultComboBoxModel categoryDataModel;
72 private DefaultListModel currentCategorySelectionListModel;
73 private DefaultListModel currentArticleCategoriesListModel;
74 private DefaultListModel categoriesListModel;
75
76 private JButton btnLogin;
77 private JButton btnLogout;
78 private JButton btnRegister;
79 private JButton btnAddCategory;
80 private JButton btnAddNewCategory;
81 private JButton btnInsertArticle;
82 private JButton btnRemoveSelectedCategory;
83 private JButton editArticleAddCategoryButton;
84 private JButton changeArticleDataAddNewCategoryButton;
85 private JButton btnSetSelectedArticle;
86 private JButton btnDeleteSelectedArticle;
87 private JButton btnSearch;
88 private JButton btnRefreshCategories;
89 private JButton btnBuyArticle;
90 private JButton btnBidOnArticle;
91 private JButton btnChangeBid;
92 private JButton btnShowArticleDetails;
93 //button will most likely be deleted
94// private JButton btnShowSelectedCategory;
95 private JButton btnUpdateArticleList;
96 private JButton btnEditSelectedArticle;
97 private JButton btnSetNewPrice;
98 private JButton btnAddToDescription;
99 private JButton btnShowMessages;
100 private JButton btnHideOldMessages;
101 private JButton btnChangeOk;
102 private JButton changeArticleDataRemoveSelectedCategoryButton;
103 private JButton btnAufDeutschBitte;
104 private JButton btnDelete;
105 private JButton btnLock;
106 private JButton btnUnlock;
107 private JButton btnShowArticles;
108 private JButton btnShowUsers;
109 private JButton btnShowAllMessages;
110 private JButton btnDeleteArticle;
111
112 private JCheckBox chckbxShowPhonenoOn;
113 private JCheckBox chckbxShowEmailOn;
114 private JComboBox comboBoxChangeUserdata;
115 private JComboBox comboBox;
116 private JComboBox categorySelectionComboBox;
117 private JComboBox editArticleCategorySelectionComboBox;
118 private JComboBox searchMethodSelectionComboBox;
119
120 private JFrame frame;
121
122 private JLabel lblTitle;
123 private JLabel lblCurrentPrice;
124 private JLabel lblAuctionEnd;
125 private JLabel lblDescription;
126 private JLabel lblArticleTitleHere;
127 private JLabel lblCurrentPriceHere;
128 private JLabel lblAuctionEndAnd;
129 private JLabel lblArticleno;
130 private JLabel lblSoldBy;
131 private JLabel lblPhoneno;
132 private JLabel lblEmail;
133 private JLabel lblNoOfBids;
134 private JLabel lblDisplayNoOfBids;
135 private JLabel lblArticlenoHere;
136 private JLabel lblVendorNameHere;
137 private JLabel lblPhonenoHere;
138 private JLabel lblEmailHere;
139 private JLabel lblArticlesInSelected;
140 private JLabel lblYourMaxBid;
141 private JLabel lblMaxBidHere;
142 private JLabel lblChange;
143 private JLabel lblTo;
144 private JLabel lblFormatYymmdd;
145 private JLabel lblSelectedCategories;
146 private JLabel lblMultiplesOf;
147 private JLabel changeArticleDataSelectedCategoriesLabel;
148 private JLabel changeSuccessLabel;
149 private JLabel welcomeLabel;
150
151 private JList currentCategorySelectionList;
152 private JList currentArticleCategoriesList;
153 private JList categoryListBuyTab;
154
155 private JPanel adminPanel;
156 private JPanel adminControlsPanel;
157 private JPanel showMyArticlesPanel;
158 private JPanel articleDetailsPanel;
159 private JPanel buyTabPanel;
160 private JPanel sellTabPanel;
161 private JPanel messagePanel;
162 private JPanel userControlCenterPanel;
163 private JPanel adminControlsPanel2;
164 private JPanel loginPanel;
165
166 private JScrollPane articleDescriptionTextAreaScrollPane;
167 private JScrollPane currentCategorySelectionListScrollPane;
168 private JScrollPane showMyArticlesTableScrollPane;
169 private JScrollPane txtrCurrentDescriptionScrollPane;
170 private JScrollPane addToCurrentDescriptionScrollPane;
171 private JScrollPane currentArticleCategoriesListScrollPane;
172 private JScrollPane messageTableScrollPane;
173 private JScrollPane categoryListBuyTabScrollPane;
174 private JScrollPane articleTableBuyTabScrollPane;
175 private JScrollPane articleDescriptionTextAreaBuyTabScrollPane;
176 private JScrollPane adminArticleTableScrollPane;
177
178 private JTabbedPane tabbedPane;
179 private JTable showMyArticlesTable;
180 private JTable messageTable;
181 private JTable articleTableBuyTab;
182 private JTable adminArticleTable;
183
184 private JTextArea articleDescriptionTextArea;
185 private JTextArea txtrCurrentDescription;
186 private JTextArea txtrAddToCurrentDescription;
187 private JTextArea articleDescriptionTextAreaBuyTab;
188
189 private JTextField txtUsernameToEdit;
190 private JTextField txtUsername;
191 private JTextField txtPassword;
192 private JTextField txtArticleTitle;
193 private JTextField txtChangeNewValue;
194 private JTextField txtNewCategory;
195 private JTextField txtPrice;
196 private JTextField txtAuctionEndDate;
197 private JTextField changeArticleDataNewCategoryTextField;
198 private JTextField changeArticleDataChangePriceTextField;
199 private JTextField txtEnterSearchTerm;
200
201 /**
202 * Launch the application.
203 */
204 public static void main(String[] args) {
205 EventQueue.invokeLater(new Runnable() {
206 public void run() {
207 try {
208 GUI window = new GUI();
209 window.frame.setVisible(true);
210 } catch (Exception e) {
211 e.printStackTrace();
212 }
213 }
214 });
215 }
216
217 /**
218 * Create the application.
219 *
220 * @throws Exception
221 */
222 public GUI() {
223 Messages.changeLanguage();
224 initialize();
225 }
226
227 /**
228 * connects to the server. ip is hardcoded. first creates a new socket and
229 * then opens an objectinputstream and an objectoutputstream
230 */
231 public void connectToServer() {
232 byte[] addr = new byte[4];
233
234 addr[0] = (byte) 172;
235 addr[1] = (byte) 20;
236 addr[2] = (byte) 10;
237 addr[3] = (byte) 2;
238
239
240
241
242 InetAddress host;
243 try {
244 host = InetAddress.getByAddress(addr);
245 socket = new Socket(host.getHostName(), 1234);
246 oos = new ObjectOutputStream(socket.getOutputStream());
247 ois = new ObjectInputStream(socket.getInputStream());
248 } catch (UnknownHostException e1) {
249 JOptionPane
250 .showMessageDialog(
251 null,
252 Messages.getString("GUI.FailedToConnect"), //$NON-NLS-1$
253 Messages.getString("GUI.ConnectionProblem"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
254 } catch (IOException e) {
255 JOptionPane
256 .showMessageDialog(
257 null,
258 Messages.getString("GUI.FailedToConnect2"), //$NON-NLS-1$
259 Messages.getString("GUI.ConnectionProblem2"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
260 }
261 }
262
263 /**
264 * converts a time, represented by a gregoriancalendar, to a string that
265 * indicated the remaining time from now (systemtime) until the given date.
266 *
267 * @param cal2
268 * the gregoriancalendar representation of an auction end date
269 * @return a textual representation of the date difference from systemtime
270 * until given calendar. format: XXT: HH : MM : SS
271 */
272 public String dateDifferenceToString(GregorianCalendar cal2) {
273 GregorianCalendar cal1 = new GregorianCalendar();
274 String timeString = new String();
275 // cal1 = current time, cal1 = auction end
276 long differenceSeconds = cal2.getTimeInMillis()
277 - cal1.getTimeInMillis();
278 int day = 0;
279 int hour = 0;
280 int minute = 0;
281 int second = 0;
282 long longday = 1000 * 60 * 60 * 24;
283 long longhour = 1000 * 60 * 60;
284 long longminute = 1000 * 60;
285 long longsecond = 1000;
286
287 while (differenceSeconds > 999) {
288 if (differenceSeconds - longsecond >= 0) {
289 if (differenceSeconds - longminute >= 0) {
290 if (differenceSeconds - longhour >= 0) {
291 if (differenceSeconds - longday >= 0) {
292 day++;
293 differenceSeconds -= longday;
294 continue;
295 }
296 hour++;
297 differenceSeconds -= longhour;
298 continue;
299 }
300 minute++;
301 differenceSeconds -= longminute;
302 continue;
303 }
304 second++;
305 differenceSeconds -= longsecond;
306 continue;
307 }
308 }
309 // if 1000ms are left add a second
310 if (differenceSeconds < 1000 && differenceSeconds > 499) {
311 second++;
312 }
313
314 if (second >= 60) {
315 minute++;
316 second -= 60;
317 if (minute >= 60) {
318 hour++;
319 minute -= 60;
320 if (hour >= 24) {
321 day++;
322 hour -= 24;
323 }
324 }
325 }
326
327 String daystring;
328 if (day > 9 && day < 100) {
329 daystring = "0" + String.valueOf(day); //$NON-NLS-1$
330 } else if (day < 10) {
331 daystring = "00" + String.valueOf(day); //$NON-NLS-1$
332 } else {
333 daystring = String.valueOf(day);
334 }
335
336 String hourstring;
337 if (hour > 9) {
338 hourstring = String.valueOf(hour);
339 } else {
340 hourstring = "0" + String.valueOf(hour); //$NON-NLS-1$
341 }
342
343 String minutestring;
344 if (minute > 9) {
345 minutestring = String.valueOf(minute);
346 } else {
347 minutestring = "0" + String.valueOf(minute); //$NON-NLS-1$
348 }
349
350 String secondstring;
351 if (second > 9) {
352 secondstring = String.valueOf(second);
353 } else {
354 secondstring = "0" + String.valueOf(second); //$NON-NLS-1$
355 }
356
357 timeString = daystring + "d " + hourstring + "h " + minutestring + "m " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
358 + secondstring + "s"; //$NON-NLS-1$
359
360 return timeString;
361 }
362
363 /**
364 * converts the given gregoriancalendar into a textual representation
365 * (YY.MM.DD or YY.MM.DD HH:MM:SS) of the saved date.
366 *
367 * @param cal
368 * the gregoriancalendar to be transformed into a String
369 * @param method
370 * decides if the return String represents the date with or
371 * without time
372 * @return String representation of input calendar
373 */
374 public String gregorianToString(GregorianCalendar cal, String method) {
375 // year to string. cut first 2 digits. thanks crappy dateformat...
376 String year = String.valueOf(cal.get(Calendar.YEAR)).substring(2);
377
378 // month to string. if single digit add leading zero
379 String month = new String();
380 int intmonth = cal.get(Calendar.MONTH);
381 // january is 0 so month+1 is needed
382 intmonth++;
383 if (intmonth < 10) {
384 month = "0" + String.valueOf(intmonth); //$NON-NLS-1$
385 } else {
386 month = String.valueOf(intmonth);
387 }
388
389 // day to string. if single digit add leading zero
390 String day = new String();
391 int intday = cal.get(Calendar.DATE);
392 if (intday < 10) {
393 day = "0" + String.valueOf(intday); //$NON-NLS-1$
394 } else {
395 day = String.valueOf(intday);
396 }
397
398 // if the long version is needed
399 if (method.equals("long")) { //$NON-NLS-1$
400 String hour = new String();
401 int conversionHour = cal.get(Calendar.HOUR_OF_DAY);
402 if (conversionHour < 10) {
403 hour = "0" + String.valueOf(conversionHour); //$NON-NLS-1$
404 } else {
405 hour = String.valueOf(conversionHour);
406 }
407
408 String minute = new String();
409 int conversionMinute = cal.get(Calendar.MINUTE);
410 if (conversionMinute < 10) {
411 minute = "0" + String.valueOf(conversionMinute); //$NON-NLS-1$
412 } else {
413 minute = String.valueOf(conversionMinute);
414 }
415
416 String second = new String();
417 int conversionSecond = cal.get(Calendar.SECOND);
418 if (conversionSecond < 10) {
419 second = "0" + String.valueOf(conversionSecond); //$NON-NLS-1$
420 } else {
421 second = String.valueOf(conversionSecond);
422 }
423
424 // join year, month, day, hour, minute and second
425 String date = year + "." + month + "." + day + " " + hour + ":" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
426 + minute + ":" + second; //$NON-NLS-1$
427
428 return date;
429
430 // if the long version is not required, take the short one
431 } else {
432 // join year, month and day
433 String date = year + "." + month + "." + day; //$NON-NLS-1$ //$NON-NLS-2$
434
435 return date;
436 }
437 }
438
439 public void transmissionError(String cause) {
440 JOptionPane.showMessageDialog(null, cause,
441 Messages.getString("GUI.ThereWasAProblem"), //$NON-NLS-1$
442 JOptionPane.WARNING_MESSAGE);
443 }
444
445 /**
446 * analyzes the input command and then transfers it to the server, where it
447 * is processed. then the return value sent by the server is saved.
448 *
449 * @param command
450 * command to be executed
451 */
452 public void execute(String command) {
453 try {
454 if (command.startsWith("LOGIN ")) { //$NON-NLS-1$
455 if (oos != null) {
456 oos.writeObject(command);
457
458 if ((Boolean) ois.readObject()) {
459 Exception shouldNotHappen = (Exception) ois
460 .readObject();
461 transmissionError(shouldNotHappen.getMessage());
462 loginBool = false;
463 } else {
464 loginBool = (Boolean) ois.readObject();
465 }
466
467 }
468
469 } else if (command.startsWith("INSERT USER ")) { //$NON-NLS-1$
470 if (oos != null) {
471 oos.writeObject(command);
472
473 if ((Boolean) ois.readObject()) {
474 Exception shouldNotHappen = (Exception) ois
475 .readObject();
476 transmissionError(shouldNotHappen.getMessage());
477 regBool = false;
478 } else {
479 regBool = (Boolean) ois.readObject();
480 }
481
482 }
483
484 } else if (command.startsWith("CHANGE USER ")) { //$NON-NLS-1$
485 if (oos != null) {
486 oos.writeObject(command);
487
488 if ((Boolean) ois.readObject()) {
489 Exception shouldNotHappen = (Exception) ois
490 .readObject();
491 transmissionError(shouldNotHappen.getMessage());
492 changeBool = false;
493 } else {
494 changeBool = (Boolean) ois.readObject();
495 }
496
497 }
498
499 } else if (command.startsWith("DELETE USER")) { //$NON-NLS-1$
500 if (oos != null) {
501 oos.writeObject(command);
502
503 if ((Boolean) ois.readObject()) {
504 Exception shouldNotHappen = (Exception) ois
505 .readObject();
506 transmissionError(shouldNotHappen.getMessage());
507 deleteBool = false;
508 } else {
509 deleteBool = (Boolean) ois.readObject();
510 }
511
512 }
513
514 } else if (command.startsWith("LIST USER")) { //$NON-NLS-1$
515 if (oos != null) {
516 oos.writeObject(command);
517 articleList = (ArrayList<Article>) ois.readObject();
518 }
519
520 } else if (command.startsWith("LOCK USER")) { //$NON-NLS-1$
521 if (oos != null) {
522 oos.writeObject(command);
523
524 if ((Boolean) ois.readObject()) {
525 Exception shouldNotHappen = (Exception) ois
526 .readObject();
527 transmissionError(shouldNotHappen.getMessage());
528 lockBool = false;
529 } else {
530 lockBool = (Boolean) ois.readObject();
531 }
532
533 }
534
535 } else if (command.startsWith("UNLOCK USER")) { //$NON-NLS-1$
536 if (oos != null) {
537 oos.writeObject(command);
538
539 if ((Boolean) ois.readObject()) {
540 Exception shouldNotHappen = (Exception) ois
541 .readObject();
542 transmissionError(shouldNotHappen.getMessage());
543 unlockBool = false;
544 } else {
545 unlockBool = (Boolean) ois.readObject();
546 }
547
548 }
549
550 } else if (command.startsWith("DELETE ARTICLE")) { //$NON-NLS-1$
551 if (oos != null) {
552 oos.writeObject(command);
553
554 if ((Boolean) ois.readObject()) {
555 Exception shouldNotHappen = (Exception) ois
556 .readObject();
557 transmissionError(shouldNotHappen.getMessage());
558 deleteArticleBool = false;
559 } else {
560 deleteArticleBool = (Boolean) ois.readObject();
561 }
562 }
563
564 } else if (command.startsWith("SHOW USERS")) { //$NON-NLS-1$
565 if (oos != null) {
566 oos.writeObject(command);
567 userList = (ArrayList<User>) ois.readObject();
568 }
569
570 } else if (command.startsWith("SHOW MESSAGES")) { //$NON-NLS-1$
571 if (oos != null) {
572 oos.writeObject(command);
573 // TODO empty messagelist is no error. have to change it
574 // there was an error. create empty messagelist and show the
575 // error
576 if ((Boolean) ois.readObject()) {
577 messageList = new ArrayList<Message>();
578 Exception shouldNotHappen = (Exception) ois
579 .readObject();
580 //TODO wegmachen wenn der fehler nicht mehr fliegt
581 // transmissionError(shouldNotHappen.getMessage());
582 // there was no error. proceed as planned
583 } else {
584 messageList = (ArrayList<Message>) ois.readObject();
585 }
586 }
587
588 } else if (command.startsWith("SHOW CATEGORIES")) { //$NON-NLS-1$
589 if (oos != null) {
590 oos.writeObject(command);
591 categoryList = (ArrayList<Category>) ois.readObject();
592 }
593
594 } else if (command.startsWith("INSERT SALE")) { //$NON-NLS-1$
595 if (oos != null) {
596 oos.writeObject(command);
597
598 if ((Boolean) ois.readObject()) {
599 Exception shouldNotHappen = (Exception) ois
600 .readObject();
601 transmissionError(shouldNotHappen.getMessage());
602 newSetArticleNo = -1;
603 } else {
604 newSetArticleNo = (Integer) ois.readObject();
605 }
606 }
607
608 } else if (command.startsWith("INSERT AUCTION")) { //$NON-NLS-1$
609 if (oos != null) {
610 oos.writeObject(command);
611
612 if ((Boolean) ois.readObject()) {
613 Exception shouldNotHappen = (Exception) ois
614 .readObject();
615 transmissionError(shouldNotHappen.getMessage());
616 newSetArticleNo = -1;
617 } else {
618 newSetArticleNo = (Integer) ois.readObject();
619 }
620 }
621
622 } else if (command.startsWith("ADD DESCRIPTION")) { //$NON-NLS-1$
623 if (oos != null) {
624 oos.writeObject(command);
625
626 // there was an error. show it
627 if ((Boolean) ois.readObject()) {
628 Exception shouldNotHappen = (Exception) ois
629 .readObject();
630 transmissionError(shouldNotHappen.getMessage());
631 }
632 // nothing else because there is no return value
633 }
634
635 } else if (command.startsWith("ADD CATEGORY")) { //$NON-NLS-1$
636 if (oos != null) {
637 oos.writeObject(command);
638
639 // there was an error. show it
640 if ((Boolean) ois.readObject()) {
641 Exception shouldNotHappen = (Exception) ois
642 .readObject();
643 transmissionError(shouldNotHappen.getMessage());
644 }
645 // nothing else because there is no return value
646 }
647
648 } else if (command.startsWith("SHOW PHONE")) { //$NON-NLS-1$
649 if (oos != null) {
650 oos.writeObject(command);
651
652 // there was an error. show it
653 if ((Boolean) ois.readObject()) {
654 Exception shouldNotHappen = (Exception) ois
655 .readObject();
656 transmissionError(shouldNotHappen.getMessage());
657 }
658 // nothing else because there is no return value
659 }
660
661 } else if (command.startsWith("SHOW EMAIL")) { //$NON-NLS-1$
662 if (oos != null) {
663 oos.writeObject(command);
664
665 // there was an error. show it
666 if ((Boolean) ois.readObject()) {
667 Exception shouldNotHappen = (Exception) ois
668 .readObject();
669 transmissionError(shouldNotHappen.getMessage());
670 }
671 // nothing else because there is no return value
672 }
673
674 } else if (command.startsWith("SHOW ARTICLE")) { //$NON-NLS-1$
675 if (oos != null) {
676 oos.writeObject(command);
677
678 if ((Boolean) ois.readObject()) {
679 Exception shouldNotHappen = (Exception) ois
680 .readObject();
681 transmissionError(shouldNotHappen.getMessage());
682 editArticle = null;
683 } else {
684 editArticle = (Article) ois.readObject();
685 }
686 }
687
688 } else if (command.startsWith("DELETE CATEGORY")) { //$NON-NLS-1$
689 if (oos != null) {
690 oos.writeObject(command);
691
692 if ((Boolean) ois.readObject()) {
693 Exception shouldNotHappen = (Exception) ois
694 .readObject();
695 transmissionError(shouldNotHappen.getMessage());
696 }
697 // nothing else because there is no return value
698 }
699
700 } else if (command.startsWith("REMOVE OLDMESSAGES")) { //$NON-NLS-1$
701 if (oos != null) {
702 oos.writeObject(command);
703
704 if ((Boolean) ois.readObject()) {
705 Exception shouldNotHappen = (Exception) ois
706 .readObject();
707 transmissionError(shouldNotHappen.getMessage());
708 }
709 // nothing else because there is no return value
710 }
711
712 } else if (command.startsWith("SET PRICE")) { //$NON-NLS-1$
713 if (oos != null) {
714 oos.writeObject(command);
715
716 if ((Boolean) ois.readObject()) {
717 Exception shouldNotHappen = (Exception) ois
718 .readObject();
719 transmissionError(shouldNotHappen.getMessage());
720 setNewPrice = false;
721 }else{
722 setNewPrice = (Boolean) ois.readObject();
723 }
724
725 }
726
727 } else if (command.startsWith("UNSOLD")) { //$NON-NLS-1$
728 if (oos != null) {
729 oos.writeObject(command);
730
731 if ((Boolean) ois.readObject()) {
732 Exception shouldNotHappen = (Exception) ois
733 .readObject();
734 transmissionError(shouldNotHappen.getMessage());
735 changeSoldFlagBool = false;
736 }else{
737 changeSoldFlagBool = (Boolean) ois.readObject();
738 }
739
740
741 }
742
743 } else if (command.startsWith("CHANGE AUCTIONEND")) { //$NON-NLS-1$
744 if (oos != null) {
745 oos.writeObject(command);
746
747 if ((Boolean) ois.readObject()) {
748 Exception shouldNotHappen = (Exception) ois
749 .readObject();
750 transmissionError(shouldNotHappen.getMessage());
751 // nothing because no return is expected
752 }
753 // nothing else because no return is expected
754
755 }
756
757 } else if (command.startsWith("LIST CATEGORY")) { //$NON-NLS-1$
758 if (oos != null) {
759 oos.writeObject(command);
760
761
762 if ((Boolean) ois.readObject()) {
763 Exception shouldNotHappen = (Exception) ois
764 .readObject();
765 transmissionError(shouldNotHappen.getMessage());
766 //create an empty articlelist to avoid busting the programm because of a non existing list
767 articleList = new ArrayList<Article>();
768 }else{
769 articleList = (ArrayList<Article>) ois.readObject();
770 }
771 }
772
773 } else if (command.startsWith("BUY")) { //$NON-NLS-1$
774 if (oos != null) {
775 oos.writeObject(command);
776
777 if ((Boolean) ois.readObject()) {
778 Exception shouldNotHappen = (Exception) ois
779 .readObject();
780 transmissionError(shouldNotHappen.getMessage());
781 buyBool = false;
782 } else {
783 buyBool = (Boolean) ois.readObject();
784 }
785
786 }
787
788 } else if (command.startsWith("BID")) { //$NON-NLS-1$
789 if (oos != null) {
790 oos.writeObject(command);
791
792 if ((Boolean) ois.readObject()) {
793 Exception shouldNotHappen = (Exception) ois
794 .readObject();
795 transmissionError(shouldNotHappen.getMessage());
796 bidBool = false;
797 } else {
798 bidBool = (Boolean) ois.readObject();
799 }
800 }
801
802 } else if (command.startsWith("SEARCH")) { //$NON-NLS-1$
803 if (oos != null) {
804 oos.writeObject(command);
805 articleList = (ArrayList<Article>) ois.readObject();
806 }
807
808 } else if (command.startsWith("LOGOUT")) { //$NON-NLS-1$
809 if (oos != null) {
810 oos.writeObject(command);
811 socket = null;
812 ois = null;
813 oos = null;
814 }
815 }
816
817 } catch (IOException e) {
818 JOptionPane
819 .showMessageDialog(
820 null,
821 Messages.getString("GUI.FailedToConnect3"), //$NON-NLS-1$
822 Messages.getString("GUI.ConnectionProblem3"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
823 } catch (ClassNotFoundException e) {
824 JOptionPane
825 .showMessageDialog(
826 null,
827 Messages.getString("GUI.FailedToConnect4"), //$NON-NLS-1$
828 Messages.getString("GUI.ConnectionProblem4"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
829 }
830 }
831
832 /**
833 *
834 * @param input
835 * String to be checked
836 * @param type
837 * format to Check
838 * @return false if input is malformed, true if input is ok
839 */
840 public boolean checkForMalformedValues(String input, String type) {
841 if (type.equals("username")) { //$NON-NLS-1$
842 if (input.equals("")) { //$NON-NLS-1$
843 JOptionPane
844 .showMessageDialog(
845 null,
846 Messages.getString("GUI.NoUsername"), //$NON-NLS-1$
847 Messages.getString("GUI.NoUsernameEntered"), //$NON-NLS-1$
848 JOptionPane.WARNING_MESSAGE);
849 return false;
850 }
851
852 if (input.contains(" ")) { //$NON-NLS-1$
853 JOptionPane
854 .showMessageDialog(
855 null,
856 Messages.getString("GUI.UsernameContainsA"), //$NON-NLS-1$
857 Messages.getString("GUI.MalformedUsername"), //$NON-NLS-1$
858 JOptionPane.WARNING_MESSAGE);
859 return false;
860 }
861
862 } else if (type.equals("password")) { //$NON-NLS-1$
863 if (input.equals("")) { //$NON-NLS-1$
864 JOptionPane
865 .showMessageDialog(
866 null,
867 Messages.getString("GUI.NoPasswordEnteredPlease"), //$NON-NLS-1$
868 Messages.getString("GUI.NoPasswordEntered"), //$NON-NLS-1$
869 JOptionPane.WARNING_MESSAGE);
870 return false;
871 }
872
873 if (input.contains(" ")) { //$NON-NLS-1$
874 JOptionPane
875 .showMessageDialog(
876 null,
877 Messages.getString("GUI.PasswordContains"), //$NON-NLS-1$
878 Messages.getString("GUI.MalformedPw"), //$NON-NLS-1$
879 JOptionPane.WARNING_MESSAGE);
880 return false;
881 }
882
883 } else if (type.equals("dateofbirth")) { //$NON-NLS-1$
884 if (input.equals("")) { //$NON-NLS-1$
885 JOptionPane
886 .showMessageDialog(
887 null,
888 Messages.getString("GUI.NoDateOfBirth"), //$NON-NLS-1$
889 Messages.getString("GUI.NoDateOfBirthEntered"), //$NON-NLS-1$
890 JOptionPane.WARNING_MESSAGE);
891 return false;
892 }
893
894 if (input.length() != 6 || !input.matches("\\d*")) { //$NON-NLS-1$
895 JOptionPane.showMessageDialog(null,
896 Messages.getString("GUI.DateOfBirthIsMalformed"), //$NON-NLS-1$
897 Messages.getString("GUI.MalformedDateOfBirth"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
898 return false;
899 }
900
901 } else if (type.equals("auctionend")) { //$NON-NLS-1$
902 if (input.equals("") || input.equals("auction end date")) { //$NON-NLS-1$ //$NON-NLS-2$
903 JOptionPane
904 .showMessageDialog(
905 null,
906 Messages.getString("GUI.NoAuctionEndEntered"), //$NON-NLS-1$
907 Messages.getString("GUI.NoAuctionEndEntered2"), //$NON-NLS-1$
908 JOptionPane.WARNING_MESSAGE);
909 return false;
910 }
911
912 if (input.length() != 13) {
913 return false;
914 }
915
916 if (input.contains("-")) { //$NON-NLS-1$
917 String[] tempStringArray = input.split("-"); //$NON-NLS-1$
918
919 if (!tempStringArray[0].matches("\\d*") //$NON-NLS-1$
920 || !tempStringArray[1].matches("\\d*")) { //$NON-NLS-1$
921 JOptionPane.showMessageDialog(null,
922 Messages.getString("GUI.AuctionEndIsMalformed"), //$NON-NLS-1$
923 Messages.getString("GUI.MalformedActionEnd"), //$NON-NLS-1$
924 JOptionPane.WARNING_MESSAGE);
925 return false;
926 }
927 }
928
929 } else if (type.equals("zip")) { //$NON-NLS-1$
930 if (input.equals("")) { //$NON-NLS-1$
931 JOptionPane.showMessageDialog(null,
932 Messages.getString("GUI.NoZipEnteredPlease"), //$NON-NLS-1$
933 Messages.getString("GUI.NoZipEntered"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
934 return false;
935 }
936
937 if (!input.matches("\\d*")) { //$NON-NLS-1$
938 JOptionPane.showMessageDialog(null,
939 Messages.getString("GUI.ZipIsMalformed"), Messages.getString("GUI.MalformedZip"), //$NON-NLS-1$ //$NON-NLS-2$
940 JOptionPane.WARNING_MESSAGE);
941 return false;
942 }
943
944 } else if (type.equals("phoneno")) { //$NON-NLS-1$
945 if (input.equals("")) { //$NON-NLS-1$
946 JOptionPane
947 .showMessageDialog(
948 null,
949 Messages.getString("GUI.NoPhoneNumberEntered"), //$NON-NLS-1$
950 Messages.getString("GUI.NoPhoneNumberEntered2"), //$NON-NLS-1$
951 JOptionPane.WARNING_MESSAGE);
952 return false;
953 }
954
955 if (input.contains("-")) { //$NON-NLS-1$
956 String[] tempStringArray = input.split("-"); //$NON-NLS-1$
957
958 if (!tempStringArray[0].matches("\\d*") //$NON-NLS-1$
959 || !tempStringArray[1].matches("\\d*")) { //$NON-NLS-1$
960 // phoneno doesn't contain just digits
961 JOptionPane.showMessageDialog(null,
962 Messages.getString("GUI.PhoneNumberIsMalformed"), //$NON-NLS-1$
963 Messages.getString("GUI.MalformedPhoneNo"), //$NON-NLS-1$
964 JOptionPane.WARNING_MESSAGE);
965 return false;
966 }
967 } else {
968 // no - included in phoneno
969 JOptionPane.showMessageDialog(null,
970 Messages.getString("GUI.PhoneNoIs"), //$NON-NLS-1$
971 Messages.getString("GUI.MalformedPhone"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
972 return false;
973 }
974
975 } else if (type.equals("price")) { //$NON-NLS-1$
976 if (input.equals("price") || input.equals("")) { //$NON-NLS-1$ //$NON-NLS-2$
977 JOptionPane.showMessageDialog(null, Messages.getString("GUI.PleaseEnterAPrice"), //$NON-NLS-1$
978 Messages.getString("GUI.NoPriceEntered"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
979 return false;
980 }
981
982 try {
983 double check = Double.parseDouble(input);
984 if (check % 0.5 != 0) {
985 JOptionPane
986 .showMessageDialog(
987 null,
988 Messages.getString("GUI.ThePriceHasToBe"), //$NON-NLS-1$
989 Messages.getString("GUI.MalformedPrice"), //$NON-NLS-1$
990 JOptionPane.WARNING_MESSAGE);
991 return false;
992 }
993 } catch (NumberFormatException e) {
994 JOptionPane
995 .showMessageDialog(
996 null,
997 Messages.getString("GUI.ThePriceHasTo"), //$NON-NLS-1$
998 Messages.getString("GUI.MalformedPrice2"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
999 return false;
1000 }
1001
1002 } else if (type.equals("category")) { //$NON-NLS-1$
1003 if (input.contains(" ")) { //$NON-NLS-1$
1004 JOptionPane
1005 .showMessageDialog(
1006 null,
1007 Messages.getString("GUI.CategoriesMustNotContain"), //$NON-NLS-1$
1008 Messages.getString("GUI.MalformedCategory"), //$NON-NLS-1$
1009 JOptionPane.WARNING_MESSAGE);
1010 return false;
1011 }
1012
1013 } else if (type.equals("email")) { //$NON-NLS-1$
1014 if (input.equals("")) { //$NON-NLS-1$
1015 JOptionPane
1016 .showMessageDialog(
1017 null,
1018 Messages.getString("GUI.NoE-mailAddress"), //$NON-NLS-1$
1019 Messages.getString("GUI.NoEMailAdrdressEntered1"), //$NON-NLS-1$
1020 JOptionPane.WARNING_MESSAGE);
1021 return false;
1022 }
1023
1024 if (input.contains("@")) { //$NON-NLS-1$
1025 String[] emailArray = input.split("@"); //$NON-NLS-1$
1026 if (!emailArray[emailArray.length - 1].contains(".")) { //$NON-NLS-1$
1027 JOptionPane.showMessageDialog(null,
1028 Messages.getString("GUI.EmailAddressIs"), //$NON-NLS-1$
1029 Messages.getString("GUI.MalformedEmailAddress"), //$NON-NLS-1$
1030 JOptionPane.WARNING_MESSAGE);
1031 return false;
1032 }
1033
1034 } else {
1035 JOptionPane
1036 .showMessageDialog(
1037 null,
1038 Messages.getString("GUI.EmailAddressIs2"), //$NON-NLS-1$
1039 Messages.getString("GUI.MalformedEmailAddress2"), //$NON-NLS-1$
1040 JOptionPane.WARNING_MESSAGE);
1041 return false;
1042 }
1043
1044 }
1045 // no problems found? return true!
1046 return true;
1047 }
1048
1049 /**
1050 * updates the category data represented by two comboboxes in the sell tab.
1051 * if no server connection is active it connects. if a connection is
1052 * available the client requests a categorylist from the server. the
1053 * categorylist is then convertet to an array of categorynames, which then
1054 * is added to the defaultcomboboxmodel
1055 *
1056 * @return DefaultComboBoxModel with updated category data
1057 */
1058 public DefaultComboBoxModel updateCategoryData() {
1059 if (socket == null) {
1060 connectToServer();
1061 execute("SHOW CATEGORIES"); //$NON-NLS-1$
1062 execute("LOGOUT"); //$NON-NLS-1$
1063 } else {
1064 execute("SHOW CATEGORIES"); //$NON-NLS-1$
1065 }
1066
1067 String[] categoryData = new String[categoryList.size()];
1068 Iterator<Category> it = categoryList.iterator();
1069
1070 if (categoryList.size() != 0) {
1071 int counter = 0;
1072 while (it.hasNext()) {
1073 Category actual = it.next();
1074 categoryData[counter] = actual.getCatName();
1075 counter++;
1076 }
1077 }
1078
1079 DefaultComboBoxModel model = new DefaultComboBoxModel(categoryData);
1080
1081 return model;
1082 }
1083
1084
1085
1086
1087
1088
1089 /**
1090 * Initialize the contents of the frame.
1091 */
1092 private void initialize() {
1093
1094
1095
1096 frame = new JFrame("3,14159265bay"); //$NON-NLS-1$
1097 frame.setBounds(100, 100, 1100, 600);
1098
1099 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
1100 frame.getContentPane().setLayout(
1101 new FormLayout(new ColumnSpec[] {
1102 FormFactory.RELATED_GAP_COLSPEC,
1103 ColumnSpec.decode("default:grow"), }, new RowSpec[] { //$NON-NLS-1$
1104 FormFactory.RELATED_GAP_ROWSPEC,
1105 RowSpec.decode("max(23dlu;default)"), //$NON-NLS-1$
1106 FormFactory.RELATED_GAP_ROWSPEC,
1107 RowSpec.decode("default:grow"), //$NON-NLS-1$
1108 FormFactory.RELATED_GAP_ROWSPEC,
1109 RowSpec.decode("default:grow"), })); //$NON-NLS-1$
1110
1111 loginPanel = new JPanel();
1112 frame.getContentPane().add(loginPanel, "2, 2, fill, fill"); //$NON-NLS-1$
1113
1114 welcomeLabel = new JLabel(""); //$NON-NLS-1$
1115 loginPanel.add(welcomeLabel);
1116
1117 txtUsername = new JTextField();
1118 txtUsername.setText(Messages.getString("GUI.Username")); //$NON-NLS-1$
1119 txtUsername.setColumns(10);
1120 loginPanel.add(txtUsername);
1121
1122 txtPassword = new JTextField();
1123 txtPassword.setText(Messages.getString("GUI.Password")); //$NON-NLS-1$
1124 txtPassword.setColumns(10);
1125 loginPanel.add(txtPassword);
1126
1127
1128 /**
1129 * takes the strings from txtUsername and txtPassword to log the user
1130 * in. therefore the login command is executed. after that the answer
1131 * from the server is processed. if the login was successful the
1132 * loginarea is set invisible and the logout button becomes visible.
1133 */
1134 btnLogin = new JButton(Messages.getString("GUI.Login")); //$NON-NLS-1$
1135 btnLogin.addMouseListener(new MouseAdapter() {
1136 @Override
1137 public void mouseClicked(MouseEvent arg0) {
1138 if (socket == null) {
1139 connectToServer();
1140 }
1141
1142 execute("LOGIN " + txtUsername.getText() + " " //$NON-NLS-1$ //$NON-NLS-2$
1143 + txtPassword.getText());
1144
1145 // save username for later use
1146 usernameTempSaved = txtUsername.getText();
1147
1148 if (loginBool) {
1149 txtUsername.setVisible(false);
1150 txtPassword.setVisible(false);
1151 btnLogin.setVisible(false);
1152 btnLogout.setVisible(true);
1153 btnRegister.setVisible(false);
1154 welcomeLabel.setText(Messages.getString("GUI.Welcome") + usernameTempSaved); //$NON-NLS-1$
1155
1156 // admin only gets the user control center with extra admin
1157 // panel
1158
1159 if (usernameTempSaved.equals("Administrator")) {
1160
1161 tabbedPane.removeAll();
1162 tabbedPane.addTab(Messages.getString("GUI.UserControlCenter"), null, //$NON-NLS-1$
1163 userControlCenterPanel, null);
1164 // admin can't change his userdata
1165 comboBoxChangeUserdata.setVisible(false);
1166 lblChange.setVisible(false);
1167 lblTo.setVisible(false);
1168 txtChangeNewValue.setVisible(false);
1169 btnChangeOk.setVisible(false);
1170 adminPanel.setVisible(true);
1171
1172 // everyone else gets all tabs without admin panel
1173 } else {
1174
1175 tabbedPane.removeAll();
1176 tabbedPane.addTab(Messages.getString("GUI.buy"), null, buyTabPanel, null); //$NON-NLS-1$
1177 tabbedPane.addTab(Messages.getString("GUI.sell"), null, sellTabPanel, null); //$NON-NLS-1$
1178 tabbedPane.addTab(Messages.getString("GUI.msgs"), null, messagePanel, null); //$NON-NLS-1$
1179 tabbedPane.addTab(Messages.getString("GUI.UCC"), null, //$NON-NLS-1$
1180 userControlCenterPanel, null);
1181 // user can change his userdata
1182 comboBoxChangeUserdata.setVisible(true);
1183 lblChange.setVisible(true);
1184 lblTo.setVisible(true);
1185 txtChangeNewValue.setVisible(true);
1186 btnChangeOk.setVisible(true);
1187
1188 adminPanel.setVisible(false);
1189 //article details visible in buy tab
1190
1191 articleDetailsPanel.setVisible(true);
1192 btnShowArticleDetails.setVisible(true);
1193 }
1194 // if login failed
1195 } else {
1196
1197 JOptionPane.showMessageDialog(null,
1198 Messages.getString("GUI.PleaseEnterCorrectLogin"), Messages.getString("GUI.LoginFailed"), //$NON-NLS-1$ //$NON-NLS-2$
1199 JOptionPane.WARNING_MESSAGE);
1200 }
1201 // reset username and password text fields
1202 txtUsername.setText(Messages.getString("GUI.Username2")); //$NON-NLS-1$
1203 txtPassword.setText(Messages.getString("GUI.password")); //$NON-NLS-1$
1204 }
1205
1206 });
1207 loginPanel.add(btnLogin);
1208
1209 /**
1210 * executes the logout command and then resets the userinterface. login
1211 * panel becomes visible again.
1212 */
1213 btnLogout = new JButton(Messages.getString("GUI.Logout")); //$NON-NLS-1$
1214 btnLogout.addMouseListener(new MouseAdapter() {
1215 @Override
1216 public void mouseClicked(MouseEvent arg0) {
1217 txtUsername.setVisible(true);
1218 txtPassword.setVisible(true);
1219 btnLogin.setVisible(true);
1220 btnLogout.setVisible(false);
1221 welcomeLabel.setText(""); //$NON-NLS-1$
1222 btnRegister.setVisible(true);
1223 loginBool = false;
1224 usernameTempSaved = null;
1225 adminPanel.setVisible(false);
1226
1227 // resetting elements in buy tab
1228 txtEnterSearchTerm.setText(Messages.getString("GUI.EnterSearchItem")); //$NON-NLS-1$
1229 lblArticleTitleHere.setText(""); //$NON-NLS-1$
1230 lblCurrentPriceHere.setText(""); //$NON-NLS-1$
1231 lblAuctionEndAnd.setText(""); //$NON-NLS-1$
1232 lblDisplayNoOfBids.setText(""); //$NON-NLS-1$
1233 articleDescriptionTextAreaBuyTab.setText(""); //$NON-NLS-1$
1234 lblArticlenoHere.setText(""); //$NON-NLS-1$
1235 lblVendorNameHere.setText(""); //$NON-NLS-1$
1236 lblPhonenoHere.setText(""); //$NON-NLS-1$
1237 lblEmailHere.setText(""); //$NON-NLS-1$
1238 lblMaxBidHere.setText(""); //$NON-NLS-1$
1239
1240 // resetting elements in login panel
1241 txtUsername.setText(Messages.getString("GUI.Username3")); //$NON-NLS-1$
1242 txtPassword.setText(Messages.getString("GUI.Password2")); //$NON-NLS-1$
1243
1244
1245 //resetting elements in sell tab
1246
1247
1248 txtArticleTitle.setText(Messages.getString("GUI.ArticleTitle")); //$NON-NLS-1$
1249 articleDescriptionTextArea.setText(Messages.getString("GUI.ArticleDescription")); //$NON-NLS-1$
1250 txtNewCategory.setText(Messages.getString("GUI.newCategory")); //$NON-NLS-1$
1251
1252 chckbxShowPhonenoOn.setSelected(false);
1253 chckbxShowEmailOn.setSelected(false);
1254 txtPrice.setText(Messages.getString("GUI.Price")); //$NON-NLS-1$
1255 txtAuctionEndDate.setText(Messages.getString("GUI.AuctionEndDate")); //$NON-NLS-1$
1256 txtrCurrentDescription.setText(""); //$NON-NLS-1$
1257 txtrAddToCurrentDescription.setText(""); //$NON-NLS-1$
1258 changeArticleDataNewCategoryTextField.setText(Messages.getString("GUI.newCategory2")); //$NON-NLS-1$
1259 changeArticleDataChangePriceTextField.setText(Messages.getString("GUI.Price2")); //$NON-NLS-1$
1260
1261 // resetting elements in user control tab
1262 txtChangeNewValue.setText(""); //$NON-NLS-1$
1263 txtUsernameToEdit.setText(Messages.getString("GUI.UsernameToEdit")); //$NON-NLS-1$
1264
1265
1266 // resetting the article table in the buy tab
1267 Object[][] data = new Object[0][0];
1268 String[] columnNamesArticleTableBuyTab = { Messages.getString("GUI.title"), //$NON-NLS-1$
1269 Messages.getString("GUI.currentPrice"), Messages.getString("GUI.timeLeft") }; //$NON-NLS-1$ //$NON-NLS-2$
1270 articleTableBuyTab = new JTable(data,
1271 columnNamesArticleTableBuyTab);
1272
1273
1274 // resetting the article table in the sell tab
1275
1276 Object[][] data2 = new Object[0][0];
1277 String[] columnNamesArticleListChangeArticle = { Messages.getString("GUI.ArticleNo"), //$NON-NLS-1$
1278 Messages.getString("GUI.title2"), Messages.getString("GUI.description"), Messages.getString("GUI.currentPrice2"), Messages.getString("GUI.timeLeft2"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
1279 Messages.getString("GUI.status") }; //$NON-NLS-1$
1280 showMyArticlesTable = new JTable(data2,
1281 columnNamesArticleListChangeArticle);
1282
1283
1284 tabbedPane.removeAll();
1285 tabbedPane.addTab(Messages.getString("GUI.buy1"), null, buyTabPanel, null); //$NON-NLS-1$
1286
1287 // hide article details in buy tab until a user logs in
1288 articleDetailsPanel.setVisible(false);
1289 btnShowArticleDetails.setVisible(false);
1290
1291 execute("LOGOUT"); //$NON-NLS-1$
1292
1293
1294 loginPanel.add(btnLogout);
1295
1296 /**
1297 * opens a popup where user data can be entered to register a user.
1298 */
1299 btnRegister = new JButton(Messages.getString("GUI.register")); //$NON-NLS-1$
1300 btnRegister.addMouseListener(new MouseAdapter() {
1301 @Override
1302 public void mouseClicked(MouseEvent arg0) {
1303 JTextField txtRegUsername = new JTextField();
1304 JTextField txtRegPassword = new JTextField();
1305 JTextField txtRegLastname = new JTextField();
1306 JTextField txtRegFirstname = new JTextField();
1307 JTextField txtRegDateOfBirth = new JTextField();
1308 JTextField txtRegStreet = new JTextField();
1309 JTextField txtRegZip = new JTextField();
1310 JTextField txtRegLocation = new JTextField();
1311 JTextField txtRegPhoneNo = new JTextField();
1312 JTextField txtRegEmail = new JTextField();
1313 boolean sendFlag = true;
1314
1315 Object[] registrationFields = {
1316 Messages.getString("GUI.Username(noSpace)"), //$NON-NLS-1$
1317 txtRegUsername,
1318 Messages.getString("GUI.Password(noSpace)"), //$NON-NLS-1$
1319 txtRegPassword, Messages.getString("GUI.LastName"), txtRegLastname, //$NON-NLS-1$
1320 Messages.getString("GUI.FirstName"), txtRegFirstname, //$NON-NLS-1$
1321 Messages.getString("GUI.DateOfBirth"), txtRegDateOfBirth, //$NON-NLS-1$
1322 Messages.getString("GUI.Street"), txtRegStreet, Messages.getString("GUI.ZIP"), txtRegZip, Messages.getString("GUI.Location"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1323 txtRegLocation,
1324 Messages.getString("GUI.Phoneno"), //$NON-NLS-1$
1325 txtRegPhoneNo, Messages.getString("GUI.Email"), txtRegEmail }; //$NON-NLS-1$
1326
1327 JOptionPane registrationPane = new JOptionPane(
1328 registrationFields, JOptionPane.PLAIN_MESSAGE,
1329 JOptionPane.OK_CANCEL_OPTION);
1330 registrationPane.createDialog(null, "Register User") //$NON-NLS-1$
1331 .setVisible(true);
1332
1333 String RegUsernameString = txtRegUsername.getText();
1334 String RegPasswordString = txtRegPassword.getText();
1335 String RegLastnameString = txtRegLastname.getText();
1336 String RegFirstnameString = txtRegFirstname.getText();
1337 String RegDateOfBirthString = txtRegDateOfBirth.getText();
1338 String RegStreetString = txtRegStreet.getText();
1339 String RegZipString = txtRegZip.getText();
1340 String RegLocationString = txtRegLocation.getText();
1341 String RegPhoneNoString = txtRegPhoneNo.getText();
1342 String RegEmailString = txtRegEmail.getText();
1343
1344 // check username for malformation
1345 if (!checkForMalformedValues(RegUsernameString, "username")) { //$NON-NLS-1$
1346 sendFlag = false;
1347 }
1348
1349 // check password for malformation
1350 if (!checkForMalformedValues(RegPasswordString, "password")) { //$NON-NLS-1$
1351 sendFlag = false;
1352 }
1353
1354 // check date of birth for malformation
1355 if (!checkForMalformedValues(RegDateOfBirthString,
1356 "dateofbirth")) { //$NON-NLS-1$
1357 sendFlag = false;
1358 }
1359
1360 // check zip for malformation
1361 if (!checkForMalformedValues(RegZipString, "zip")) { //$NON-NLS-1$
1362 sendFlag = false;
1363 }
1364
1365 // check phoneno for malformation
1366 if (!checkForMalformedValues(RegPhoneNoString, "phoneno")) { //$NON-NLS-1$
1367 sendFlag = false;
1368 }
1369
1370 // check email for malformation
1371 if (!checkForMalformedValues(RegEmailString, "email")) { //$NON-NLS-1$
1372 sendFlag = false;
1373 }
1374
1375 // when no malformations were detected execute insert user
1376 if (sendFlag) {
1377 if (socket == null) {
1378 connectToServer();
1379 }
1380 execute("INSERT USER " + RegUsernameString + " " //$NON-NLS-1$ //$NON-NLS-2$
1381 + RegPasswordString + " " + "\"" //$NON-NLS-1$ //$NON-NLS-2$
1382 + RegLastnameString + "\"" + " " + "\"" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1383 + RegFirstnameString + "\"" + " " //$NON-NLS-1$ //$NON-NLS-2$
1384 + RegDateOfBirthString + " " + "\"" //$NON-NLS-1$ //$NON-NLS-2$
1385 + RegStreetString + "\"" + " " + RegZipString + " " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1386 + "\"" + RegLocationString + "\"" + " " + "\"" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
1387 + RegPhoneNoString + "\"" + " " + "\"" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1388 + RegEmailString + "\""); //$NON-NLS-1$
1389
1390 // if registration failed (username already taken)
1391 if (!regBool) {
1392 JOptionPane
1393 .showMessageDialog(
1394 null,
1395 Messages.getString("GUI.UsernameAlreadyTakenPlease"), //$NON-NLS-1$
1396 Messages.getString("GUI.UsernameAlreadyTaken"), //$NON-NLS-1$
1397 JOptionPane.WARNING_MESSAGE);
1398
1399 }
1400
1401 //
1402 if (regBool) {
1403 JOptionPane
1404 .showMessageDialog(
1405 null,
1406 "Congratulations. Your account has been created. You can now log in.",
1407 "User created",
1408 JOptionPane.WARNING_MESSAGE);
1409
1410 }
1411 }
1412
1413 }
1414 });
1415 loginPanel.add(btnRegister);
1416
1417 /**
1418 * changes the language of the user interface between English and German
1419 */
1420 btnAufDeutschBitte = new JButton(Messages.getString("GUI.AufDeutschBitte")); //$NON-NLS-1$
1421 btnAufDeutschBitte.addMouseListener(new MouseAdapter() {
1422 @Override
1423 public void mouseClicked(MouseEvent arg0) {
1424 Messages.changeLanguage();
1425 // TODO @Marcel hier muss die GUI neu gestartet werden
1426 }
1427 });
1428 loginPanel.add(btnAufDeutschBitte);
1429 btnLogout.setVisible(false);
1430
1431 /**
1432 * pane containing all the tabs
1433 */
1434 tabbedPane = new JTabbedPane(JTabbedPane.TOP);
1435 frame.getContentPane().add(tabbedPane, "2, 4, 1, 3"); //$NON-NLS-1$
1436 tabbedPane.setVisible(true);
1437
1438 /**
1439 * the buy tab
1440 */
1441 buyTabPanel = new JPanel();
1442 tabbedPane.addTab(Messages.getString("GUI.Buy2"), null, buyTabPanel, null); //$NON-NLS-1$
1443
1444 buyTabPanel.setLayout(new FormLayout(new ColumnSpec[] {
1445 FormFactory.RELATED_GAP_COLSPEC,
1446 ColumnSpec.decode("max(95dlu;min)"), //$NON-NLS-1$
1447 FormFactory.RELATED_GAP_COLSPEC,
1448 ColumnSpec.decode("55px"), //$NON-NLS-1$
1449 FormFactory.RELATED_GAP_COLSPEC,
1450 ColumnSpec.decode("80px"), //$NON-NLS-1$
1451 FormFactory.RELATED_GAP_COLSPEC,
1452
1453 ColumnSpec.decode("310px"),
1454
1455
1456 FormFactory.RELATED_GAP_COLSPEC,
1457
1458 ColumnSpec.decode("35px"),
1459
1460 FormFactory.RELATED_GAP_COLSPEC,
1461
1462 ColumnSpec.decode("330px"),
1463
1464 FormFactory.RELATED_GAP_COLSPEC,
1465 FormFactory.DEFAULT_COLSPEC,},
1466 new RowSpec[] {
1467 FormFactory.RELATED_GAP_ROWSPEC,
1468 FormFactory.DEFAULT_ROWSPEC,
1469 FormFactory.RELATED_GAP_ROWSPEC,
1470 FormFactory.DEFAULT_ROWSPEC,
1471 FormFactory.RELATED_GAP_ROWSPEC,
1472 RowSpec.decode("default:grow"), //$NON-NLS-1$
1473 FormFactory.RELATED_GAP_ROWSPEC,
1474 RowSpec.decode("max(135dlu;default)"), //$NON-NLS-1$
1475 FormFactory.RELATED_GAP_ROWSPEC,
1476 FormFactory.DEFAULT_ROWSPEC,
1477 FormFactory.RELATED_GAP_ROWSPEC,
1478
1479 RowSpec.decode("fill:max(80dlu;default):grow"),}));
1480
1481
1482 /**
1483 * textfield to enter a search term location: buy tab, left hand side
1484 */
1485 txtEnterSearchTerm = new JTextField();
1486 txtEnterSearchTerm.setText(Messages.getString("GUI.EnterSearchItem")); //$NON-NLS-1$
1487 buyTabPanel.add(txtEnterSearchTerm, "2, 2, fill, default"); //$NON-NLS-1$
1488 txtEnterSearchTerm.setColumns(10);
1489
1490 /**
1491 * combobox to select the used search method location: buy tab, left
1492 * hand side
1493 */
1494 Object[] searchMethodsForComboBox = { Messages.getString("GUI.and"), Messages.getString("GUI.or") }; //$NON-NLS-1$ //$NON-NLS-2$
1495 searchMethodSelectionComboBox = new JComboBox(searchMethodsForComboBox);
1496 buyTabPanel.add(searchMethodSelectionComboBox, "4, 2, fill, default"); //$NON-NLS-1$
1497
1498 /**
1499 * executes the search. takes the search term from txtEnterSearchTerm
1500 * and the search method from searchMethodSelectionComboBox and executes
1501 * a search. works if a user is logged in or not. location: buy tab,
1502 * left hand side
1503 */
1504 btnSearch = new JButton(Messages.getString("GUI.search")); //$NON-NLS-1$
1505 btnSearch.addMouseListener(new MouseAdapter() {
1506 @Override
1507 public void mouseClicked(MouseEvent arg0) {
1508 // works even if no user is logged in
1509 if (socket == null) {
1510 connectToServer();
1511 execute("SEARCH " //$NON-NLS-1$
1512 + searchMethodSelectionComboBox.getSelectedItem()
1513 + " \"" + txtEnterSearchTerm.getText() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
1514 execute("LOGOUT"); //$NON-NLS-1$
1515 } else {
1516 // gets all articles of selected category
1517 execute("SEARCH " //$NON-NLS-1$
1518 + searchMethodSelectionComboBox.getSelectedItem()
1519 + " \"" + txtEnterSearchTerm.getText() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
1520 }
1521
1522 Iterator<Article> checkForSoldArticlesIterator = articleList
1523 .iterator();
1524 int numberOfSoldArticles = 0;
1525 while (checkForSoldArticlesIterator.hasNext()) {
1526 Article actual = checkForSoldArticlesIterator.next();
1527 if (actual.isSold()) {
1528 numberOfSoldArticles++;
1529 }
1530 }
1531
1532 if (!articleList.isEmpty()) {
1533 // number of rows => number of articles minus the sold ones
1534 Object[][] data = new Object[articleList.size()
1535 - numberOfSoldArticles][4];
1536 String[] columnNamesArticleTableBuyTab = { Messages.getString("GUI.title3"), //$NON-NLS-1$
1537 Messages.getString("GUI.currentPrice2"), Messages.getString("GUI.TimeLeft3"), Messages.getString("GUI.ArticleNo2") }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1538
1539 // counter to prevent running out of array bounds
1540 int counter = 0;
1541 // first the salesitems
1542 Iterator<Article> it = articleList.iterator();
1543 while (it.hasNext()) {
1544 Object actual = it.next();
1545
1546 if (actual.getClass().getSimpleName().equals(
1547 "SalesItem")) { //$NON-NLS-1$
1548 // if article isn't sold add it to the list
1549 if (!((SalesItem) actual).isSold()) {
1550 data[counter][0] = ((SalesItem) actual)
1551 .getTitle();
1552 data[counter][1] = ((SalesItem) actual)
1553 .getPrice();
1554 data[counter][2] = ""; //$NON-NLS-1$
1555 data[counter][3] = ((SalesItem) actual)
1556 .getArticleNo();
1557 counter++;
1558 }
1559 }
1560 }
1561
1562 // then the auction items
1563 Iterator<Article> it2 = articleList.iterator();
1564 while (it2.hasNext()) {
1565 Object actual = it2.next();
1566
1567 if (actual.getClass().getSimpleName().equals(
1568 "AuctionArticle")) { //$NON-NLS-1$
1569 // if article isn't sold add it to the list
1570 if (!((AuctionArticle) actual).isSold()) {
1571 data[counter][0] = ((AuctionArticle) actual)
1572 .getTitle();
1573 data[counter][1] = ((AuctionArticle) actual)
1574 .getCurrentMaxBid();
1575 data[counter][2] = dateDifferenceToString(((AuctionArticle) actual)
1576 .getAuctionEnd());
1577 data[counter][3] = ((AuctionArticle) actual)
1578 .getArticleNo();
1579 counter++;
1580 }
1581 }
1582 }
1583
1584 articleTableBuyTab = new JTable(new MyTableModel(columnNamesArticleTableBuyTab, data));
1585 articleTableBuyTab
1586 .setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
1587 articleTableBuyTab.setAutoCreateRowSorter(true);
1588 articleTableBuyTabScrollPane
1589 .setViewportView(articleTableBuyTab);
1590
1591 // set column widths so that they fill the panel
1592 articleTableBuyTab.getColumnModel().getColumn(0)
1593 .setPreferredWidth(242);
1594 articleTableBuyTab.getColumnModel().getColumn(1)
1595 .setPreferredWidth(80);
1596 articleTableBuyTab.getColumnModel().getColumn(2)
1597 .setPreferredWidth(110);
1598 } else {
1599 JOptionPane
1600 .showMessageDialog(
1601 null,
1602 Messages.getString("GUI.YourSearchReturned0"), //$NON-NLS-1$
1603 Messages.getString("GUI.NoArticlesFound"), //$NON-NLS-1$
1604 JOptionPane.INFORMATION_MESSAGE);
1605 }
1606
1607 ;
1608 buyTabPanel.add(btnSearch, "6, 2"); //$NON-NLS-1$
1609
1610 /**
1611 * gets the categorylist from the server and adds it to the category
1612 * list location: buy tab, left hand side
1613 */
1614 btnRefreshCategories = new JButton(Messages.getString("GUI.RefreshCategories")); //$NON-NLS-1$
1615 btnRefreshCategories.addMouseListener(new MouseAdapter() {
1616 @Override
1617 public void mouseClicked(MouseEvent arg0) {
1618 // works even if no user is logged in
1619 if (socket == null) {
1620 connectToServer();
1621 execute("SHOW CATEGORIES"); //$NON-NLS-1$
1622 execute("LOGOUT"); //$NON-NLS-1$
1623 } else {
1624 // gets the categories
1625 execute("SHOW CATEGORIES"); //$NON-NLS-1$
1626 }
1627
1628 // clear categorylist
1629 categoriesListModel.removeAllElements();
1630
1631 Iterator<Category> it = categoryList.iterator();
1632 while (it.hasNext()) {
1633 Category actual = it.next();
1634 categoriesListModel.add(categoriesListModel.size(), actual
1635 .getCatName()
1636
1637 + " (" + actual.getNumberOfUnsoldArticles() + ")");
1638
1639 }
1640
1641 }
1642 });
1643 buyTabPanel.add(btnRefreshCategories, "2, 6"); //$NON-NLS-1$
1644
1645 lblArticlesInSelected = new JLabel(Messages.getString("GUI.ArticlesInSelectedC")); //$NON-NLS-1$
1646 buyTabPanel.add(lblArticlesInSelected, "4, 6, 5, 1"); //$NON-NLS-1$
1647
1648 /**
1649 * panel containing all buttons and fields needed to buy an article
1650 */
1651 articleDetailsPanel = new JPanel();
1652 buyTabPanel.add(articleDetailsPanel, "10, 6, 3, 7, fill, fill"); //$NON-NLS-1$
1653 articleDetailsPanel.setLayout(new FormLayout(new ColumnSpec[] {
1654 FormFactory.RELATED_GAP_COLSPEC,
1655
1656 ColumnSpec.decode("100px"),
1657
1658 FormFactory.RELATED_GAP_COLSPEC,
1659
1660 ColumnSpec.decode("240px"),},
1661
1662 new RowSpec[] {
1663 FormFactory.RELATED_GAP_ROWSPEC,
1664 FormFactory.DEFAULT_ROWSPEC,
1665 FormFactory.RELATED_GAP_ROWSPEC,
1666 FormFactory.DEFAULT_ROWSPEC,
1667 FormFactory.RELATED_GAP_ROWSPEC,
1668 FormFactory.DEFAULT_ROWSPEC,
1669 FormFactory.RELATED_GAP_ROWSPEC,
1670 FormFactory.DEFAULT_ROWSPEC,
1671 FormFactory.RELATED_GAP_ROWSPEC,
1672 RowSpec.decode("75px"), //$NON-NLS-1$
1673 FormFactory.RELATED_GAP_ROWSPEC,
1674 FormFactory.DEFAULT_ROWSPEC,
1675 FormFactory.RELATED_GAP_ROWSPEC,
1676 FormFactory.DEFAULT_ROWSPEC,
1677 FormFactory.RELATED_GAP_ROWSPEC,
1678 FormFactory.DEFAULT_ROWSPEC,
1679 FormFactory.RELATED_GAP_ROWSPEC,
1680 FormFactory.DEFAULT_ROWSPEC,
1681 FormFactory.RELATED_GAP_ROWSPEC,
1682 FormFactory.DEFAULT_ROWSPEC,
1683 FormFactory.RELATED_GAP_ROWSPEC,
1684 FormFactory.DEFAULT_ROWSPEC,
1685 FormFactory.RELATED_GAP_ROWSPEC,
1686 FormFactory.DEFAULT_ROWSPEC,
1687 FormFactory.RELATED_GAP_ROWSPEC,
1688 FormFactory.DEFAULT_ROWSPEC,}));
1689
1690 /**
1691 * labels containing the title of the selected article
1692 */
1693 lblTitle = new JLabel("Title:"); //$NON-NLS-1$
1694 articleDetailsPanel.add(lblTitle, "2, 2, right, default"); //$NON-NLS-1$
1695 lblArticleTitleHere = new JLabel(""); //$NON-NLS-1$
1696 articleDetailsPanel.add(lblArticleTitleHere, "4, 2"); //$NON-NLS-1$
1697
1698 /**
1699 * labels containing the current price/bid of the selected article
1700 */
1701 lblCurrentPrice = new JLabel("current price:"); //$NON-NLS-1$
1702 articleDetailsPanel.add(lblCurrentPrice, "2, 4, right, default"); //$NON-NLS-1$
1703 lblCurrentPriceHere = new JLabel(""); //$NON-NLS-1$
1704 articleDetailsPanel.add(lblCurrentPriceHere, "4, 4"); //$NON-NLS-1$
1705
1706 /**
1707 * labels showing the time left until the auction end
1708 */
1709 lblAuctionEnd = new JLabel(Messages.getString("GUI.TimeLeft4")); //$NON-NLS-1$
1710 articleDetailsPanel.add(lblAuctionEnd, "2, 6, right, default"); //$NON-NLS-1$
1711 lblAuctionEndAnd = new JLabel(""); //$NON-NLS-1$
1712 articleDetailsPanel.add(lblAuctionEndAnd, "4, 6"); //$NON-NLS-1$
1713
1714 /**
1715 * labels showing the number of bids on the article
1716 */
1717 lblNoOfBids = new JLabel(Messages.getString("GUI.NoOfBids")); //$NON-NLS-1$
1718 articleDetailsPanel.add(lblNoOfBids, "2, 8, right, default"); //$NON-NLS-1$
1719 lblDisplayNoOfBids = new JLabel(""); //$NON-NLS-1$
1720 articleDetailsPanel.add(lblDisplayNoOfBids, "4, 8"); //$NON-NLS-1$
1721
1722 /**
1723 * label and text area showing the article description. text area is not
1724 * editable and has a scroll pane
1725 */
1726 lblDescription = new JLabel(Messages.getString("GUI.Description123")); //$NON-NLS-1$
1727 articleDetailsPanel.add(lblDescription, "2, 10, right, center"); //$NON-NLS-1$
1728 articleDescriptionTextAreaBuyTabScrollPane = new JScrollPane();
1729 articleDetailsPanel.add(articleDescriptionTextAreaBuyTabScrollPane,
1730 "4, 10, fill, fill"); //$NON-NLS-1$
1731 articleDescriptionTextAreaBuyTab = new JTextArea();
1732 articleDescriptionTextAreaBuyTabScrollPane
1733 .setViewportView(articleDescriptionTextAreaBuyTab);
1734 articleDescriptionTextAreaBuyTab.setLineWrap(true);
1735
1736 /**
1737 * label showing the article number
1738 */
1739 lblArticleno = new JLabel(Messages.getString("GUI.ArtcleNo123")); //$NON-NLS-1$
1740 articleDetailsPanel.add(lblArticleno, "2, 12, right, default"); //$NON-NLS-1$
1741 lblArticlenoHere = new JLabel(""); //$NON-NLS-1$
1742 articleDetailsPanel.add(lblArticlenoHere, "4, 12"); //$NON-NLS-1$
1743
1744 /**
1745 * label showing the article vendor
1746 */
1747 lblSoldBy = new JLabel(Messages.getString("GUI.SoldBy123")); //$NON-NLS-1$
1748 articleDetailsPanel.add(lblSoldBy, "2, 14, right, default"); //$NON-NLS-1$
1749 lblVendorNameHere = new JLabel(""); //$NON-NLS-1$
1750 articleDetailsPanel.add(lblVendorNameHere, "4, 14"); //$NON-NLS-1$
1751
1752 /**
1753 * label showing the vendors phone number if he choose to show it
1754 */
1755 lblPhoneno = new JLabel(Messages.getString("GUI.PhoneNo123")); //$NON-NLS-1$
1756 articleDetailsPanel.add(lblPhoneno, "2, 16, right, default"); //$NON-NLS-1$
1757 lblPhonenoHere = new JLabel(""); //$NON-NLS-1$
1758 articleDetailsPanel.add(lblPhonenoHere, "4, 16"); //$NON-NLS-1$
1759
1760 /**
1761 * label showing the vendors e-mail address if he choose to show it
1762 */
1763 lblEmail = new JLabel(Messages.getString("GUI.EMail123")); //$NON-NLS-1$
1764 articleDetailsPanel.add(lblEmail, "2, 18, right, default"); //$NON-NLS-1$
1765 lblEmailHere = new JLabel(""); //$NON-NLS-1$
1766 articleDetailsPanel.add(lblEmailHere, "4, 18"); //$NON-NLS-1$
1767
1768 /**
1769 * button to purchase a sales item
1770 */
1771 btnBuyArticle = new JButton(Messages.getString("GUI.PurchaseArticle")); //$NON-NLS-1$
1772 btnBuyArticle.addMouseListener(new MouseAdapter() {
1773 @Override
1774 public void mouseClicked1(MouseEvent arg0) {
1775 // check because of possible transmission errors
1776 if (editArticle != null) {
1777 // check if it's a sales item to be safe
1778 if (editArticle.getClass().getSimpleName().equals(
1779 "SalesItem")) { //$NON-NLS-1$
1780 execute("BUY " + editArticle.getArticleNo()); //$NON-NLS-1$
1781 if (buyBool) {
1782 JOptionPane
1783 .showMessageDialog(
1784 null,
1785 Messages.getString("GUI.Congratulation"), //$NON-NLS-1$
1786 Messages.getString("GUI.ArticleBought"), //$NON-NLS-1$
1787 JOptionPane.INFORMATION_MESSAGE);
1788 } else {
1789 JOptionPane
1790 .showMessageDialog(
1791 null,
1792 Messages.getString("GUI.Sorry"), //$NON-NLS-1$
1793 Messages.getString("GUI.ArticleAlreadySold"), //$NON-NLS-1$
1794 JOptionPane.WARNING_MESSAGE);
1795 }
1796 }
1797 }
1798 ;
1799 articleDetailsPanel.add(btnBuyArticle, "4, 22"); //$NON-NLS-1$
1800
1801 /**
1802 * labels showing the current max bid put on the article by the user
1803 */
1804 lblYourMaxBid = new JLabel(Messages.getString("GUI.YourMaxBid")); //$NON-NLS-1$
1805 articleDetailsPanel.add(lblYourMaxBid, "2, 20, right, default"); //$NON-NLS-1$
1806 lblMaxBidHere = new JLabel(""); //$NON-NLS-1$
1807 articleDetailsPanel.add(lblMaxBidHere, "4, 20"); //$NON-NLS-1$
1808
1809 /**
1810 * button to bid an an article
1811 */
1812 btnBidOnArticle = new JButton(Messages.getString("GUI.BidOnArticle")); //$NON-NLS-1$
1813 btnBidOnArticle.addMouseListener(new MouseAdapter() {
1814 @Override
1815 public void mouseClicked(MouseEvent arg0) {
1816 JTextField newBid = new JTextField();
1817
1818 Object[] newBidFields = {
1819 Messages.getString("GUI.PleaseEnterANewBid") //$NON-NLS-1$
1820 + ((AuctionArticle) editArticle)
1821 .getNextBidStep(), newBid };
1822
1823 JOptionPane newBidPane = new JOptionPane(newBidFields,
1824 JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
1825
1826 newBidPane.createDialog(null, Messages.getString("GUI.EnterNewBid")).setVisible(true); //$NON-NLS-1$
1827
1828 if (checkForMalformedValues(newBid.getText(), "price")) { //$NON-NLS-1$
1829 double newBidValue = Double.parseDouble(newBid.getText());
1830 if (newBidValue >= ((AuctionArticle) editArticle)
1831 .getNextBidStep()) {
1832 execute("BID " + editArticle.getArticleNo() + " " //$NON-NLS-1$ //$NON-NLS-2$
1833 + newBidValue);
1834 } else {
1835
1836
1837 JOptionPane
1838 .showMessageDialog(
1839 null,
1840 Messages.getString("GUI.BidLow"), //$NON-NLS-1$
1841 Messages.getString("GUI.NewBidLow"), //$NON-NLS-1$
1842 JOptionPane.WARNING_MESSAGE);
1843
1844 }
1845 }
1846
1847 if (bidBool) {
1848 JOptionPane.showMessageDialog(null,
1849 Messages.getString("GUI.BidBeenAccepted"), //$NON-NLS-1$
1850 Messages.getString("GUI.BidAccepted"), JOptionPane.INFORMATION_MESSAGE); //$NON-NLS-1$
1851 } else {
1852 JOptionPane
1853 .showMessageDialog(
1854 null,
1855 Messages.getString("GUI.ProblemBid"), //$NON-NLS-1$
1856 Messages.getString("GUI.BidNotAccepted"), //$NON-NLS-1$
1857 JOptionPane.WARNING_MESSAGE);
1858 }
1859
1860 }
1861 });
1862 articleDetailsPanel.add(btnBidOnArticle, "4, 24"); //$NON-NLS-1$
1863
1864 /**
1865 * button to change the bid set on the article by the user. changes the
1866 * maxBid.
1867 */
1868 btnChangeBid = new JButton(Messages.getString("GUI.ChangeBid")); //$NON-NLS-1$
1869 btnChangeBid.addMouseListener(new MouseAdapter() {
1870 @Override
1871 public void mouseClicked(MouseEvent arg0) {
1872
1873 JTextField newBid = new JTextField();
1874
1875 Object[] newBidFields = {
1876 Messages.getString("GUI.PleaseNewBidMin") //$NON-NLS-1$
1877 + ((AuctionArticle) editArticle)
1878 .getNextBidStep(), newBid };
1879
1880 JOptionPane newBidPane = new JOptionPane(newBidFields,
1881 JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
1882
1883 newBidPane.createDialog(null, Messages.getString("GUI.EnterNewBid1")).setVisible(true); //$NON-NLS-1$
1884
1885
1886
1887 if (checkForMalformedValues(newBid.getText(), "price")) { //$NON-NLS-1$
1888 double newBidValue = Double.parseDouble(newBid.getText());
1889 if (newBidValue >= ((AuctionArticle) editArticle)
1890 .getNextBidStep()) {
1891 execute("BID " + editArticle.getArticleNo() + " " //$NON-NLS-1$ //$NON-NLS-2$
1892 + newBidValue);
1893
1894 } else {
1895 JOptionPane
1896 .showMessageDialog(
1897 null,
1898
1899 Messages.getString("GUI.BidLowPlease"), //$NON-NLS-1$
1900 Messages.getString("GUI.NewBidToLow"), //$NON-NLS-1$
1901
1902 JOptionPane.WARNING_MESSAGE);
1903 }
1904 }
1905
1906 if (bidBool) {
1907 JOptionPane.showMessageDialog(null,
1908 Messages.getString("GUI.YourBidHasAccepted"), //$NON-NLS-1$
1909 Messages.getString("GUI.BidAccepted"), JOptionPane.INFORMATION_MESSAGE); //$NON-NLS-1$
1910 } else {
1911 JOptionPane
1912 .showMessageDialog(
1913 null,
1914 Messages.getString("GUI.ProblemWithBid"), //$NON-NLS-1$
1915 Messages.getString("GUI.BidNotAccepted2"), //$NON-NLS-1$
1916 JOptionPane.WARNING_MESSAGE);
1917 }
1918
1919
1920 }
1921 });
1922 articleDetailsPanel.add(btnChangeBid, "4, 26"); //$NON-NLS-1$
1923
1924 articleTableBuyTabScrollPane = new JScrollPane();
1925 buyTabPanel.add(articleTableBuyTabScrollPane, "4, 8, 5, 1, fill, fill"); //$NON-NLS-1$
1926
1927 /**
1928 * initial table for not having an empty spot in the gui
1929 */
1930
1931 Object[][] data = new Object[0][0];
1932 String[] columnNamesArticleTableBuyTab = { Messages.getString("GUI.title5"), Messages.getString("GUI.cuurentPrice5"), //$NON-NLS-1$ //$NON-NLS-2$
1933 Messages.getString("GUI.timeLeft5") }; //$NON-NLS-1$
1934 articleTableBuyTab = new JTable(data, columnNamesArticleTableBuyTab);
1935
1936 articleTableBuyTab.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
1937 articleTableBuyTab.setAutoCreateRowSorter(true);
1938 articleTableBuyTabScrollPane.setViewportView(articleTableBuyTab);
1939
1940 categoryListBuyTabScrollPane = new JScrollPane();
1941 buyTabPanel.add(categoryListBuyTabScrollPane, "2, 8, fill, fill"); //$NON-NLS-1$
1942
1943 /**
1944 * category list in buy tab. if a category is selected the
1945 * articleTableBuyTab table is filled with all articles from this
1946 * category
1947 */
1948 categoriesListModel = new DefaultListModel();
1949 categoryListBuyTab = new JList(categoriesListModel);
1950 categoryListBuyTab
1951 .addListSelectionListener(new ListSelectionListener() {
1952 public void valueChanged(ListSelectionEvent arg0) {
1953 if (arg0.getValueIsAdjusting()) {
1954 String selectedCategory = (String) categoryListBuyTab
1955 .getSelectedValue();
1956 String[] catNameSplit = selectedCategory.split(" "); //$NON-NLS-1$
1957 // works even if no user is logged in
1958 if (socket == null) {
1959 connectToServer();
1960 execute("LIST CATEGORY " + catNameSplit[0]); //$NON-NLS-1$
1961 execute("LOGOUT"); //$NON-NLS-1$
1962 } else {
1963 // gets all articles of selected category
1964 execute("LIST CATEGORY " + catNameSplit[0]); //$NON-NLS-1$
1965 }
1966
1967 Iterator<Article> checkForSoldArticlesIterator = articleList
1968 .iterator();
1969 int numberOfSoldArticles = 0;
1970 while (checkForSoldArticlesIterator.hasNext()) {
1971 Article actual = checkForSoldArticlesIterator
1972 .next();
1973 if (actual.isSold()) {
1974 numberOfSoldArticles++;
1975 }
1976
1977 }
1978
1979 if (!articleList.isEmpty()) {
1980 // number of rows => number of articles minus
1981 // the sold ones
1982 Object[][] data = new Object[articleList.size()
1983 - numberOfSoldArticles][4];
1984 String[] columnNamesArticleTableBuyTab = {
1985 Messages.getString("GUI.title6"), Messages.getString("GUI.cuurentPrice6"), Messages.getString("GUI.timeLeft6"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1986 Messages.getString("GUI.ArticleNo6") }; //$NON-NLS-1$
1987
1988 // counter to prevent running out of array
1989 // bounds
1990 int counter = 0;
1991 // first the salesitems
1992 Iterator<Article> it = articleList.iterator();
1993 while (it.hasNext()) {
1994 Object actual = it.next();
1995
1996 if (actual.getClass().getSimpleName()
1997 .equals("SalesItem")) { //$NON-NLS-1$
1998 // if article isn't sold add it to the
1999 // list
2000 if (!((SalesItem) actual).isSold()) {
2001 data[counter][0] = ((SalesItem) actual)
2002 .getTitle();
2003 data[counter][1] = ((SalesItem) actual)
2004 .getPrice();
2005 data[counter][2] = ""; //$NON-NLS-1$
2006 data[counter][3] = ((SalesItem) actual)
2007 .getArticleNo();
2008 counter++;
2009 }
2010 }
2011 }
2012
2013 // then the auction items
2014 Iterator<Article> it2 = articleList.iterator();
2015 while (it2.hasNext()) {
2016 Object actual = it2.next();
2017
2018 if (actual.getClass().getSimpleName()
2019 .equals("AuctionArticle")) { //$NON-NLS-1$
2020 // if article isn't sold add it to the
2021 // list
2022 if (!((AuctionArticle) actual).isSold()) {
2023 data[counter][0] = ((AuctionArticle) actual)
2024 .getTitle();
2025
2026 //if the minbiddingprice is higher than the currentmaxbid the minbidding price is shown
2027 //this should ONLY be the case if there is no bid yet. then the currentmaxbid is 0.00
2028 if( ((AuctionArticle) actual).getMinBiddingPrice() > ((AuctionArticle) actual).getCurrentMaxBid() ){
2029 data[counter][1] = ((AuctionArticle) actual).getMinBiddingPrice();
2030
2031 //if the currentmaxbid is higher than the minbiddingprice show the currentmax bid
2032 }else{
2033 data[counter][1] = ((AuctionArticle) actual)
2034 .getCurrentMaxBid();
2035 }
2036
2037 data[counter][2] = dateDifferenceToString(((AuctionArticle) actual)
2038 .getAuctionEnd());
2039 data[counter][3] = ((AuctionArticle) actual)
2040 .getArticleNo();
2041 counter++;
2042 }
2043 }
2044 }
2045
2046 articleTableBuyTab = new JTable(new MyTableModel(columnNamesArticleTableBuyTab, data));
2047 articleTableBuyTab
2048 .setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
2049 articleTableBuyTab.setAutoCreateRowSorter(true);
2050 articleTableBuyTabScrollPane
2051 .setViewportView(articleTableBuyTab);
2052
2053 // set column widths so that they fill the panel
2054 articleTableBuyTab.getColumnModel()
2055 .getColumn(0).setPreferredWidth(268);
2056 articleTableBuyTab.getColumnModel()
2057 .getColumn(1).setPreferredWidth(80);
2058 articleTableBuyTab.getColumnModel()
2059 .getColumn(2).setPreferredWidth(110);
2060
2061 }
2062 }
2063 }
2064 });
2065 categoryListBuyTab
2066 .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
2067 categoryListBuyTab.setLayoutOrientation(JList.VERTICAL);
2068 categoryListBuyTab.setVisible(true);
2069
2070 categoryListBuyTabScrollPane.setViewportView(categoryListBuyTab);
2071
2072 //button will most likely be deleted
2073 // btnShowSelectedCategory = new JButton("show selected Category");
2074 // btnShowSelectedCategory.addMouseListener(new MouseAdapter() {
2075 // @Override
2076 // public void mouseClicked(MouseEvent arg0) {
2077 // String selectedCategory = (String)
2078 // categoryListBuyTab.getSelectedValue();
2079 // String[] catNameSplit = selectedCategory.split(" ");
2080 // execute("LIST CATEGORY "+catNameSplit[0]);
2081 //
2082 // if(!articleList.isEmpty()){
2083 // Object[][] data = new Object[articleList.size()][3];
2084 // String[] columnNamesArticleTableBuyTab = { "Title", "Current Price",
2085 // "Time left" };
2086 //
2087 // //counter to prevent running out of array bounds
2088 // int counter = 0;
2089 // //first the salesitems
2090 // Iterator<Article> it = articleList.iterator();
2091 // while (it.hasNext()){
2092 // Object actual = it.next();
2093 //
2094 // if(actual.getClass().getSimpleName().equals("SalesItem")){
2095 //
2096 // data[counter][0] = ((SalesItem) actual).getTitle();
2097 // data[counter][1] = ((SalesItem) actual).getPrice();
2098 // data[counter][2] = "";
2099 // counter++;
2100 // }
2101 // }
2102 //
2103 // //then the auction items
2104 // Iterator<Article> it2 = articleList.iterator();
2105 // while(it2.hasNext()){
2106 // Object actual = it2.next();
2107 //
2108 // if(actual.getClass().getSimpleName().equals("AuctionArticle")){
2109 // data[counter][0] = ((AuctionArticle) actual).getTitle();
2110 // data[counter][1] = ((AuctionArticle) actual).getCurrentMaxBid();
2111 // data[counter][2] = dateDifferenceToString(((AuctionArticle)
2112 // actual).getAuctionEnd());
2113 // counter++;
2114 // }
2115 // }
2116 //
2117 //
2118 // articleTableBuyTab = new JTable(data, columnNamesArticleTableBuyTab);
2119 // articleTableBuyTab.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
2120 // articleTableBuyTab.setAutoCreateRowSorter(true);
2121 // articleTableBuyTabScrollPane.setViewportView(articleTableBuyTab);
2122 //
2123 // //set column widths so that they fill the panel
2124 // articleTableBuyTab.getColumnModel().getColumn(0).setPreferredWidth(240);
2125 // articleTableBuyTab.getColumnModel().getColumn(1).setPreferredWidth(80);
2126 // articleTableBuyTab.getColumnModel().getColumn(2).setPreferredWidth(110);
2127 //
2128 //
2129 // }
2130 //
2131 // }
2132 // });
2133 // buyTabPanel.add(btnShowSelectedCategory, "2, 10, center, default");
2134
2135 /**
2136 * shows the article details of the article selected in the
2137 * articleTableBuyTab jtable
2138 */
2139 btnShowArticleDetails = new JButton(Messages.getString("GUI.showArticleDetails")); //$NON-NLS-1$
2140 btnShowArticleDetails.addMouseListener(new MouseAdapter() {
2141 @Override
2142 public void mouseClicked(MouseEvent arg0) {
2143
2144 // check if a row is selected (-1 means no row selected)
2145 if (articleTableBuyTab.getSelectedRow() != -1) {
2146 int articleToGetId = (Integer) articleTableBuyTab
2147 .getValueAt(articleTableBuyTab.getSelectedRow(), 3);
2148
2149 execute("SHOW ARTICLE " + articleToGetId); //$NON-NLS-1$
2150
2151 // check because of possible transmission errors
2152 if (editArticle != null) {
2153 lblArticleTitleHere.setText(editArticle.getTitle());
2154 if (editArticle.getClass().getSimpleName().equals(
2155 "SalesItem")) { //$NON-NLS-1$
2156 SalesItem tempItem = (SalesItem) editArticle;
2157 lblCurrentPriceHere.setText(String.valueOf(tempItem
2158 .getPrice()));
2159 // sales items don't have an auction end or bids and
2160 // you can't buy them
2161 lblAuctionEnd.setVisible(false);
2162 lblAuctionEndAnd.setVisible(false);
2163 lblNoOfBids.setVisible(false);
2164 lblDisplayNoOfBids.setVisible(false);
2165 btnBuyArticle.setVisible(true);
2166 btnBidOnArticle.setVisible(false);
2167 btnChangeBid.setVisible(false);
2168
2169 lblMaxBidHere.setVisible(false);
2170 lblYourMaxBid.setVisible(false);
2171
2172 } else if (editArticle.getClass().getSimpleName()
2173 .equals("AuctionArticle")) { //$NON-NLS-1$
2174 AuctionArticle tempArticle = (AuctionArticle) editArticle;
2175
2176 //if the minbiddingprice is higher than the currentmaxbid the minbidding price is shown
2177 //this should ONLY be the case if there is no bid yet. then the currentmaxbid is 0.00
2178 if( tempArticle.getMinBiddingPrice() > tempArticle.getCurrentMaxBid() ){
2179 lblCurrentPriceHere.setText(String
2180
2181 .valueOf(tempArticle.getMinBiddingPrice())
2182 + " EUR");
2183
2184 //if the currentmaxbid is higher than the minbiddingprice show the currentmax bid
2185 }else{
2186 lblCurrentPriceHere.setText(String
2187 .valueOf(tempArticle.getCurrentMaxBid())
2188 + " EUR");
2189 }
2190
2191
2192 lblAuctionEndAnd
2193 .setText(dateDifferenceToString(tempArticle
2194 .getAuctionEnd())
2195 + " (" //$NON-NLS-1$
2196 + gregorianToString(tempArticle
2197 .getAuctionEnd(), "long") //$NON-NLS-1$
2198 + ")"); //$NON-NLS-1$
2199 lblDisplayNoOfBids.setText(String
2200 .valueOf(tempArticle.getBidList().size()));
2201
2202 // //sales items don't have an auction end or bids
2203 // but auction articles do
2204 lblAuctionEnd.setVisible(true);
2205 lblAuctionEndAnd.setVisible(true);
2206 lblNoOfBids.setVisible(true);
2207 lblDisplayNoOfBids.setVisible(true);
2208 btnBuyArticle.setVisible(false);
2209
2210 lblMaxBidHere.setVisible(true);
2211 lblYourMaxBid.setVisible(true);
2212
2213 // determin whether to show the bid (for the first
2214 // time) on article or the change bid button
2215 Iterator<Bid> it = tempArticle.getBidList()
2216 .iterator();
2217 boolean userAlreadyBidOnArticle = false;
2218 double userCurrentMaxBid = 0;
2219 while (it.hasNext()) {
2220 Bid actual = it.next();
2221 System.out.println("user corresponding to the bid: "+actual.getCorrespondingUser().getUsername());
2222 System.out.println("user currently logged in: "+usernameTempSaved);
2223 System.out.println("are the the same? "+actual.getCorrespondingUser().getUsername().equals(usernameTempSaved));
2224 if (actual.getCorrespondingUser().getUsername().equals(
2225 usernameTempSaved)) {
2226 userAlreadyBidOnArticle = true;
2227 // user's current bid on article
2228 userCurrentMaxBid = actual.getMaxBid();
2229 System.out.println(usernameTempSaved+" max bid: "+actual.getMaxBid());
2230 }
2231 }
2232 if (userAlreadyBidOnArticle) {
2233 btnBidOnArticle.setVisible(false);
2234 btnChangeBid.setVisible(true);
2235 lblYourMaxBid.setVisible(true);
2236 lblMaxBidHere.setVisible(true);
2237 lblMaxBidHere.setText(String
2238 .valueOf(userCurrentMaxBid));
2239 } else {
2240 btnBidOnArticle.setVisible(true);
2241 btnChangeBid.setVisible(false);
2242 lblMaxBidHere.setVisible(false);
2243 lblYourMaxBid.setVisible(false);
2244 }
2245 }
2246
2247 articleDescriptionTextAreaBuyTab.setText(editArticle
2248 .getDescription());
2249 lblArticlenoHere.setText(String.valueOf(editArticle
2250 .getArticleNo()));
2251 lblVendorNameHere.setText(editArticle.getVendor()
2252 .getUsername());
2253
2254 // did the vendor select show phone?
2255 if (editArticle.isShowPhoneNoSet()) {
2256 lblPhonenoHere.setText(editArticle.getVendor()
2257 .getPhoneNo());
2258 } else {
2259 lblPhonenoHere.setText(Messages.getString("GUI.NotVisible")); //$NON-NLS-1$
2260 }
2261 // did the vendor select show email?
2262 if (editArticle.isShowEmailSet()) {
2263 lblEmailHere.setText(editArticle.getVendor()
2264 .getEmail());
2265 } else {
2266 lblEmailHere.setText(Messages.getString("GUI.NotVisible2")); //$NON-NLS-1$
2267 }
2268 }
2269
2270 // index -1 => no article selected
2271 } else {
2272 JOptionPane
2273 .showMessageDialog(
2274 null,
2275 Messages.getString("GUI.NoSelected"), //$NON-NLS-1$
2276 Messages.getString("GUI.NoSelectedArticle"), //$NON-NLS-1$
2277 JOptionPane.WARNING_MESSAGE);
2278
2279 }
2280
2281 }
2282 });
2283 buyTabPanel.add(btnShowArticleDetails, "4, 10, 3, 1, center, default"); //$NON-NLS-1$
2284
2285 /**
2286 * the sell tab
2287 */
2288 sellTabPanel = new JPanel();
2289
2290 tabbedPane.addTab("Sell", null, sellTabPanel, null);
2291 sellTabPanel.setLayout(new FormLayout(new ColumnSpec[] {
2292 FormFactory.RELATED_GAP_COLSPEC,
2293 ColumnSpec.decode("210px"),
2294 FormFactory.RELATED_GAP_COLSPEC,
2295 ColumnSpec.decode("150px"),
2296 FormFactory.RELATED_GAP_COLSPEC,
2297 ColumnSpec.decode("30px"),
2298 FormFactory.RELATED_GAP_COLSPEC,
2299 ColumnSpec.decode("100px"),
2300 FormFactory.RELATED_GAP_COLSPEC,
2301 ColumnSpec.decode("160px"),
2302 FormFactory.RELATED_GAP_COLSPEC,
2303 ColumnSpec.decode("150px"),
2304 FormFactory.RELATED_GAP_COLSPEC,
2305 ColumnSpec.decode("140px"),
2306 FormFactory.RELATED_GAP_COLSPEC,
2307 FormFactory.DEFAULT_COLSPEC,},
2308 new RowSpec[] {
2309 FormFactory.RELATED_GAP_ROWSPEC,
2310 RowSpec.decode("default:grow"),
2311 FormFactory.RELATED_GAP_ROWSPEC,
2312 FormFactory.DEFAULT_ROWSPEC,
2313 FormFactory.RELATED_GAP_ROWSPEC,
2314 FormFactory.DEFAULT_ROWSPEC,
2315 FormFactory.RELATED_GAP_ROWSPEC,
2316 RowSpec.decode("default:grow"),
2317 FormFactory.RELATED_GAP_ROWSPEC,
2318 FormFactory.DEFAULT_ROWSPEC,
2319 FormFactory.RELATED_GAP_ROWSPEC,
2320 FormFactory.DEFAULT_ROWSPEC,
2321 FormFactory.RELATED_GAP_ROWSPEC,
2322 RowSpec.decode("max(19dlu;min)"),
2323 FormFactory.RELATED_GAP_ROWSPEC,
2324 RowSpec.decode("max(19dlu;min)"),
2325 FormFactory.RELATED_GAP_ROWSPEC,
2326 FormFactory.DEFAULT_ROWSPEC,
2327 FormFactory.RELATED_GAP_ROWSPEC,
2328 FormFactory.DEFAULT_ROWSPEC,
2329 FormFactory.RELATED_GAP_ROWSPEC,
2330 FormFactory.DEFAULT_ROWSPEC,
2331 FormFactory.RELATED_GAP_ROWSPEC,
2332 FormFactory.DEFAULT_ROWSPEC,
2333 FormFactory.RELATED_GAP_ROWSPEC,
2334 FormFactory.DEFAULT_ROWSPEC,
2335 FormFactory.RELATED_GAP_ROWSPEC,
2336 FormFactory.DEFAULT_ROWSPEC,
2337 FormFactory.RELATED_GAP_ROWSPEC,
2338 FormFactory.DEFAULT_ROWSPEC,}));
2339
2340
2341 /**
2342 * combobox representing choices for article insertion (sales item or
2343 * auction article) location: sell tab, left hand side
2344 */
2345 String[] articleInsertionChoices = { Messages.getString("GUI.InsertSalesItem"), //$NON-NLS-1$
2346 Messages.getString("GUI.inerstAuctionArticle") }; //$NON-NLS-1$
2347 comboBox = new JComboBox(articleInsertionChoices);
2348 comboBox.addActionListener(new ActionListener() {
2349 public void actionPerformed(ActionEvent arg0) {
2350 if (comboBox.getSelectedItem().equals(Messages.getString("GUI.InsertSalesItem2"))) { //$NON-NLS-1$
2351 txtAuctionEndDate.setVisible(false);
2352 lblFormatYymmdd.setVisible(false);
2353
2354 } else if (comboBox.getSelectedItem().equals(
2355 Messages.getString("GUI.inerstAuctionArticle2"))) { //$NON-NLS-1$
2356 txtAuctionEndDate.setVisible(true);
2357 lblFormatYymmdd.setVisible(true);
2358 }
2359
2360 }
2361 });
2362 sellTabPanel.add(comboBox, "2, 2"); //$NON-NLS-1$
2363
2364 /**
2365 * updates the article list shown in the sell tab. shows the articles
2366 * offered by the user currently logged in. location: selll tab, right
2367 * hand side
2368 */
2369 btnUpdateArticleList = new JButton(Messages.getString("GUI.UpdateList")); //$NON-NLS-1$
2370 btnUpdateArticleList.addMouseListener(new MouseAdapter() {
2371 @Override
2372 public void mouseClicked(MouseEvent arg0) {
2373 String[] columnNamesArticleListChangeArticle = { Messages.getString("GUI.ArtNo"), //$NON-NLS-1$
2374 Messages.getString("GUI.Title7"), Messages.getString("GUI.Describtion7"), Messages.getString("GUI.CurrentPrice7"), Messages.getString("GUI.TimeLeft7"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
2375 Messages.getString("GUI.Status7") }; //$NON-NLS-1$
2376
2377 String articlesByUser = usernameTempSaved;
2378 if (checkForMalformedValues(articlesByUser, Messages.getString("GUI.Username7"))) { //$NON-NLS-1$
2379 execute("LIST USER " + articlesByUser); //$NON-NLS-1$
2380 Object[][] data = new Object[articleList.size()][6];
2381 if (articleList.size() != 0) {
2382 // counter to prevent running out of array bounds
2383 int counter = 0;
2384 // first the salesitems
2385 Iterator<Article> it = articleList.iterator();
2386 while (it.hasNext()) {
2387 Object actual = it.next();
2388
2389 if (actual.getClass().getSimpleName().equals(
2390 "SalesItem")) { //$NON-NLS-1$
2391 data[counter][0] = ((SalesItem) actual)
2392 .getArticleNo();
2393 data[counter][1] = ((SalesItem) actual)
2394 .getTitle();
2395 data[counter][2] = ((SalesItem) actual)
2396 .getDescription();
2397 data[counter][3] = ((SalesItem) actual)
2398 .getPrice();
2399 data[counter][4] = ""; //$NON-NLS-1$
2400 if (((SalesItem) actual).isSold()) {
2401 data[counter][5] = "sold"; //$NON-NLS-1$
2402 } else {
2403 data[counter][5] = "available"; //$NON-NLS-1$
2404 }
2405 counter++;
2406 }
2407 }
2408
2409 // then the auction items
2410 Iterator<Article> it2 = articleList.iterator();
2411 while (it2.hasNext()) {
2412 Object actual = it2.next();
2413
2414 if (actual.getClass().getSimpleName().equals(
2415 "AuctionArticle")) { //$NON-NLS-1$
2416 data[counter][0] = ((AuctionArticle) actual)
2417 .getArticleNo();
2418 data[counter][1] = ((AuctionArticle) actual)
2419 .getTitle();
2420 data[counter][2] = ((AuctionArticle) actual)
2421 .getDescription();
2422 //if the minbiddingprice is higher than the currentmaxbid the minbidding price is shown
2423 //this should ONLY be the case if there is no bid yet. then the currentmaxbid is 0.00
2424 if( ((AuctionArticle) actual).getMinBiddingPrice() > ((AuctionArticle) actual).getCurrentMaxBid() ){
2425 data[counter][3] = ((AuctionArticle) actual).getMinBiddingPrice();
2426
2427 //if the currentmaxbid is higher than the minbiddingprice show the currentmax bid
2428 }else{
2429 data[counter][3] = ((AuctionArticle) actual)
2430 .getCurrentMaxBid();
2431 }
2432
2433 data[counter][4] = dateDifferenceToString(((AuctionArticle) actual)
2434 .getAuctionEnd());
2435 if (((AuctionArticle) actual).isSold()) {
2436 data[counter][5] = "sold"; //$NON-NLS-1$
2437 } else {
2438 data[counter][5] = "available"; //$NON-NLS-1$
2439 }
2440 counter++;
2441 }
2442 }
2443
2444 //reset fields
2445 //TODO reset jtable on right side of sell tab
2446 currentArticleCategoriesListModel.removeAllElements();
2447 txtrCurrentDescription.setText("current description");
2448 txtrAddToCurrentDescription.setText("add to current description");
2449 changeArticleDataNewCategoryTextField.setText("new Category");
2450 changeArticleDataChangePriceTextField.setText("price");
2451
2452 showMyArticlesTable = new JTable(new MyTableModel(columnNamesArticleListChangeArticle, data));
2453 showMyArticlesTable
2454 .setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
2455 showMyArticlesTable.setAutoCreateRowSorter(true);
2456
2457 showMyArticlesTableScrollPane
2458 .setViewportView(showMyArticlesTable);
2459 }else{
2460 //show empty jtable
2461 showMyArticlesTable.removeAll();
2462 Object[][] data2 = new Object[0][0];
2463 showMyArticlesTable.setModel(new MyTableModel(columnNamesArticleListChangeArticle, data2));
2464 showMyArticlesTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
2465 showMyArticlesTable.setAutoCreateRowSorter(true);
2466 showMyArticlesTableScrollPane.setViewportView(showMyArticlesTable);
2467
2468
2469 JOptionPane.showMessageDialog(null,
2470 "You don't sell anything. So we cannot show you what you sell. Sounds reasonable doesn't it?",
2471 "No items found", JOptionPane.WARNING_MESSAGE);
2472 }
2473 }
2474 }
2475 });
2476
2477 sellTabPanel.add(btnUpdateArticleList, "10, 2"); //$NON-NLS-1$
2478
2479
2480 /**
2481 * loads the article selected in showMyArticlesTable into the article
2482 * change interface location: sell tab. right hand side
2483 */
2484 btnEditSelectedArticle = new JButton(Messages.getString("GUI.EditArticle")); //$NON-NLS-1$
2485 btnEditSelectedArticle.addMouseListener(new MouseAdapter() {
2486 @Override
2487 public void mouseClicked(MouseEvent arg0) {
2488 // check if an article is selected
2489 if (showMyArticlesTable.getSelectedRow() != -1) {
2490 int articleIdToChange = (Integer) showMyArticlesTable
2491 .getValueAt(showMyArticlesTable.getSelectedRow(), 0);
2492
2493 execute("SHOW ARTICLE " + articleIdToChange); //$NON-NLS-1$
2494
2495
2496 // check because of possible transmission errors
2497 if (editArticle != null) {
2498 txtrCurrentDescription.setText(editArticle
2499 .getDescription());
2500
2501 if (editArticle.getClass().getSimpleName().equals(
2502 "AuctionArticle")) { //$NON-NLS-1$
2503 changeArticleDataChangePriceTextField
2504 .setVisible(false);
2505 btnSetNewPrice.setVisible(false);
2506
2507 } else if (editArticle.getClass().getSimpleName()
2508 .equals("SalesItem")) { //$NON-NLS-1$
2509 changeArticleDataChangePriceTextField
2510 .setVisible(true);
2511 SalesItem sale = (SalesItem) editArticle;
2512 changeArticleDataChangePriceTextField
2513 .setText(String.valueOf(sale.getPrice()));
2514 btnSetNewPrice.setVisible(true);
2515 }
2516 // clear categorylist in edit panel
2517 currentArticleCategoriesListModel.removeAllElements();
2518
2519 ArrayList<Category> tempCategoryList = editArticle
2520 .getCategoryList();
2521 Iterator<Category> it = tempCategoryList.iterator();
2522
2523 while (it.hasNext()) {
2524 Category actual = it.next();
2525 currentArticleCategoriesListModel.add(
2526 currentArticleCategoriesListModel.size(),
2527 actual.getCatName());
2528
2529 }
2530
2531 }
2532 } else {
2533 JOptionPane.showMessageDialog(null,
2534 Messages.getString("GUI.SelectArticle"), //$NON-NLS-1$
2535 Messages.getString("GUI.NoSelectArticle"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
2536 }
2537 }
2538 });
2539
2540 sellTabPanel.add(btnEditSelectedArticle, "12, 2"); //$NON-NLS-1$
2541
2542
2543 showMyArticlesPanel = new JPanel();
2544
2545 sellTabPanel.add(showMyArticlesPanel, "10, 3, 3, 7, fill, fill"); //$NON-NLS-1$
2546
2547 showMyArticlesPanel.setLayout(new FormLayout(new ColumnSpec[] {
2548 FormFactory.RELATED_GAP_COLSPEC,
2549 ColumnSpec.decode("default:grow"), }, new RowSpec[] { //$NON-NLS-1$
2550 FormFactory.RELATED_GAP_ROWSPEC,
2551 RowSpec.decode("default:grow"), })); //$NON-NLS-1$
2552
2553 String[] columnNamesArticleListChangeArticle = { "ArticleNo",
2554 "Title", "Description", "Current Price", "Time left",
2555 "Status" };
2556 showMyArticlesTable = new JTable();
2557 showMyArticlesTable.setModel(new MyTableModel(columnNamesArticleListChangeArticle,new Object[0][0]));
2558 showMyArticlesTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
2559 showMyArticlesTable.setAutoCreateRowSorter(true);
2560
2561 /**
2562 * scrollpane for showMyArticlesTable
2563 */
2564 showMyArticlesTableScrollPane = new JScrollPane();
2565 showMyArticlesPanel.add(showMyArticlesTableScrollPane,
2566
2567
2568 "2, 2, fill, fill");
2569 showMyArticlesTableScrollPane.setViewportView(showMyArticlesTable);
2570
2571
2572 /**
2573 * deleted the selected article if it is not sold and in case of an
2574 * auction article if there is no bid on it
2575 */
2576 btnDeleteSelectedArticle = new JButton(
2577 Messages.getString("GUI.deletArticle")); //$NON-NLS-1$
2578 btnDeleteSelectedArticle.addMouseListener(new MouseAdapter() {
2579 @Override
2580 public void mouseClicked(MouseEvent arg0) {
2581 if (showMyArticlesTable.getSelectedRow() != -1) {
2582 int articleIdToChange = (Integer) showMyArticlesTable
2583 .getValueAt(showMyArticlesTable.getSelectedRow(), 0);
2584 execute("SHOW ARTICLE " + articleIdToChange); //$NON-NLS-1$
2585
2586 // check because of possible transmission errors
2587 if (editArticle != null) {
2588 // is the article to be deleted an auction article?
2589 if (editArticle.getClass().getSimpleName().equals(
2590 "AuctionArticle")) { //$NON-NLS-1$
2591 AuctionArticle auction = (AuctionArticle) editArticle;
2592 // are bids given for this auction article? if no,
2593 // go on
2594 if (auction.getBidList().isEmpty()) {
2595 // is the auction article sold? if no, go on
2596 // delete it.
2597 // probably unnecessary check but better save
2598 // than sorry.
2599 if (!auction.isSold()) {
2600 execute("DELETE ARTICLE " //$NON-NLS-1$
2601 + articleIdToChange);
2602 }
2603 // bids on article -> cannot delete it
2604 } else if (!auction.getBidList().isEmpty()) {
2605 JOptionPane
2606 .showMessageDialog(
2607 null,
2608 Messages.getString("GUI.ConnotDelete"), //$NON-NLS-1$
2609 Messages.getString("GUI.DeletionError"), //$NON-NLS-1$
2610 JOptionPane.WARNING_MESSAGE);
2611 }
2612
2613 // or is the article to be deleted a sales item?
2614 } else if (editArticle.getClass().getSimpleName()
2615 .equals("SalesItem")) { //$NON-NLS-1$
2616 SalesItem sale = (SalesItem) editArticle;
2617 // is sales item already sold? if no, delete it
2618 if (!sale.isSold()) {
2619 execute("DELETE ARTICLE " + articleIdToChange); //$NON-NLS-1$
2620 }
2621 }
2622 }
2623 }
2624 }
2625 });
2626 txtArticleTitle = new JTextField();
2627 txtArticleTitle.setText(Messages.getString("GUI.ArticleTitle")); //$NON-NLS-1$
2628 sellTabPanel.add(txtArticleTitle, "2, 4, fill, default"); //$NON-NLS-1$
2629 txtArticleTitle.setColumns(10);
2630
2631 sellTabPanel.add(btnDeleteSelectedArticle, "14, 4"); //$NON-NLS-1$
2632
2633
2634 /**
2635 * article title textfield for article insertion location: sell tab,
2636 * left hand side
2637 */
2638
2639 /**
2640 * sets the selected article to unsold if the article was sold and the
2641 * buyer didn't pay
2642 */
2643 // work-around with html to be able to have a two line button
2644 btnSetSelectedArticle = new JButton(
2645 Messages.getString("GUI.selectedArticleTo")); //$NON-NLS-1$
2646 btnSetSelectedArticle.addMouseListener(new MouseAdapter() {
2647 @Override
2648 public void mouseClicked(MouseEvent arg0) {
2649
2650 // check if an article is selected
2651 if (showMyArticlesTable.getSelectedRow() != -1) {
2652 int articleIdToChange = (Integer) showMyArticlesTable
2653 .getValueAt(showMyArticlesTable.getSelectedRow(), 0);
2654 execute("SHOW ARTICLE " + articleIdToChange); //$NON-NLS-1$
2655
2656 // check because of possible transmission errors
2657 if (editArticle != null) {
2658 // if the article is marked as sold, change it
2659 if (editArticle.isSold()) {
2660 if (editArticle.getClass().getSimpleName().equals(
2661 "AuctionArticle")) { //$NON-NLS-1$
2662
2663 // get the new auction end date
2664 JTextField newAuctionEndDate = new JTextField();
2665 Object[] newAuctionEndDateFields = {
2666 Messages.getString("GUI.PleaseEnterNewAuction"), //$NON-NLS-1$
2667 newAuctionEndDate };
2668
2669 JOptionPane newAuctionEndDatePane = new JOptionPane(
2670 newAuctionEndDateFields,
2671 JOptionPane.PLAIN_MESSAGE,
2672 JOptionPane.OK_CANCEL_OPTION);
2673 newAuctionEndDatePane.createDialog(null,
2674 Messages.getString("GUI.AuctionEndDate0")) //$NON-NLS-1$
2675 .setVisible(true);
2676
2677 String newAuctionEndDateString = newAuctionEndDate
2678 .getText();
2679 if (checkForMalformedValues(
2680 newAuctionEndDateString, "auctionend")) { //$NON-NLS-1$
2681 execute("UNSOLD " + articleIdToChange); //$NON-NLS-1$
2682 execute("CHANGE AUCTIONEND " //$NON-NLS-1$
2683 + articleIdToChange + " TO " //$NON-NLS-1$
2684 + newAuctionEndDateString);
2685
2686 //if the change to unsold was successfull show it
2687 if(changeSoldFlagBool){
2688 JOptionPane
2689 .showMessageDialog(
2690 null,
2691 "The article is now set to unsold.",
2692 "Article set to unsold",
2693 JOptionPane.WARNING_MESSAGE);
2694
2695 //if not show it too
2696 }else{
2697 JOptionPane
2698 .showMessageDialog(
2699 null,
2700 "The article couldn't be set to unsold.",
2701 "Article NOT set to unsold",
2702 JOptionPane.WARNING_MESSAGE);
2703 }
2704 }
2705
2706 } else if (editArticle.getClass().getSimpleName()
2707
2708 .equals("SalesItem")) {
2709 execute("UNSOLD " + articleIdToChange);
2710
2711 //if the change to unsold was successfull show it
2712 if(changeSoldFlagBool){
2713 JOptionPane
2714 .showMessageDialog(
2715 null,
2716 "The article is now set to unsold.",
2717 "Article set to unsold",
2718 JOptionPane.WARNING_MESSAGE);
2719
2720 //if not show it too
2721 }else{
2722 JOptionPane
2723 .showMessageDialog(
2724 null,
2725 "The article couldn't be set to unsold.",
2726 "Article NOT set to unsold",
2727 JOptionPane.WARNING_MESSAGE);
2728 }
2729
2730 }
2731
2732 // i have no idea how to make this easier. so
2733 // another big piece of copy paste code
2734 // ///////////start copy paste code
2735 String[] columnNamesArticleListChangeArticle = {
2736 Messages.getString("GUI.ArticleNo8"), Messages.getString("GUI.Title8"), Messages.getString("GUI.Description8"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
2737 Messages.getString("GUI.CurrentPrice8"), Messages.getString("GUI.TimeLeft8"), Messages.getString("GUI.Status") }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
2738
2739 String articlesByUser = usernameTempSaved;
2740 if (checkForMalformedValues(articlesByUser,
2741 Messages.getString("GUI.username8"))) { //$NON-NLS-1$
2742 execute("LIST USER " + articlesByUser); //$NON-NLS-1$
2743 Object[][] data = new Object[articleList.size()][6];
2744 if (articleList.size() != 0) {
2745 // counter to prevent running out of array
2746 // bounds
2747 int counter = 0;
2748 // first the salesitems
2749 Iterator<Article> it = articleList
2750 .iterator();
2751 while (it.hasNext()) {
2752 Object actual = it.next();
2753
2754 if (actual.getClass().getSimpleName()
2755 .equals("SalesItem")) { //$NON-NLS-1$
2756 data[counter][0] = ((SalesItem) actual)
2757 .getArticleNo();
2758 data[counter][1] = ((SalesItem) actual)
2759 .getTitle();
2760 data[counter][2] = ((SalesItem) actual)
2761 .getDescription();
2762 data[counter][3] = ((SalesItem) actual)
2763 .getPrice();
2764 data[counter][4] = ""; //$NON-NLS-1$
2765 if (((SalesItem) actual).isSold()) {
2766 data[counter][5] = "sold"; //$NON-NLS-1$
2767 } else {
2768 data[counter][5] = "available"; //$NON-NLS-1$
2769 }
2770 counter++;
2771 }
2772 }
2773
2774 // then the auction items
2775 Iterator<Article> it2 = articleList
2776 .iterator();
2777 while (it2.hasNext()) {
2778 Object actual = it2.next();
2779
2780 if (actual.getClass().getSimpleName()
2781 .equals("AuctionArticle")) { //$NON-NLS-1$
2782 data[counter][0] = ((AuctionArticle) actual)
2783 .getArticleNo();
2784 data[counter][1] = ((AuctionArticle) actual)
2785 .getTitle();
2786 data[counter][2] = ((AuctionArticle) actual)
2787 .getDescription();
2788
2789 //if the minbiddingprice is higher than the currentmaxbid the minbidding price is shown
2790 //this should ONLY be the case if there is no bid yet. then the currentmaxbid is 0.00
2791 if( ((AuctionArticle) actual).getMinBiddingPrice() > ((AuctionArticle) actual).getCurrentMaxBid() ){
2792 data[counter][3] = ((AuctionArticle) actual).getMinBiddingPrice();
2793
2794 //if the currentmaxbid is higher than the minbiddingprice show the currentmax bid
2795 }else{
2796 data[counter][3] = ((AuctionArticle) actual)
2797 .getCurrentMaxBid();
2798 }
2799
2800 data[counter][4] = dateDifferenceToString(((AuctionArticle) actual)
2801 .getAuctionEnd());
2802 if (((AuctionArticle) actual)
2803 .isSold()) {
2804 data[counter][5] = "sold"; //$NON-NLS-1$
2805 } else {
2806 data[counter][5] = "available"; //$NON-NLS-1$
2807 }
2808 counter++;
2809 }
2810 }
2811
2812 showMyArticlesTable = new JTable(data,
2813 columnNamesArticleListChangeArticle);
2814 showMyArticlesTable
2815 .setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
2816 showMyArticlesTable
2817 .setAutoCreateRowSorter(true);
2818
2819 showMyArticlesTableScrollPane
2820 .setViewportView(showMyArticlesTable);
2821 }
2822 }
2823
2824 // /////////end copy paste code
2825
2826 // if the article isn't marked as sold let the user
2827 // know he cannot fool the application
2828 } else if (!editArticle.isSold()) {
2829 JOptionPane
2830 .showMessageDialog(
2831 null,
2832 Messages.getString("GUI.ArticleIsntSold"), //$NON-NLS-1$
2833 Messages.getString("GUI.ConnotUnsold"), //$NON-NLS-1$
2834 JOptionPane.WARNING_MESSAGE);
2835 }
2836 }
2837
2838 } else {
2839 JOptionPane.showMessageDialog(null,
2840 Messages.getString("GUI.PleaseSelect"), //$NON-NLS-1$
2841 Messages.getString("GUI.NoSelected3"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
2842 }
2843 }
2844 });
2845
2846 sellTabPanel.add(btnSetSelectedArticle, "14, 8"); //$NON-NLS-1$
2847
2848
2849 /**
2850 * article description textarea for article insertion location: sell
2851 * tab, left hand side
2852 */
2853 articleDescriptionTextArea = new JTextArea(Messages.getString("GUI.ArticleDescription")); //$NON-NLS-1$
2854 articleDescriptionTextArea.setLineWrap(true);
2855
2856 /**
2857 * scrollpane for article description textarea
2858 */
2859 articleDescriptionTextAreaScrollPane = new JScrollPane();
2860 articleDescriptionTextAreaScrollPane
2861 .setViewportView(articleDescriptionTextArea);
2862 sellTabPanel.add(articleDescriptionTextAreaScrollPane,
2863 "2, 6, 1, 3, fill, fill"); //$NON-NLS-1$
2864
2865 /**
2866 * combobox for category selection. used while inserting articles
2867 * location: sell tab, left hand side
2868 */
2869 categorySelectionComboBox = new JComboBox(updateCategoryData());
2870 sellTabPanel.add(categorySelectionComboBox, "2, 10, fill, default"); //$NON-NLS-1$
2871
2872 /**
2873 * add category button. used while inserting articles. adds the selected
2874 * category to the jlist containing all article categories location:
2875 * sell tab, left hand side
2876 */
2877 btnAddCategory = new JButton(Messages.getString("GUI.AddCategory1")); //$NON-NLS-1$
2878 btnAddCategory.addMouseListener(new MouseAdapter() {
2879 @Override
2880 public void mouseClicked(MouseEvent arg0) {
2881 // adds the selected category from the category selection
2882 // combobox at the end of the selected category list
2883 currentCategorySelectionListModel.add(
2884 currentCategorySelectionList.getModel().getSize(),
2885 categorySelectionComboBox.getSelectedItem());
2886 }
2887 });
2888 sellTabPanel.add(btnAddCategory, "4, 10"); //$NON-NLS-1$
2889
2890 /**
2891 * text area displaying current description. used while editing article
2892 * data. location: sell tab, right hand side
2893 */
2894 txtrCurrentDescription = new JTextArea(Messages.getString("GUI.currentDescription")); //$NON-NLS-1$
2895 txtrCurrentDescription.setRows(3);
2896 txtrCurrentDescription.setEditable(false);
2897 txtrCurrentDescription.setLineWrap(true);
2898
2899 /**
2900 * scroll pane for text area displaying current description. see above
2901 * location: sell tab, right hand side
2902 */
2903 txtrCurrentDescriptionScrollPane = new JScrollPane();
2904 txtrCurrentDescriptionScrollPane
2905 .setViewportView(txtrCurrentDescription);
2906 sellTabPanel.add(txtrCurrentDescriptionScrollPane,
2907
2908 "10, 10, 3, 1, fill, fill"); //$NON-NLS-1$
2909
2910
2911 /**
2912 * text field for a adding an new category location: sell tab, left hand
2913 * side
2914 */
2915 txtNewCategory = new JTextField();
2916 txtNewCategory.setText(Messages.getString("GUI.NewCategory")); //$NON-NLS-1$
2917 sellTabPanel.add(txtNewCategory, "2, 12, fill, default"); //$NON-NLS-1$
2918 txtNewCategory.setColumns(10);
2919
2920 /**
2921 * button to add a new category. adds category to jlist with all article
2922 * categories. checks if the "new" category is really new and then adds
2923 * it to the jlist. after that all comboboxes containing the
2924 * categorylist are updated. location: sell tab, left hand side
2925 */
2926 btnAddNewCategory = new JButton(Messages.getString("GUI.addNewCategory")); //$NON-NLS-1$
2927 btnAddNewCategory.addMouseListener(new MouseAdapter() {
2928 @Override
2929 public void mouseClicked(MouseEvent arg0) {
2930 boolean alreadyExistingCategory = false;
2931 // if category name doesn't contain a space character ->
2932 // continue
2933 if (checkForMalformedValues(txtNewCategory.getText(),
2934 "category")) { //$NON-NLS-1$
2935 // check if new category name already exists (if so it's in
2936 // the categoryselectioncombobox)
2937 for (int i = 0; i < categorySelectionComboBox
2938 .getItemCount(); i++) {
2939 if (categorySelectionComboBox.getItemAt(i).equals(
2940 txtNewCategory.getText())) {
2941 alreadyExistingCategory = true;
2942 }
2943 }
2944
2945 // category is new? then add it to the list
2946 if (!alreadyExistingCategory) {
2947 // adds the selected category from the new category
2948 // textfield at the end of the selected category list
2949 currentCategorySelectionListModel.add(
2950 currentCategorySelectionList.getModel()
2951 .getSize(), txtNewCategory.getText());
2952
2953 //update category comboboxes with new category data
2954 categorySelectionComboBox.setModel(updateCategoryData());
2955 editArticleCategorySelectionComboBox.setModel(updateCategoryData());
2956
2957
2958 // category already exists? let the user know about that
2959 } else if (alreadyExistingCategory) {
2960 JOptionPane
2961 .showMessageDialog(
2962 null,
2963 Messages.getString("GUI.CategoryExistsPlease"), //$NON-NLS-1$
2964 Messages.getString("GUI.CategoryExistsAlreday"), //$NON-NLS-1$
2965 JOptionPane.WARNING_MESSAGE);
2966 }
2967 }
2968
2969 }
2970 });
2971 sellTabPanel.add(btnAddNewCategory, "4, 12"); //$NON-NLS-1$
2972
2973 /**
2974 * text area to gather additional description text for article.
2975 * location: sell tab, right hand side
2976 */
2977 txtrAddToCurrentDescription = new JTextArea();
2978 txtrAddToCurrentDescription.setLineWrap(true);
2979 txtrAddToCurrentDescription.setText(Messages.getString("GUI.AddToCurrentDescrip")); //$NON-NLS-1$
2980
2981 /**
2982 * scroll pane for txtrAddToCurrentDescription text area. location: sell
2983 * tab, right hand side
2984 */
2985 addToCurrentDescriptionScrollPane = new JScrollPane();
2986 addToCurrentDescriptionScrollPane
2987 .setViewportView(txtrAddToCurrentDescription);
2988 sellTabPanel.add(addToCurrentDescriptionScrollPane,
2989
2990 "10, 12, 3, 3, fill, fill"); //$NON-NLS-1$
2991
2992
2993 /**
2994 * listmodel to alter currentCategorySelectionList data
2995 *
2996 */
2997 currentCategorySelectionListModel = new DefaultListModel();
2998
2999 /**
3000 * list containing all currently selected categories for new article
3001 * location: sell tab, left hand side
3002 */
3003 currentCategorySelectionList = new JList(
3004 currentCategorySelectionListModel);
3005 currentCategorySelectionList
3006 .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
3007 currentCategorySelectionList.setLayoutOrientation(JList.VERTICAL);
3008 currentCategorySelectionList.setVisibleRowCount(3);
3009
3010 /**
3011 * scroll pane for currentCategorySelectionList location: sell tab, left
3012 * hand side
3013 */
3014 currentCategorySelectionListScrollPane = new JScrollPane();
3015 currentCategorySelectionListScrollPane
3016 .setViewportView(currentCategorySelectionList);
3017 sellTabPanel.add(currentCategorySelectionListScrollPane,
3018 "2, 14, 1, 3, fill, fill"); //$NON-NLS-1$
3019
3020 /**
3021 * lable beside currentCategorySelectionList location: sell tab, left
3022 * hand side
3023 */
3024 lblSelectedCategories = new JLabel(Messages.getString("GUI.SelectedCategory1")); //$NON-NLS-1$
3025 sellTabPanel.add(lblSelectedCategories, "4, 14, 1, 2"); //$NON-NLS-1$
3026
3027 /**
3028 * removes the selected category from the currentCategorySelectionList
3029 * location: sell tab, left hand side
3030 */
3031 btnRemoveSelectedCategory = new JButton(Messages.getString("GUI.removeCategory")); //$NON-NLS-1$
3032 btnRemoveSelectedCategory.addMouseListener(new MouseAdapter() {
3033 @Override
3034 public void mouseClicked(MouseEvent arg0) {
3035 int selectedIndex = currentCategorySelectionList
3036 .getSelectedIndex();
3037 if (selectedIndex != -1) {
3038 currentCategorySelectionListModel.remove(selectedIndex);
3039 }
3040 }
3041 });
3042 sellTabPanel.add(btnRemoveSelectedCategory, "4, 16"); //$NON-NLS-1$
3043
3044 /**
3045 * adds the new description text from txtrAddToCurrentDescription to the
3046 * already existing description text
3047 */
3048 btnAddToDescription = new JButton(Messages.getString("GUI.AddToDescription")); //$NON-NLS-1$
3049 btnAddToDescription.addMouseListener(new MouseAdapter() {
3050 @Override
3051 public void mouseClicked(MouseEvent arg0) {
3052 // check because of possible transmission errors
3053 if (editArticle != null) {
3054
3055 execute("ADD DESCRIPTION " + editArticle.getArticleNo()
3056 + " \"" + "\n"+txtrAddToCurrentDescription.getText()
3057 + "\"");
3058
3059 }
3060 }
3061 });
3062
3063 sellTabPanel.add(btnAddToDescription, "12, 16");
3064
3065
3066 /**
3067 * checkbox to indicate whether the phone number should be visible on
3068 * article details location: sell tab, left hand side
3069 */
3070 chckbxShowPhonenoOn = new JCheckBox(Messages.getString("GUI.ShowPhoneNo")); //$NON-NLS-1$
3071 sellTabPanel.add(chckbxShowPhonenoOn, "2, 18, 3, 1"); //$NON-NLS-1$
3072
3073 /**
3074 * takes selected category from editArticleCategorySelectionComboBox and
3075 * adds the category to the article. location: sell tab, right hand side
3076 */
3077 editArticleAddCategoryButton = new JButton(Messages.getString("GUI.AddCategory8")); //$NON-NLS-1$
3078 editArticleAddCategoryButton.addMouseListener(new MouseAdapter() {
3079 @Override
3080 public void mouseClicked(MouseEvent arg0) {
3081 String newCategory = (String) editArticleCategorySelectionComboBox
3082 .getSelectedItem();
3083 // check because of possible transmission errors
3084 if (editArticle != null) {
3085 execute("ADD CATEGORY " + editArticle.getArticleNo() + " " //$NON-NLS-1$ //$NON-NLS-2$
3086 + newCategory);
3087 currentArticleCategoriesListModel.add(
3088 currentArticleCategoriesListModel.size(),
3089 editArticleCategorySelectionComboBox
3090 .getSelectedItem());
3091 }
3092 }
3093 });
3094
3095 /**
3096 * combobox showing all availible categories while editing article
3097 * location: sell tab, right hand side
3098 */
3099 editArticleCategorySelectionComboBox = new JComboBox(
3100 updateCategoryData());
3101 sellTabPanel.add(editArticleCategorySelectionComboBox,
3102
3103 "10, 18, fill, default");
3104 sellTabPanel.add(editArticleAddCategoryButton, "12, 18");
3105
3106
3107 /**
3108 * checkbox to indicate whether the e-mail address should be visible on
3109 * article details location: sell tab, left hand side
3110 */
3111 chckbxShowEmailOn = new JCheckBox(Messages.getString("GUI.ShowEmailOn")); //$NON-NLS-1$
3112 sellTabPanel.add(chckbxShowEmailOn, "2, 20, 3, 1"); //$NON-NLS-1$
3113
3114 /**
3115 * text field to add a new category to the article being edited
3116 * location: sell tab, right hand side
3117 */
3118 changeArticleDataNewCategoryTextField = new JTextField();
3119 changeArticleDataNewCategoryTextField.setText(Messages.getString("GUI.NewCategory8")); //$NON-NLS-1$
3120 changeArticleDataNewCategoryTextField.setColumns(10);
3121 sellTabPanel.add(changeArticleDataNewCategoryTextField,
3122
3123 "10, 20, fill, default");
3124
3125
3126 /**
3127 * adds a new, formerly unknown, category to the article being edited.
3128 * checks if the "new" category is really new. if so it adds it to the
3129 * jlist with the article categories and executes "ADD CATEGORY".
3130 * location: sell tab, right hand side
3131 */
3132 changeArticleDataAddNewCategoryButton = new JButton(Messages.getString("GUI.AddNewCategory8")); //$NON-NLS-1$
3133 changeArticleDataAddNewCategoryButton
3134 .addMouseListener(new MouseAdapter() {
3135 @Override
3136 public void mouseClicked(MouseEvent arg0) {
3137 boolean alreadyExistingCategory = false;
3138 // if category name doesn't contain a space character ->
3139 // continue
3140 if (checkForMalformedValues(
3141 changeArticleDataNewCategoryTextField.getText(),
3142 "category")) { //$NON-NLS-1$
3143 // check if new category name already exists (if so
3144 // it's in the categoryselectioncombobox)
3145 for (int i = 0; i < editArticleCategorySelectionComboBox
3146 .getItemCount(); i++) {
3147 if (editArticleCategorySelectionComboBox
3148 .getItemAt(i).equals(
3149 changeArticleDataNewCategoryTextField
3150 .getText())) {
3151 alreadyExistingCategory = true;
3152 }
3153 }
3154
3155 // category is new? then add it to the list
3156 if (!alreadyExistingCategory) {
3157 // adds the selected category from the new
3158 // category textfield at the end of the selected
3159 // category list
3160 currentArticleCategoriesListModel.add(
3161 currentArticleCategoriesList.getModel()
3162 .getSize(),
3163 changeArticleDataNewCategoryTextField
3164 .getText());
3165 // check because of possible transmission errors
3166 if (editArticle != null) {
3167 execute("ADD CATEGORY " //$NON-NLS-1$
3168 + editArticle.getArticleNo()
3169 + " " //$NON-NLS-1$
3170 + changeArticleDataNewCategoryTextField
3171 .getText());
3172
3173 //update category comboboxes with new category data
3174 categorySelectionComboBox.setModel(updateCategoryData());
3175 editArticleCategorySelectionComboBox.setModel(updateCategoryData());
3176 }
3177
3178 // category already exists? let the user know
3179 // about that
3180 } else if (alreadyExistingCategory) {
3181 JOptionPane
3182 .showMessageDialog(
3183 null,
3184 Messages.getString("GUI.CategoryAlreadyExistsPlease"), //$NON-NLS-1$
3185 Messages.getString("GUI.CategoryAlreadyExists"), //$NON-NLS-1$
3186 JOptionPane.WARNING_MESSAGE);
3187 }
3188 }
3189
3190 }
3191 });
3192
3193 sellTabPanel.add(changeArticleDataAddNewCategoryButton, "12, 20");
3194
3195
3196 /**
3197 * default list model to be able to edit currentArticleCategoriesList
3198 * data
3199 */
3200 currentArticleCategoriesListModel = new DefaultListModel();
3201
3202 /**
3203 * jlist containing all categories currently added to the article being
3204 * edited location: sell tab, right hand side
3205 */
3206 currentArticleCategoriesList = new JList(
3207 currentArticleCategoriesListModel);
3208 currentArticleCategoriesList
3209 .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
3210 currentArticleCategoriesList.setLayoutOrientation(JList.VERTICAL);
3211 currentArticleCategoriesList.setVisibleRowCount(3);
3212
3213 /**
3214 * scroll pane for currentArticleCategoriesList location: sell tab,
3215 * right hand side
3216 */
3217 currentArticleCategoriesListScrollPane = new JScrollPane();
3218 currentArticleCategoriesListScrollPane
3219 .setViewportView(currentArticleCategoriesList);
3220 sellTabPanel.add(currentArticleCategoriesListScrollPane,
3221
3222 "10, 22, 1, 3, fill, fill");
3223
3224
3225 /**
3226 * textfield containing the price of the article being inserted
3227 * location: sell tab, left hand side
3228 */
3229 txtPrice = new JTextField();
3230 txtPrice.setText(Messages.getString("GUI.Price9")); //$NON-NLS-1$
3231 sellTabPanel.add(txtPrice, "2, 22, fill, default"); //$NON-NLS-1$
3232
3233 /**
3234 * label beside txtPrice. location: sell tab, left hand side
3235 */
3236 lblMultiplesOf = new JLabel(Messages.getString("GUI.multiples")); //$NON-NLS-1$
3237 sellTabPanel.add(lblMultiplesOf, "4, 22"); //$NON-NLS-1$
3238
3239 changeArticleDataSelectedCategoriesLabel = new JLabel(
3240
3241 Messages.getString("GUI.selectedCategories6")); //$NON-NLS-1$
3242 sellTabPanel.add(changeArticleDataSelectedCategoriesLabel, "12, 22"); //$NON-NLS-1$
3243
3244
3245 /**
3246 * textfield to enter a auction end date while inserting a new article
3247 * location: sell tab, left hand side
3248 */
3249 txtAuctionEndDate = new JTextField();
3250 txtAuctionEndDate.setText(Messages.getString("GUI.auctionEndDate")); //$NON-NLS-1$
3251 sellTabPanel.add(txtAuctionEndDate, "2, 24, fill, default"); //$NON-NLS-1$
3252 // standard selection is sales item => invisible
3253 txtAuctionEndDate.setVisible(false);
3254
3255 /**
3256 * label indicating the format to be used when entering the auction end
3257 * date in txtAuctionEndDate. sales item is the standard selection when
3258 * inserting a new article. the label is invisible by default. location:
3259 * sell tab, left hand side
3260 */
3261 lblFormatYymmdd = new JLabel(Messages.getString("GUI.Format")); //$NON-NLS-1$
3262 sellTabPanel.add(lblFormatYymmdd, "4, 24, 3, 1"); //$NON-NLS-1$
3263 //standard selection is sales item => invisible
3264
3265 lblFormatYymmdd.setVisible(false);
3266
3267 /**
3268 * button to enter a new article into the system. checks for various
3269 * malformations before inserting the article location: sell tab, left
3270 * hand side
3271 */
3272
3273 /**
3274 * button to remove a category from the jlist containing all categories
3275 * from the article being edited location: sell tab, right hand side
3276 */
3277 changeArticleDataRemoveSelectedCategoryButton = new JButton(
3278 Messages.getString("GUI.RemoveCatego")); //$NON-NLS-1$
3279 changeArticleDataRemoveSelectedCategoryButton
3280 .addMouseListener(new MouseAdapter() {
3281 @Override
3282 public void mouseClicked(MouseEvent arg0) {
3283 if (currentArticleCategoriesList.getSelectedIndex() != -1) {
3284 // check because of possible transmission errors
3285 if (editArticle != null) {
3286 execute("DELETE CATEGORY " //$NON-NLS-1$
3287 + editArticle.getArticleNo()
3288 + " " //$NON-NLS-1$
3289 + currentArticleCategoriesList
3290 .getSelectedValue());
3291 currentArticleCategoriesListModel
3292 .remove(currentArticleCategoriesList
3293 .getSelectedIndex());
3294 }
3295 }
3296 }
3297 });
3298 sellTabPanel.add(changeArticleDataRemoveSelectedCategoryButton,
3299
3300 "12, 24");
3301
3302
3303 /**
3304 * textfield to change the price of a salesitem location: sell tab,
3305 * right hand side
3306 */
3307 btnInsertArticle = new JButton(Messages.getString("GUI.insertArticle")); //$NON-NLS-1$
3308 btnInsertArticle.addMouseListener(new MouseAdapter() {
3309 @Override
3310 public void mouseClicked(MouseEvent arg0) {
3311 // check for empty or default fields
3312 if (!txtArticleTitle.getText().isEmpty()
3313 && !articleDescriptionTextArea.getText().isEmpty()
3314 && !txtArticleTitle.getText().equals("Article title") //$NON-NLS-1$
3315 && !articleDescriptionTextArea.getText().equals(
3316 "Article description")) { //$NON-NLS-1$
3317
3318 // check if price is properly formed (X.X, multiple of 0.5,
3319 // no letters, no empty field, no default "price" string)
3320 if (checkForMalformedValues(txtPrice.getText(), "price")) { //$NON-NLS-1$
3321
3322 // do you want to add a sales item?
3323 if (comboBox.getSelectedItem().equals(
3324 "Insert Sales Item")) { //$NON-NLS-1$
3325 execute("INSERT SALE \"" //$NON-NLS-1$
3326 + txtArticleTitle.getText() + "\" " //$NON-NLS-1$
3327 + txtPrice.getText());
3328 if (newSetArticleNo != -1) {
3329 execute("ADD DESCRIPTION " + newSetArticleNo //$NON-NLS-1$
3330 + " \"" //$NON-NLS-1$
3331 + articleDescriptionTextArea.getText()
3332 + "\""); //$NON-NLS-1$
3333 }
3334
3335 // or do you want to add an auction article?
3336 } else if (comboBox.getSelectedItem().equals(
3337 "Insert Auction Article")) { //$NON-NLS-1$
3338 // is auction end in format YYMMDD-HHMMSS, not empty
3339 // and no just filled with default string?
3340 if (checkForMalformedValues(txtAuctionEndDate
3341 .getText(), "auctionend")) { //$NON-NLS-1$
3342 execute("INSERT AUCTION \"" //$NON-NLS-1$
3343 + txtArticleTitle.getText() + "\" " //$NON-NLS-1$
3344 + txtPrice.getText() + " " //$NON-NLS-1$
3345 + txtAuctionEndDate.getText());
3346 if (newSetArticleNo != -1) {
3347 execute("ADD DESCRIPTION " //$NON-NLS-1$
3348 + newSetArticleNo
3349 + " \"" //$NON-NLS-1$
3350 + articleDescriptionTextArea
3351 .getText() + "\""); //$NON-NLS-1$
3352 }
3353 }
3354 }
3355
3356 // if adding the article was successful, add the other
3357 // data
3358 if (newSetArticleNo != -1) {
3359 String[] categoriesToBeSet = new String[currentCategorySelectionListModel
3360 .size()];
3361 currentCategorySelectionListModel
3362 .copyInto(categoriesToBeSet);
3363 for (int i = 0; i < categoriesToBeSet.length; i++) {
3364 execute("ADD CATEGORY " + newSetArticleNo + " " //$NON-NLS-1$ //$NON-NLS-2$
3365 + categoriesToBeSet[i]);
3366 }
3367
3368 if (chckbxShowPhonenoOn.isSelected()) {
3369 execute("SHOW PHONE " + newSetArticleNo //$NON-NLS-1$
3370 + " TRUE"); //$NON-NLS-1$
3371 }
3372
3373 if (chckbxShowEmailOn.isSelected()) {
3374 execute("SHOW EMAIL " + newSetArticleNo //$NON-NLS-1$
3375 + " TRUE"); //$NON-NLS-1$
3376 }
3377
3378 JOptionPane.showMessageDialog(null,
3379 "Your Article was successfully inserted. It has the ArticleNo: "+newSetArticleNo,
3380 "Article successfully inserted", JOptionPane.WARNING_MESSAGE);
3381 }
3382 // reset the articleno value
3383 newSetArticleNo = -1;
3384
3385 //TODO Maritjes translations. currently everything is reset to english.
3386
3387 //reset the rest of the fields in the left half of the sell tab
3388 currentCategorySelectionListModel.removeAllElements();
3389 comboBox.setSelectedIndex(0);
3390 txtArticleTitle.setText("Article title");
3391 articleDescriptionTextArea.setText("Article description");
3392 txtNewCategory.setText("new Category");
3393 chckbxShowPhonenoOn.setSelected(false);
3394 chckbxShowEmailOn.setSelected(false);
3395 txtPrice.setText("price");
3396 txtAuctionEndDate.setText("auction end date");
3397
3398 }
3399 // if a field is empty, ask user to fill out all fields
3400 } else {
3401 JOptionPane.showMessageDialog(null,
3402 Messages.getString("GUI.PleaseFill"), //$NON-NLS-1$
3403 Messages.getString("GUI.MissingInfo"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
3404 }
3405 }
3406 });
3407 sellTabPanel.add(btnInsertArticle, "2, 26"); //$NON-NLS-1$
3408 changeArticleDataChangePriceTextField = new JTextField();
3409 changeArticleDataChangePriceTextField.setText(Messages.getString("GUI.Price0")); //$NON-NLS-1$
3410 sellTabPanel.add(changeArticleDataChangePriceTextField,
3411
3412 "10, 26, fill, default");
3413
3414
3415 /**
3416 * takes the value from changeArticleDataChangePriceTextField, checks it
3417 * for malformation and then sets the price to the new value. only works
3418 * for sales items! location: sell tab, right hand side
3419 */
3420 btnSetNewPrice = new JButton(Messages.getString("GUI.setNewPrice1")); //$NON-NLS-1$
3421 btnSetNewPrice.addMouseListener(new MouseAdapter() {
3422 @Override
3423 public void mouseClicked(MouseEvent arg0) {
3424 if (checkForMalformedValues(
3425 changeArticleDataChangePriceTextField.getText(),
3426 "price")) { //$NON-NLS-1$
3427 // check because of possible transmission errors
3428 if (editArticle != null) {
3429 execute("SET PRICE " //$NON-NLS-1$
3430 + editArticle.getArticleNo()
3431 + " " //$NON-NLS-1$
3432 + changeArticleDataChangePriceTextField
3433 .getText());
3434 }
3435 }
3436 }
3437 });
3438
3439 sellTabPanel.add(btnSetNewPrice, "12, 26");
3440
3441
3442 /**
3443 * messagetab
3444 */
3445 messagePanel = new JPanel();
3446 tabbedPane.addTab(Messages.getString("GUI.Messages1"), null, messagePanel, null); //$NON-NLS-1$
3447 messagePanel.setLayout(new FormLayout(
3448 new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC,
3449 FormFactory.DEFAULT_COLSPEC,
3450 FormFactory.RELATED_GAP_COLSPEC,
3451 FormFactory.DEFAULT_COLSPEC,
3452 FormFactory.RELATED_GAP_COLSPEC,
3453 FormFactory.DEFAULT_COLSPEC,
3454 FormFactory.RELATED_GAP_COLSPEC,
3455 ColumnSpec.decode("650px"), //$NON-NLS-1$
3456 FormFactory.RELATED_GAP_COLSPEC,
3457 FormFactory.DEFAULT_COLSPEC,
3458 FormFactory.RELATED_GAP_COLSPEC,
3459 FormFactory.DEFAULT_COLSPEC, }, new RowSpec[] {
3460 FormFactory.RELATED_GAP_ROWSPEC,
3461 FormFactory.DEFAULT_ROWSPEC,
3462 FormFactory.RELATED_GAP_ROWSPEC,
3463 FormFactory.DEFAULT_ROWSPEC,
3464 FormFactory.RELATED_GAP_ROWSPEC,
3465 FormFactory.DEFAULT_ROWSPEC,
3466 FormFactory.RELATED_GAP_ROWSPEC,
3467 FormFactory.DEFAULT_ROWSPEC, }));
3468
3469 /**
3470 * gets all messages for the user from the server and shows them in a
3471 * table
3472 */
3473 btnShowMessages = new JButton(Messages.getString("GUI.showMessages1")); //$NON-NLS-1$
3474 btnShowMessages.addMouseListener(new MouseAdapter() {
3475 @Override
3476 public void mouseClicked(MouseEvent arg0) {
3477 execute("SHOW MESSAGES"); //$NON-NLS-1$
3478 String[] columnNamesMessagelist = { Messages.getString("GUI.SendDate"), //$NON-NLS-1$
3479 Messages.getString("GUI.Title0"), Messages.getString("GUI.MessageContent") }; //$NON-NLS-1$ //$NON-NLS-2$
3480
3481 Object[][] dataMessagelist = new Object[messageList.size()][columnNamesMessagelist.length];
3482
3483 // if messages exist, show them
3484 if (messageList.size() != 0) {
3485 int counter = 0;
3486 Iterator<Message> it = messageList.iterator();
3487 while (it.hasNext()) {
3488 Message actual = it.next();
3489 dataMessagelist[counter][0] = gregorianToString(actual
3490 .getSendDate(), "short"); //$NON-NLS-1$
3491 dataMessagelist[counter][1] = actual.getTitle();
3492 dataMessagelist[counter][2] = actual.getMsgText();
3493 counter++;
3494 }
3495 }
3496 messageTable = new JTable(new MyTableModel(columnNamesMessagelist, dataMessagelist));
3497 messageTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
3498 // senddate column
3499 messageTable.getColumnModel().getColumn(0).setPreferredWidth(
3500 125);
3501 // title column
3502 messageTable.getColumnModel().getColumn(1).setPreferredWidth(
3503 150);
3504 // message content column
3505 messageTable.getColumnModel().getColumn(2).setPreferredWidth(
3506 650);
3507 messageTable.setAutoCreateRowSorter(true);
3508 messageTableScrollPane.setViewportView(messageTable);
3509
3510 }
3511 });
3512 messagePanel.add(btnShowMessages, "2, 2"); //$NON-NLS-1$
3513
3514 /**
3515 * sends the remove oldmessages command to the server and then updates
3516 * the message table
3517 */
3518 btnHideOldMessages = new JButton(Messages.getString("GUI.HideOldMsg")); //$NON-NLS-1$
3519 btnHideOldMessages.addMouseListener(new MouseAdapter() {
3520 @Override
3521 public void mouseClicked(MouseEvent arg0) {
3522 execute("REMOVE OLDMESSAGES"); //$NON-NLS-1$
3523 // buton.doClick() doesn't work because it's a mouseevent. so i
3524 // have to reuse the code
3525 execute("SHOW MESSAGES"); //$NON-NLS-1$
3526 String[] columnNamesMessagelist = { Messages.getString("GUI.SendDate()"), //$NON-NLS-1$
3527 Messages.getString("GUI.title0"), Messages.getString("GUI.messageConent") }; //$NON-NLS-1$ //$NON-NLS-2$
3528
3529 Object[][] dataMessagelist = new Object[messageList.size()][columnNamesMessagelist.length];
3530
3531 // if messages exist, show them
3532 if (messageList.size() != 0) {
3533 int counter = 0;
3534 Iterator<Message> it = messageList.iterator();
3535 while (it.hasNext()) {
3536 Message actual = it.next();
3537 dataMessagelist[counter][0] = gregorianToString(actual
3538 .getSendDate(), "short"); //$NON-NLS-1$
3539 dataMessagelist[counter][1] = actual.getTitle();
3540 dataMessagelist[counter][2] = actual.getMsgText();
3541 counter++;
3542 }
3543 }
3544 messageTable = new JTable(new MyTableModel(columnNamesMessagelist, dataMessagelist));
3545 messageTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
3546 // senddate column
3547 messageTable.getColumnModel().getColumn(0).setPreferredWidth(
3548 125);
3549 // title column
3550 messageTable.getColumnModel().getColumn(1).setPreferredWidth(
3551 150);
3552 // message content column
3553 messageTable.getColumnModel().getColumn(2).setPreferredWidth(
3554 650);
3555 messageTable.setAutoCreateRowSorter(true);
3556 messageTableScrollPane.setViewportView(messageTable);
3557
3558 }
3559 });
3560 messagePanel.add(btnHideOldMessages, "4, 2"); //$NON-NLS-1$
3561
3562 messageTableScrollPane = new JScrollPane();
3563 messagePanel.add(messageTableScrollPane, "2, 4, 7, 1, fill, fill"); //$NON-NLS-1$
3564
3565 messageTable = new JTable();
3566 String[] columnNamesMessagelist = {"Send date (YY.MM.DD)", "Title", "Message content"};
3567 messageTable.setModel(new MyTableModel(columnNamesMessagelist, new Object[0][0]));
3568 messageTableScrollPane.setViewportView(messageTable);
3569
3570 /**
3571 * user control tab
3572 */
3573 userControlCenterPanel = new JPanel();
3574 tabbedPane.addTab(Messages.getString("GUI.UCC3"), null, userControlCenterPanel, //$NON-NLS-1$
3575 null);
3576 userControlCenterPanel.setLayout(new FormLayout(new ColumnSpec[] {
3577 FormFactory.RELATED_GAP_COLSPEC,
3578 FormFactory.DEFAULT_COLSPEC,
3579 FormFactory.RELATED_GAP_COLSPEC,
3580 ColumnSpec.decode("max(40dlu;default)"), //$NON-NLS-1$
3581 FormFactory.RELATED_GAP_COLSPEC,
3582 ColumnSpec.decode("left:max(87dlu;default)"), //$NON-NLS-1$
3583 ColumnSpec.decode("max(33dlu;default)"), //$NON-NLS-1$
3584 FormFactory.RELATED_GAP_COLSPEC,
3585
3586 ColumnSpec.decode("max(100dlu;pref)"),
3587 FormFactory.RELATED_GAP_COLSPEC,
3588 FormFactory.DEFAULT_COLSPEC,
3589 FormFactory.RELATED_GAP_COLSPEC,
3590
3591
3592 ColumnSpec.decode("20px"),
3593
3594 FormFactory.RELATED_GAP_COLSPEC,
3595 ColumnSpec.decode("max(113dlu;default)"), //$NON-NLS-1$
3596 FormFactory.RELATED_GAP_COLSPEC,
3597
3598 ColumnSpec.decode("100px"),
3599 FormFactory.RELATED_GAP_COLSPEC,
3600 ColumnSpec.decode("max(34dlu;default)"),},
3601 new RowSpec[] {
3602 FormFactory.RELATED_GAP_ROWSPEC,
3603 FormFactory.DEFAULT_ROWSPEC,
3604 FormFactory.RELATED_GAP_ROWSPEC,
3605 FormFactory.DEFAULT_ROWSPEC,
3606
3607 FormFactory.RELATED_GAP_ROWSPEC,
3608
3609 FormFactory.DEFAULT_ROWSPEC,
3610 FormFactory.RELATED_GAP_ROWSPEC,
3611 RowSpec.decode("default:grow"),}));
3612
3613
3614 /**
3615 * label in user data change panel location: user control center tab,
3616 * upper window area
3617 */
3618 lblChange = new JLabel(Messages.getString("GUI.Change0")); //$NON-NLS-1$
3619 userControlCenterPanel.add(lblChange, "4, 4, right, default"); //$NON-NLS-1$
3620
3621 /**
3622 * values that can be changed for combobox
3623 */
3624
3625
3626 /**
3627 * combobox containing all values that can be changed by the user
3628 * location: user control center tab, upper window area
3629 */
3630 comboBoxChangeUserdata = new JComboBox(LanguagePack.possibleChangeValues());
3631 comboBoxChangeUserdata.addActionListener(new ActionListener() {
3632 public void actionPerformed(ActionEvent arg0) {
3633 changeSuccessLabel.setText("");
3634 }
3635 });
3636 userControlCenterPanel.add(comboBoxChangeUserdata,
3637 "6, 4, fill, default"); //$NON-NLS-1$
3638
3639 /**
3640 * label in user data change panel location: user control center tab,
3641 * upper window area
3642 */
3643 lblTo = new JLabel(Messages.getString("GUI.to")); //$NON-NLS-1$
3644 userControlCenterPanel.add(lblTo, "7, 4, center, default"); //$NON-NLS-1$
3645
3646 /**
3647 * textfield containing the new value for the value to be changed
3648 * location: user control center tab, upper window area
3649 */
3650 txtChangeNewValue = new JTextField();
3651 userControlCenterPanel.add(txtChangeNewValue, "9, 4, fill, default"); //$NON-NLS-1$
3652
3653 /**
3654 * button to execute change in user data. various checks are performed
3655 * before changing the value location: user control center tab, upper
3656 * window area
3657 */
3658 btnChangeOk = new JButton(Messages.getString("GUI.ok")); //$NON-NLS-1$
3659 btnChangeOk.addMouseListener(new MouseAdapter() {
3660 @Override
3661 public void mouseClicked(MouseEvent arg0) {
3662 // password change
3663 if (comboBoxChangeUserdata.getSelectedItem().equals("password")) { //$NON-NLS-1$
3664 if (checkForMalformedValues(txtChangeNewValue.getText(),
3665 "password")) { //$NON-NLS-1$
3666 execute("CHANGE USER " + usernameTempSaved //$NON-NLS-1$
3667 + " PASSWORD " + txtChangeNewValue.getText()); //$NON-NLS-1$
3668 }
3669 // last name change
3670 } else if (comboBoxChangeUserdata.getSelectedItem().equals(
3671 "last name")) { //$NON-NLS-1$
3672 execute("CHANGE USER " + usernameTempSaved + " LASTNAME \"" //$NON-NLS-1$ //$NON-NLS-2$
3673 + txtChangeNewValue.getText() + "\""); //$NON-NLS-1$
3674 // first name change
3675 } else if (comboBoxChangeUserdata.getSelectedItem().equals(
3676 "first name")) { //$NON-NLS-1$
3677 execute("CHANGE USER " + usernameTempSaved //$NON-NLS-1$
3678 + " FIRSTNAME \"" + txtChangeNewValue.getText() //$NON-NLS-1$
3679 + "\""); //$NON-NLS-1$
3680 // dateofbirth change
3681 } else if (comboBoxChangeUserdata.getSelectedItem().equals(
3682 "birthday")) { //$NON-NLS-1$
3683 if (checkForMalformedValues(txtChangeNewValue.getText(),
3684 "dateofbirth")) { //$NON-NLS-1$
3685 execute("CHANGE USER " + usernameTempSaved //$NON-NLS-1$
3686 + " BIRTHDAY " + txtChangeNewValue.getText()); //$NON-NLS-1$
3687 }
3688 // street change
3689 } else if (comboBoxChangeUserdata.getSelectedItem().equals(
3690 "street")) { //$NON-NLS-1$
3691 execute("CHANGE USER " + usernameTempSaved + " STREET \"" //$NON-NLS-1$ //$NON-NLS-2$
3692 + txtChangeNewValue.getText() + "\""); //$NON-NLS-1$
3693 // zip change
3694 } else if (comboBoxChangeUserdata.getSelectedItem().equals(
3695 "zip")) { //$NON-NLS-1$
3696 if (checkForMalformedValues(txtChangeNewValue.getText(),
3697 "zip")) { //$NON-NLS-1$
3698 execute("CHANGE USER " + usernameTempSaved + " ZIP " //$NON-NLS-1$ //$NON-NLS-2$
3699 + txtChangeNewValue.getText());
3700 }
3701 // location change
3702 } else if (comboBoxChangeUserdata.getSelectedItem().equals(
3703 "location")) { //$NON-NLS-1$
3704 execute("CHANGE USER " + usernameTempSaved + " CITY \"" //$NON-NLS-1$ //$NON-NLS-2$
3705 + txtChangeNewValue.getText() + "\""); //$NON-NLS-1$
3706 // phone change
3707 } else if (comboBoxChangeUserdata.getSelectedItem().equals(
3708 "phone")) { //$NON-NLS-1$
3709 if (checkForMalformedValues(txtChangeNewValue.getText(),
3710 "phoneno")) { //$NON-NLS-1$
3711 execute("CHANGE USER " + usernameTempSaved + " PHONE " //$NON-NLS-1$ //$NON-NLS-2$
3712 + txtChangeNewValue.getText());
3713 }
3714 // email change
3715 // TODO deutsche Begriffe
3716 } else if (comboBoxChangeUserdata.getSelectedItem().equals(
3717 "e-mail")) { //$NON-NLS-1$
3718 if (checkForMalformedValues(txtChangeNewValue.getText(),
3719 "email")) { //$NON-NLS-1$
3720 execute("CHANGE USER " + usernameTempSaved + " EMAIL " //$NON-NLS-1$ //$NON-NLS-2$
3721 + txtChangeNewValue.getText());
3722 }
3723 }
3724 // change user was successful
3725 if (changeBool) {
3726 changeSuccessLabel.setText("Value successfully changed!"); //$NON-NLS-1$
3727 // reset changeBool
3728 changeBool = false;
3729 }
3730 }
3731 });
3732 userControlCenterPanel.add(btnChangeOk, "11, 4"); //$NON-NLS-1$
3733
3734 /**
3735 * empty label to get some space between btnChangeOk and
3736 * changeSuccessLabel location: user control center tab, upper window
3737 * area
3738 */
3739 changeUserLabel = new JLabel(""); //$NON-NLS-1$
3740 userControlCenterPanel.add(changeUserLabel, "13, 4"); //$NON-NLS-1$
3741
3742 /**
3743 * label indicating when user data change was successful location: user
3744 * control center tab, upper window area
3745 */
3746 changeSuccessLabel = new JLabel(""); //$NON-NLS-1$
3747 userControlCenterPanel.add(changeSuccessLabel, "15, 4"); //$NON-NLS-1$
3748
3749 /**
3750 * panel with admin functions location: user control center tab, under
3751 * change value area
3752 */
3753 adminPanel = new JPanel();
3754 // adminpanel is invisible by default
3755 adminPanel.setVisible(false);
3756 userControlCenterPanel.add(adminPanel, "4, 8, 14, 1, left, fill"); //$NON-NLS-1$
3757 adminPanel.setLayout(new BorderLayout(0, 0));
3758
3759 /**
3760 * panel on adminPanel containing all the elements
3761 */
3762 adminControlsPanel = new JPanel();
3763 adminPanel.add(adminControlsPanel, BorderLayout.NORTH);
3764
3765 /**
3766 * textfield containing the username of the user to be edited. location:
3767 * user control center tab, under change value area
3768 */
3769 txtUsernameToEdit = new JTextField();
3770 txtUsernameToEdit.setText(Messages.getString("GUI.UserToEdit")); //$NON-NLS-1$
3771 adminControlsPanel.add(txtUsernameToEdit);
3772
3773 /**
3774 * button that deletes the user entered in txtUsernameToEdit. before
3775 * deleting a check is performed whether the user still has articles
3776 * entered into the system. if so the admin has to confirm if the user
3777 * should be deleted anyways location: user control center tab, under
3778 * change value area
3779 */
3780 btnDelete = new JButton(Messages.getString("GUI.Delete0")); //$NON-NLS-1$
3781 btnDelete.addMouseListener(new MouseAdapter() {
3782 @Override
3783 public void mouseClicked(MouseEvent arg0) {
3784 String userToBeDeleted = txtUsernameToEdit.getText();
3785 // request articles by user to be deleted to see if he still has
3786 // listed articles
3787 execute("LIST USER " + userToBeDeleted); //$NON-NLS-1$
3788 // check is username is malformed
3789 if (checkForMalformedValues(userToBeDeleted, "username")) { //$NON-NLS-1$
3790 // are articles by user to be deleted in the system?
3791 // no. delete him right away
3792 if (articleList.size() == 0) {
3793 execute("DELETE USER " + userToBeDeleted); //$NON-NLS-1$
3794
3795 // yes. check back with admin
3796 } else {
3797 Object[] options = { Messages.getString("GUI.YesDelete") + userToBeDeleted, //$NON-NLS-1$
3798 Messages.getString("GUI.NoDeleteHim") }; //$NON-NLS-1$
3799 int n = JOptionPane
3800 .showOptionDialog(
3801 frame,
3802 Messages.getString("GUI.DoYoureallyDelte") //$NON-NLS-1$
3803 + userToBeDeleted
3804 + Messages.getString("GUI.evenThoughHeStill"), //$NON-NLS-1$
3805 Messages.getString("GUI.DeletionWarning"), //$NON-NLS-1$
3806 JOptionPane.YES_NO_CANCEL_OPTION,
3807 JOptionPane.QUESTION_MESSAGE, null,
3808 options, options[1]);
3809 if (n == 0) {
3810 execute("DELETE USER " + userToBeDeleted); //$NON-NLS-1$
3811 }
3812 }
3813 }
3814 }
3815 });
3816 adminControlsPanel.add(btnDelete);
3817
3818 /**
3819 * locks the username entered in txtUsernameToEdit location: user
3820 * control center tab, under change value area
3821 */
3822 btnLock = new JButton(Messages.getString("GUI.Lock")); //$NON-NLS-1$
3823 btnLock.addMouseListener(new MouseAdapter() {
3824 @Override
3825 public void mouseClicked(MouseEvent arg0) {
3826 String userToBeLocked = txtUsernameToEdit.getText();
3827 // check if username is malformed
3828 if (checkForMalformedValues(userToBeLocked, "username")) { //$NON-NLS-1$
3829 execute("LOCK USER " + userToBeLocked); //$NON-NLS-1$
3830 // user was successfully locked
3831 if (lockBool) {
3832 JOptionPane.showMessageDialog(null, Messages.getString("GUI.user0") //$NON-NLS-1$
3833 + userToBeLocked + Messages.getString("GUI.successfullyLocked"), //$NON-NLS-1$
3834 Messages.getString("GUI.UsersuccessfullyLocked"), //$NON-NLS-1$
3835 JOptionPane.WARNING_MESSAGE);
3836
3837 // user was not successfully locked. user doesn't exist
3838 // etc.
3839 } else if (!lockBool) {
3840 JOptionPane
3841 .showMessageDialog(null, Messages.getString("GUI.User01") //$NON-NLS-1$
3842 + userToBeLocked
3843 + Messages.getString("GUI.coudntLock"), //$NON-NLS-1$
3844 Messages.getString("GUI.UserFailed"), //$NON-NLS-1$
3845 JOptionPane.WARNING_MESSAGE);
3846 }
3847 }
3848 }
3849 });
3850 adminControlsPanel.add(btnLock);
3851
3852 /**
3853 * unlocks the username entered in txtUsernameToEdit location: user
3854 * control center tab, under change value area
3855 */
3856 btnUnlock = new JButton(Messages.getString("GUI.Unlock")); //$NON-NLS-1$
3857 btnUnlock.addMouseListener(new MouseAdapter() {
3858 @Override
3859 public void mouseClicked(MouseEvent arg0) {
3860 String userToBeUnlocked = txtUsernameToEdit.getText();
3861 // check if username is malformed
3862 if (checkForMalformedValues(userToBeUnlocked, "username")) { //$NON-NLS-1$
3863 execute("UNLOCK USER " + userToBeUnlocked); //$NON-NLS-1$
3864 // user was successfully unlocked
3865 if (unlockBool) {
3866 JOptionPane.showMessageDialog(null, Messages.getString("GUI.User02") //$NON-NLS-1$
3867 + userToBeUnlocked + Messages.getString("GUI.successfullyUnlocked"), //$NON-NLS-1$
3868 Messages.getString("GUI.UsersuccessfullyUnlocked"), //$NON-NLS-1$
3869 JOptionPane.WARNING_MESSAGE);
3870
3871 // user was not successfully unlocked. user doesn't
3872 // exist etc.
3873 } else if (!unlockBool) {
3874 JOptionPane
3875 .showMessageDialog(
3876 null,
3877 Messages.getString("GUI.User03") //$NON-NLS-1$
3878 + userToBeUnlocked
3879 + Messages.getString("GUI.NotBeUnlocked"), //$NON-NLS-1$
3880 Messages.getString("GUI.UnlockedUser"), //$NON-NLS-1$
3881 JOptionPane.WARNING_MESSAGE);
3882 }
3883 }
3884
3885 }
3886 });
3887 adminControlsPanel.add(btnUnlock);
3888
3889 /**
3890 * lists all users location: user control center tab, under change value
3891 * area
3892 */
3893 btnShowUsers = new JButton(Messages.getString("GUI.ShowUsers0")); //$NON-NLS-1$
3894 btnShowUsers.addMouseListener(new MouseAdapter() {
3895 @Override
3896 public void mouseClicked(MouseEvent arg0) {
3897
3898 String[] columnNamesUserlist = { Messages.getString("GUI.LastName0"), Messages.getString("GUI.FirstName0"), //$NON-NLS-1$ //$NON-NLS-2$
3899 Messages.getString("GUI.Username04"), Messages.getString("GUI.Locked0"), Messages.getString("GUI.DateOfBirth0"), Messages.getString("GUI.Street0"), Messages.getString("GUI.Zip0"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
3900 Messages.getString("GUI.Location0"), Messages.getString("GUI.PhoneNo0"), Messages.getString("GUI.email0") }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
3901
3902 execute("SHOW USERS"); //$NON-NLS-1$
3903 Object[][] dataUserlist = new Object[userList.size()][10];
3904
3905 if (userList.size() != 0) {
3906 // counter to prevent running out of array bounds
3907 int counter = 0;
3908 Iterator<User> it = userList.iterator();
3909 // add one after another. list already sorted by last name
3910 // and first name on serverside
3911 while (it.hasNext()) {
3912 User actual = it.next();
3913 dataUserlist[counter][0] = actual.getLastName();
3914 dataUserlist[counter][1] = actual.getFirstName();
3915 dataUserlist[counter][2] = actual.getUsername();
3916 dataUserlist[counter][3] = actual.isLocked();
3917 dataUserlist[counter][4] = gregorianToString(actual
3918 .getDateOfBirth(), "short"); //$NON-NLS-1$
3919 dataUserlist[counter][5] = actual.getStreet();
3920 dataUserlist[counter][6] = actual.getZip();
3921 dataUserlist[counter][7] = actual.getLocation();
3922 dataUserlist[counter][8] = actual.getPhoneNo();
3923 dataUserlist[counter][9] = actual.getEmail();
3924 counter++;
3925 }
3926 }
3927 /**
3928 * table containing all the user data
3929 */
3930 adminArticleTable = new JTable(dataUserlist,
3931 columnNamesUserlist);
3932 adminArticleTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
3933 adminArticleTable.setAutoCreateRowSorter(true);
3934 adminArticleTableScrollPane.setViewportView(adminArticleTable);
3935 }
3936 });
3937 adminControlsPanel.add(btnShowUsers);
3938
3939 /**
3940 * shows all messages entered in the system
3941 */
3942 btnShowAllMessages = new JButton(Messages.getString("GUI.ShowAllMsgs0")); //$NON-NLS-1$
3943 btnShowAllMessages.addMouseListener(new MouseAdapter() {
3944 @Override
3945 public void mouseClicked(MouseEvent arg0) {
3946 execute("SHOW MESSAGES"); //$NON-NLS-1$
3947 String[] columnNamesMessagelist = { Messages.getString("GUI.to0"), Messages.getString("GUI.sendDate0"), Messages.getString("GUI.Title0"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
3948 Messages.getString("GUI.MessageContent") }; //$NON-NLS-1$
3949
3950 Object[][] dataMessagelist = new Object[messageList.size()][columnNamesMessagelist.length];
3951
3952 // if messages exist, show them
3953 if (messageList.size() != 0) {
3954 int counter = 0;
3955 Iterator<Message> it = messageList.iterator();
3956 while (it.hasNext()) {
3957 Message actual = it.next();
3958 dataMessagelist[counter][0] = actual.getReceiver()
3959 .getUsername();
3960 dataMessagelist[counter][1] = gregorianToString(actual
3961 .getSendDate(), "short"); //$NON-NLS-1$
3962 dataMessagelist[counter][2] = actual.getTitle();
3963 dataMessagelist[counter][3] = actual.getMsgText();
3964 counter++;
3965 }
3966 }
3967 /**
3968 * table containing all the messages
3969 */
3970 adminArticleTable = new JTable(dataMessagelist,
3971 columnNamesMessagelist);
3972 adminArticleTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
3973 adminArticleTable.setAutoCreateRowSorter(true);
3974 adminArticleTableScrollPane.setViewportView(adminArticleTable);
3975 }
3976 });
3977 adminControlsPanel.add(btnShowAllMessages);
3978
3979 /**
3980 * shows all the articles entered by the user entered in
3981 * txtUsernameToEdit
3982 */
3983 btnShowArticles = new JButton(Messages.getString("GUI.showArticlesByUser")); //$NON-NLS-1$
3984 btnShowArticles.addMouseListener(new MouseAdapter() {
3985 @Override
3986 public void mouseClicked(MouseEvent arg0) {
3987 String[] columnNamesArticleListAdmin = { Messages.getString("GUI.ArticleNo0"), Messages.getString("GUI.Title01"), //$NON-NLS-1$ //$NON-NLS-2$
3988 Messages.getString("GUI.decription0"), Messages.getString("GUI.currentPrice01"), Messages.getString("GUI.TimeLeft01"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
3989 Messages.getString("GUI.VendorName") }; //$NON-NLS-1$
3990
3991 String articlesByUser = txtUsernameToEdit.getText();
3992 if (checkForMalformedValues(articlesByUser, Messages.getString("GUI.UserName0"))) { //$NON-NLS-1$
3993 execute("LIST USER " + articlesByUser); //$NON-NLS-1$
3994 Object[][] data = new Object[articleList.size()][6];
3995 if (articleList.size() != 0) {
3996 // counter to prevent running out of array bounds
3997 int counter = 0;
3998 // first the salesitems
3999 Iterator<Article> it = articleList.iterator();
4000 while (it.hasNext()) {
4001 Object actual = it.next();
4002
4003 if (actual.getClass().getSimpleName().equals(
4004 "SalesItem")) { //$NON-NLS-1$
4005 data[counter][0] = ((SalesItem) actual)
4006 .getArticleNo();
4007 data[counter][1] = ((SalesItem) actual)
4008 .getTitle();
4009 data[counter][2] = ((SalesItem) actual)
4010 .getDescription();
4011 data[counter][3] = ((SalesItem) actual)
4012 .getPrice();
4013 data[counter][4] = ""; //$NON-NLS-1$
4014 data[counter][5] = ((SalesItem) actual)
4015 .getVendor();
4016 counter++;
4017 }
4018 }
4019
4020 // then the auction items
4021 Iterator<Article> it2 = articleList.iterator();
4022 while (it2.hasNext()) {
4023 Object actual = it2.next();
4024
4025 if (actual.getClass().getSimpleName().equals(
4026 "AuctionArticle")) { //$NON-NLS-1$
4027 data[counter][0] = ((AuctionArticle) actual)
4028 .getArticleNo();
4029 data[counter][1] = ((AuctionArticle) actual)
4030 .getTitle();
4031 data[counter][2] = ((AuctionArticle) actual)
4032 .getDescription();
4033
4034 //if the minbiddingprice is higher than the currentmaxbid the minbidding price is shown
4035 //this should ONLY be the case if there is no bid yet. then the currentmaxbid is 0.00
4036 if( ((AuctionArticle) actual).getMinBiddingPrice() > ((AuctionArticle) actual).getCurrentMaxBid() ){
4037 data[counter][3] = ((AuctionArticle) actual).getMinBiddingPrice();
4038
4039 //if the currentmaxbid is higher than the minbiddingprice show the currentmax bid
4040 }else{
4041 data[counter][3] = ((AuctionArticle) actual)
4042 .getCurrentMaxBid();
4043 }
4044
4045 data[counter][4] = dateDifferenceToString(((AuctionArticle) actual)
4046 .getAuctionEnd());
4047 data[counter][5] = ((AuctionArticle) actual)
4048 .getVendor();
4049 counter++;
4050 }
4051 }
4052 /**
4053 * table containing all the article data
4054 */
4055 adminArticleTable = new JTable(data,
4056 columnNamesArticleListAdmin);
4057 adminArticleTable
4058 .setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
4059 adminArticleTable.setAutoCreateRowSorter(true);
4060 adminArticleTableScrollPane
4061 .setViewportView(adminArticleTable);
4062 }
4063 }
4064 }
4065 });
4066 adminControlsPanel.add(btnShowArticles);
4067
4068 /**
4069 * east side of admincontrolpanel
4070 */
4071 adminControlsPanel2 = new JPanel();
4072 adminPanel.add(adminControlsPanel2, BorderLayout.EAST);
4073
4074 /**
4075 * deletes the article selected from the article table
4076 */
4077 btnDeleteArticle = new JButton(Messages.getString("GUI.DeleteSelectedArticle")); //$NON-NLS-1$
4078 btnDeleteArticle.addMouseListener(new MouseAdapter() {
4079 @Override
4080 public void mouseClicked(MouseEvent arg0) {
4081 // hardcoded column 0 because articleNo is always in column 0
4082 int articleNoToBeDeleted = (Integer) adminArticleTable
4083 .getValueAt(adminArticleTable.getSelectedRow(), 0);
4084
4085 execute("DELETE ARTICLE " + articleNoToBeDeleted); //$NON-NLS-1$
4086
4087 if (deleteArticleBool) {
4088 JOptionPane.showMessageDialog(null, Messages.getString("GUI.Article04") //$NON-NLS-1$
4089 + articleNoToBeDeleted + Messages.getString("GUI.successfullyDeleted"), //$NON-NLS-1$
4090 Messages.getString("GUI.ArticleDelte01"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
4091
4092 } else if (!deleteArticleBool) {
4093 JOptionPane.showMessageDialog(null, Messages.getString("GUI.Article711") //$NON-NLS-1$
4094 + articleNoToBeDeleted + Messages.getString("GUI.CouldntDeleted712"), //$NON-NLS-1$
4095 Messages.getString("GUI.ArticleFailed713"), //$NON-NLS-1$
4096 JOptionPane.WARNING_MESSAGE);
4097 }
4098
4099 }
4100 });
4101 adminControlsPanel2.add(btnDeleteArticle);
4102
4103 /**
4104 * scroll panel for adminArticleTable
4105 */
4106 adminArticleTableScrollPane = new JScrollPane();
4107 adminPanel.add(adminArticleTableScrollPane, BorderLayout.CENTER);
4108
4109 // remove sell tab
4110 tabbedPane.removeTabAt(1);
4111 // remove message tab
4112 tabbedPane.removeTabAt(1);
4113 // remove usercontrolcenter tab
4114 tabbedPane.removeTabAt(1);
4115 // hide article details in buy tab until a user logs in
4116 articleDetailsPanel.setVisible(false);
4117 btnShowArticleDetails.setVisible(false);
4118 }
4119}