Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @author Marcel Bieler
- */
- package userInterface;
- import java.awt.BorderLayout;
- import java.awt.EventQueue;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import java.io.*;
- import java.net.*;
- import java.util.*;
- import javax.swing.*;
- import com.jgoodies.forms.factories.FormFactory;
- import com.jgoodies.forms.layout.ColumnSpec;
- import com.jgoodies.forms.layout.FormLayout;
- import com.jgoodies.forms.layout.RowSpec;
- import appLogic.Article;
- import appLogic.AuctionArticle;
- import appLogic.Bid;
- import appLogic.Category;
- import appLogic.Message;
- import appLogic.SalesItem;
- import appLogic.User;
- import appLogicAccess.MyTableModel;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import javax.swing.event.ListSelectionListener;
- import javax.swing.event.ListSelectionEvent;
- import javax.swing.table.TableColumn;
- import javax.swing.table.TableModel;
- public class GUI {
- private ArrayList<Article> articleList = new ArrayList<Article>();
- private ArrayList<User> userList = new ArrayList<User>();
- private ArrayList<Message> messageList = new ArrayList<Message>();
- private ArrayList<Category> categoryList = new ArrayList<Category>();
- private ArrayList<Category> changeCategoryList = new ArrayList<Category>();
- private Article editArticle;
- private boolean loginBool;
- private boolean regBool;
- private boolean changeBool;
- private boolean deleteBool;
- private boolean setNewPrice;
- private boolean changeSoldFlagBool;
- private boolean buyBool;
- private boolean bidBool;
- private boolean lockBool;
- private boolean unlockBool;
- private boolean deleteArticleBool;
- private double currentlyHightestBidOnArticle;
- private int newSetArticleNo = -1;
- private ObjectOutputStream oos = null;
- private ObjectInputStream ois = null;
- private Socket socket = null;
- private String usernameTempSaved = null;
- private String befehl = null;
- private String antwort = null;
- private DefaultComboBoxModel categoryDataModel;
- private DefaultListModel currentCategorySelectionListModel;
- private DefaultListModel currentArticleCategoriesListModel;
- private DefaultListModel categoriesListModel;
- private JButton btnLogin;
- private JButton btnLogout;
- private JButton btnRegister;
- private JButton btnAddCategory;
- private JButton btnAddNewCategory;
- private JButton btnInsertArticle;
- private JButton btnRemoveSelectedCategory;
- private JButton editArticleAddCategoryButton;
- private JButton changeArticleDataAddNewCategoryButton;
- private JButton btnSetSelectedArticle;
- private JButton btnDeleteSelectedArticle;
- private JButton btnSearch;
- private JButton btnRefreshCategories;
- private JButton btnBuyArticle;
- private JButton btnBidOnArticle;
- private JButton btnChangeBid;
- private JButton btnShowArticleDetails;
- //button will most likely be deleted
- // private JButton btnShowSelectedCategory;
- private JButton btnUpdateArticleList;
- private JButton btnEditSelectedArticle;
- private JButton btnSetNewPrice;
- private JButton btnAddToDescription;
- private JButton btnShowMessages;
- private JButton btnHideOldMessages;
- private JButton btnChangeOk;
- private JButton changeArticleDataRemoveSelectedCategoryButton;
- private JButton btnAufDeutschBitte;
- private JButton btnDelete;
- private JButton btnLock;
- private JButton btnUnlock;
- private JButton btnShowArticles;
- private JButton btnShowUsers;
- private JButton btnShowAllMessages;
- private JButton btnDeleteArticle;
- private JCheckBox chckbxShowPhonenoOn;
- private JCheckBox chckbxShowEmailOn;
- private JComboBox comboBoxChangeUserdata;
- private JComboBox comboBox;
- private JComboBox categorySelectionComboBox;
- private JComboBox editArticleCategorySelectionComboBox;
- private JComboBox searchMethodSelectionComboBox;
- private JFrame frame;
- private JLabel lblTitle;
- private JLabel lblCurrentPrice;
- private JLabel lblAuctionEnd;
- private JLabel lblDescription;
- private JLabel lblArticleTitleHere;
- private JLabel lblCurrentPriceHere;
- private JLabel lblAuctionEndAnd;
- private JLabel lblArticleno;
- private JLabel lblSoldBy;
- private JLabel lblPhoneno;
- private JLabel lblEmail;
- private JLabel lblNoOfBids;
- private JLabel lblDisplayNoOfBids;
- private JLabel lblArticlenoHere;
- private JLabel lblVendorNameHere;
- private JLabel lblPhonenoHere;
- private JLabel lblEmailHere;
- private JLabel lblArticlesInSelected;
- private JLabel lblYourMaxBid;
- private JLabel lblMaxBidHere;
- private JLabel lblChange;
- private JLabel lblTo;
- private JLabel lblFormatYymmdd;
- private JLabel lblSelectedCategories;
- private JLabel lblMultiplesOf;
- private JLabel changeArticleDataSelectedCategoriesLabel;
- private JLabel changeSuccessLabel;
- private JLabel welcomeLabel;
- private JList currentCategorySelectionList;
- private JList currentArticleCategoriesList;
- private JList categoryListBuyTab;
- private JPanel adminPanel;
- private JPanel adminControlsPanel;
- private JPanel showMyArticlesPanel;
- private JPanel articleDetailsPanel;
- private JPanel buyTabPanel;
- private JPanel sellTabPanel;
- private JPanel messagePanel;
- private JPanel userControlCenterPanel;
- private JPanel adminControlsPanel2;
- private JPanel loginPanel;
- private JScrollPane articleDescriptionTextAreaScrollPane;
- private JScrollPane currentCategorySelectionListScrollPane;
- private JScrollPane showMyArticlesTableScrollPane;
- private JScrollPane txtrCurrentDescriptionScrollPane;
- private JScrollPane addToCurrentDescriptionScrollPane;
- private JScrollPane currentArticleCategoriesListScrollPane;
- private JScrollPane messageTableScrollPane;
- private JScrollPane categoryListBuyTabScrollPane;
- private JScrollPane articleTableBuyTabScrollPane;
- private JScrollPane articleDescriptionTextAreaBuyTabScrollPane;
- private JScrollPane adminArticleTableScrollPane;
- private JTabbedPane tabbedPane;
- private JTable showMyArticlesTable;
- private JTable messageTable;
- private JTable articleTableBuyTab;
- private JTable adminArticleTable;
- private JTextArea articleDescriptionTextArea;
- private JTextArea txtrCurrentDescription;
- private JTextArea txtrAddToCurrentDescription;
- private JTextArea articleDescriptionTextAreaBuyTab;
- private JTextField txtUsernameToEdit;
- private JTextField txtUsername;
- private JTextField txtPassword;
- private JTextField txtArticleTitle;
- private JTextField txtChangeNewValue;
- private JTextField txtNewCategory;
- private JTextField txtPrice;
- private JTextField txtAuctionEndDate;
- private JTextField changeArticleDataNewCategoryTextField;
- private JTextField changeArticleDataChangePriceTextField;
- private JTextField txtEnterSearchTerm;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- GUI window = new GUI();
- window.frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the application.
- *
- * @throws Exception
- */
- public GUI() {
- Messages.changeLanguage();
- initialize();
- }
- /**
- * connects to the server. ip is hardcoded. first creates a new socket and
- * then opens an objectinputstream and an objectoutputstream
- */
- public void connectToServer() {
- byte[] addr = new byte[4];
- addr[0] = (byte) 172;
- addr[1] = (byte) 20;
- addr[2] = (byte) 10;
- addr[3] = (byte) 2;
- InetAddress host;
- try {
- host = InetAddress.getByAddress(addr);
- socket = new Socket(host.getHostName(), 1234);
- oos = new ObjectOutputStream(socket.getOutputStream());
- ois = new ObjectInputStream(socket.getInputStream());
- } catch (UnknownHostException e1) {
- JOptionPane
- .showMessageDialog(
- null,
- Messages.getString("GUI.FailedToConnect"), //$NON-NLS-1$
- Messages.getString("GUI.ConnectionProblem"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
- } catch (IOException e) {
- JOptionPane
- .showMessageDialog(
- null,
- Messages.getString("GUI.FailedToConnect2"), //$NON-NLS-1$
- Messages.getString("GUI.ConnectionProblem2"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
- }
- }
- /**
- * converts a time, represented by a gregoriancalendar, to a string that
- * indicated the remaining time from now (systemtime) until the given date.
- *
- * @param cal2
- * the gregoriancalendar representation of an auction end date
- * @return a textual representation of the date difference from systemtime
- * until given calendar. format: XXT: HH : MM : SS
- */
- public String dateDifferenceToString(GregorianCalendar cal2) {
- GregorianCalendar cal1 = new GregorianCalendar();
- String timeString = new String();
- // cal1 = current time, cal1 = auction end
- long differenceSeconds = cal2.getTimeInMillis()
- - cal1.getTimeInMillis();
- int day = 0;
- int hour = 0;
- int minute = 0;
- int second = 0;
- long longday = 1000 * 60 * 60 * 24;
- long longhour = 1000 * 60 * 60;
- long longminute = 1000 * 60;
- long longsecond = 1000;
- while (differenceSeconds > 999) {
- if (differenceSeconds - longsecond >= 0) {
- if (differenceSeconds - longminute >= 0) {
- if (differenceSeconds - longhour >= 0) {
- if (differenceSeconds - longday >= 0) {
- day++;
- differenceSeconds -= longday;
- continue;
- }
- hour++;
- differenceSeconds -= longhour;
- continue;
- }
- minute++;
- differenceSeconds -= longminute;
- continue;
- }
- second++;
- differenceSeconds -= longsecond;
- continue;
- }
- }
- // if 1000ms are left add a second
- if (differenceSeconds < 1000 && differenceSeconds > 499) {
- second++;
- }
- if (second >= 60) {
- minute++;
- second -= 60;
- if (minute >= 60) {
- hour++;
- minute -= 60;
- if (hour >= 24) {
- day++;
- hour -= 24;
- }
- }
- }
- String daystring;
- if (day > 9 && day < 100) {
- daystring = "0" + String.valueOf(day); //$NON-NLS-1$
- } else if (day < 10) {
- daystring = "00" + String.valueOf(day); //$NON-NLS-1$
- } else {
- daystring = String.valueOf(day);
- }
- String hourstring;
- if (hour > 9) {
- hourstring = String.valueOf(hour);
- } else {
- hourstring = "0" + String.valueOf(hour); //$NON-NLS-1$
- }
- String minutestring;
- if (minute > 9) {
- minutestring = String.valueOf(minute);
- } else {
- minutestring = "0" + String.valueOf(minute); //$NON-NLS-1$
- }
- String secondstring;
- if (second > 9) {
- secondstring = String.valueOf(second);
- } else {
- secondstring = "0" + String.valueOf(second); //$NON-NLS-1$
- }
- timeString = daystring + "d " + hourstring + "h " + minutestring + "m " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + secondstring + "s"; //$NON-NLS-1$
- return timeString;
- }
- /**
- * converts the given gregoriancalendar into a textual representation
- * (YY.MM.DD or YY.MM.DD HH:MM:SS) of the saved date.
- *
- * @param cal
- * the gregoriancalendar to be transformed into a String
- * @param method
- * decides if the return String represents the date with or
- * without time
- * @return String representation of input calendar
- */
- public String gregorianToString(GregorianCalendar cal, String method) {
- // year to string. cut first 2 digits. thanks crappy dateformat...
- String year = String.valueOf(cal.get(Calendar.YEAR)).substring(2);
- // month to string. if single digit add leading zero
- String month = new String();
- int intmonth = cal.get(Calendar.MONTH);
- // january is 0 so month+1 is needed
- intmonth++;
- if (intmonth < 10) {
- month = "0" + String.valueOf(intmonth); //$NON-NLS-1$
- } else {
- month = String.valueOf(intmonth);
- }
- // day to string. if single digit add leading zero
- String day = new String();
- int intday = cal.get(Calendar.DATE);
- if (intday < 10) {
- day = "0" + String.valueOf(intday); //$NON-NLS-1$
- } else {
- day = String.valueOf(intday);
- }
- // if the long version is needed
- if (method.equals("long")) { //$NON-NLS-1$
- String hour = new String();
- int conversionHour = cal.get(Calendar.HOUR_OF_DAY);
- if (conversionHour < 10) {
- hour = "0" + String.valueOf(conversionHour); //$NON-NLS-1$
- } else {
- hour = String.valueOf(conversionHour);
- }
- String minute = new String();
- int conversionMinute = cal.get(Calendar.MINUTE);
- if (conversionMinute < 10) {
- minute = "0" + String.valueOf(conversionMinute); //$NON-NLS-1$
- } else {
- minute = String.valueOf(conversionMinute);
- }
- String second = new String();
- int conversionSecond = cal.get(Calendar.SECOND);
- if (conversionSecond < 10) {
- second = "0" + String.valueOf(conversionSecond); //$NON-NLS-1$
- } else {
- second = String.valueOf(conversionSecond);
- }
- // join year, month, day, hour, minute and second
- String date = year + "." + month + "." + day + " " + hour + ":" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + minute + ":" + second; //$NON-NLS-1$
- return date;
- // if the long version is not required, take the short one
- } else {
- // join year, month and day
- String date = year + "." + month + "." + day; //$NON-NLS-1$ //$NON-NLS-2$
- return date;
- }
- }
- public void transmissionError(String cause) {
- JOptionPane.showMessageDialog(null, cause,
- Messages.getString("GUI.ThereWasAProblem"), //$NON-NLS-1$
- JOptionPane.WARNING_MESSAGE);
- }
- /**
- * analyzes the input command and then transfers it to the server, where it
- * is processed. then the return value sent by the server is saved.
- *
- * @param command
- * command to be executed
- */
- public void execute(String command) {
- try {
- if (command.startsWith("LOGIN ")) { //$NON-NLS-1$
- if (oos != null) {
- oos.writeObject(command);
- if ((Boolean) ois.readObject()) {
- Exception shouldNotHappen = (Exception) ois
- .readObject();
- transmissionError(shouldNotHappen.getMessage());
- loginBool = false;
- } else {
- loginBool = (Boolean) ois.readObject();
- }
- }
- } else if (command.startsWith("INSERT USER ")) { //$NON-NLS-1$
- if (oos != null) {
- oos.writeObject(command);
- if ((Boolean) ois.readObject()) {
- Exception shouldNotHappen = (Exception) ois
- .readObject();
- transmissionError(shouldNotHappen.getMessage());
- regBool = false;
- } else {
- regBool = (Boolean) ois.readObject();
- }
- }
- } else if (command.startsWith("CHANGE USER ")) { //$NON-NLS-1$
- if (oos != null) {
- oos.writeObject(command);
- if ((Boolean) ois.readObject()) {
- Exception shouldNotHappen = (Exception) ois
- .readObject();
- transmissionError(shouldNotHappen.getMessage());
- changeBool = false;
- } else {
- changeBool = (Boolean) ois.readObject();
- }
- }
- } else if (command.startsWith("DELETE USER")) { //$NON-NLS-1$
- if (oos != null) {
- oos.writeObject(command);
- if ((Boolean) ois.readObject()) {
- Exception shouldNotHappen = (Exception) ois
- .readObject();
- transmissionError(shouldNotHappen.getMessage());
- deleteBool = false;
- } else {
- deleteBool = (Boolean) ois.readObject();
- }
- }
- } else if (command.startsWith("LIST USER")) { //$NON-NLS-1$
- if (oos != null) {
- oos.writeObject(command);
- articleList = (ArrayList<Article>) ois.readObject();
- }
- } else if (command.startsWith("LOCK USER")) { //$NON-NLS-1$
- if (oos != null) {
- oos.writeObject(command);
- if ((Boolean) ois.readObject()) {
- Exception shouldNotHappen = (Exception) ois
- .readObject();
- transmissionError(shouldNotHappen.getMessage());
- lockBool = false;
- } else {
- lockBool = (Boolean) ois.readObject();
- }
- }
- } else if (command.startsWith("UNLOCK USER")) { //$NON-NLS-1$
- if (oos != null) {
- oos.writeObject(command);
- if ((Boolean) ois.readObject()) {
- Exception shouldNotHappen = (Exception) ois
- .readObject();
- transmissionError(shouldNotHappen.getMessage());
- unlockBool = false;
- } else {
- unlockBool = (Boolean) ois.readObject();
- }
- }
- } else if (command.startsWith("DELETE ARTICLE")) { //$NON-NLS-1$
- if (oos != null) {
- oos.writeObject(command);
- if ((Boolean) ois.readObject()) {
- Exception shouldNotHappen = (Exception) ois
- .readObject();
- transmissionError(shouldNotHappen.getMessage());
- deleteArticleBool = false;
- } else {
- deleteArticleBool = (Boolean) ois.readObject();
- }
- }
- } else if (command.startsWith("SHOW USERS")) { //$NON-NLS-1$
- if (oos != null) {
- oos.writeObject(command);
- userList = (ArrayList<User>) ois.readObject();
- }
- } else if (command.startsWith("SHOW MESSAGES")) { //$NON-NLS-1$
- if (oos != null) {
- oos.writeObject(command);
- // TODO empty messagelist is no error. have to change it
- // there was an error. create empty messagelist and show the
- // error
- if ((Boolean) ois.readObject()) {
- messageList = new ArrayList<Message>();
- Exception shouldNotHappen = (Exception) ois
- .readObject();
- //TODO wegmachen wenn der fehler nicht mehr fliegt
- // transmissionError(shouldNotHappen.getMessage());
- // there was no error. proceed as planned
- } else {
- messageList = (ArrayList<Message>) ois.readObject();
- }
- }
- } else if (command.startsWith("SHOW CATEGORIES")) { //$NON-NLS-1$
- if (oos != null) {
- oos.writeObject(command);
- categoryList = (ArrayList<Category>) ois.readObject();
- }
- } else if (command.startsWith("INSERT SALE")) { //$NON-NLS-1$
- if (oos != null) {
- oos.writeObject(command);
- if ((Boolean) ois.readObject()) {
- Exception shouldNotHappen = (Exception) ois
- .readObject();
- transmissionError(shouldNotHappen.getMessage());
- newSetArticleNo = -1;
- } else {
- newSetArticleNo = (Integer) ois.readObject();
- }
- }
- } else if (command.startsWith("INSERT AUCTION")) { //$NON-NLS-1$
- if (oos != null) {
- oos.writeObject(command);
- if ((Boolean) ois.readObject()) {
- Exception shouldNotHappen = (Exception) ois
- .readObject();
- transmissionError(shouldNotHappen.getMessage());
- newSetArticleNo = -1;
- } else {
- newSetArticleNo = (Integer) ois.readObject();
- }
- }
- } else if (command.startsWith("ADD DESCRIPTION")) { //$NON-NLS-1$
- if (oos != null) {
- oos.writeObject(command);
- // there was an error. show it
- if ((Boolean) ois.readObject()) {
- Exception shouldNotHappen = (Exception) ois
- .readObject();
- transmissionError(shouldNotHappen.getMessage());
- }
- // nothing else because there is no return value
- }
- } else if (command.startsWith("ADD CATEGORY")) { //$NON-NLS-1$
- if (oos != null) {
- oos.writeObject(command);
- // there was an error. show it
- if ((Boolean) ois.readObject()) {
- Exception shouldNotHappen = (Exception) ois
- .readObject();
- transmissionError(shouldNotHappen.getMessage());
- }
- // nothing else because there is no return value
- }
- } else if (command.startsWith("SHOW PHONE")) { //$NON-NLS-1$
- if (oos != null) {
- oos.writeObject(command);
- // there was an error. show it
- if ((Boolean) ois.readObject()) {
- Exception shouldNotHappen = (Exception) ois
- .readObject();
- transmissionError(shouldNotHappen.getMessage());
- }
- // nothing else because there is no return value
- }
- } else if (command.startsWith("SHOW EMAIL")) { //$NON-NLS-1$
- if (oos != null) {
- oos.writeObject(command);
- // there was an error. show it
- if ((Boolean) ois.readObject()) {
- Exception shouldNotHappen = (Exception) ois
- .readObject();
- transmissionError(shouldNotHappen.getMessage());
- }
- // nothing else because there is no return value
- }
- } else if (command.startsWith("SHOW ARTICLE")) { //$NON-NLS-1$
- if (oos != null) {
- oos.writeObject(command);
- if ((Boolean) ois.readObject()) {
- Exception shouldNotHappen = (Exception) ois
- .readObject();
- transmissionError(shouldNotHappen.getMessage());
- editArticle = null;
- } else {
- editArticle = (Article) ois.readObject();
- }
- }
- } else if (command.startsWith("DELETE CATEGORY")) { //$NON-NLS-1$
- if (oos != null) {
- oos.writeObject(command);
- if ((Boolean) ois.readObject()) {
- Exception shouldNotHappen = (Exception) ois
- .readObject();
- transmissionError(shouldNotHappen.getMessage());
- }
- // nothing else because there is no return value
- }
- } else if (command.startsWith("REMOVE OLDMESSAGES")) { //$NON-NLS-1$
- if (oos != null) {
- oos.writeObject(command);
- if ((Boolean) ois.readObject()) {
- Exception shouldNotHappen = (Exception) ois
- .readObject();
- transmissionError(shouldNotHappen.getMessage());
- }
- // nothing else because there is no return value
- }
- } else if (command.startsWith("SET PRICE")) { //$NON-NLS-1$
- if (oos != null) {
- oos.writeObject(command);
- if ((Boolean) ois.readObject()) {
- Exception shouldNotHappen = (Exception) ois
- .readObject();
- transmissionError(shouldNotHappen.getMessage());
- setNewPrice = false;
- }else{
- setNewPrice = (Boolean) ois.readObject();
- }
- }
- } else if (command.startsWith("UNSOLD")) { //$NON-NLS-1$
- if (oos != null) {
- oos.writeObject(command);
- if ((Boolean) ois.readObject()) {
- Exception shouldNotHappen = (Exception) ois
- .readObject();
- transmissionError(shouldNotHappen.getMessage());
- changeSoldFlagBool = false;
- }else{
- changeSoldFlagBool = (Boolean) ois.readObject();
- }
- }
- } else if (command.startsWith("CHANGE AUCTIONEND")) { //$NON-NLS-1$
- if (oos != null) {
- oos.writeObject(command);
- if ((Boolean) ois.readObject()) {
- Exception shouldNotHappen = (Exception) ois
- .readObject();
- transmissionError(shouldNotHappen.getMessage());
- // nothing because no return is expected
- }
- // nothing else because no return is expected
- }
- } else if (command.startsWith("LIST CATEGORY")) { //$NON-NLS-1$
- if (oos != null) {
- oos.writeObject(command);
- if ((Boolean) ois.readObject()) {
- Exception shouldNotHappen = (Exception) ois
- .readObject();
- transmissionError(shouldNotHappen.getMessage());
- //create an empty articlelist to avoid busting the programm because of a non existing list
- articleList = new ArrayList<Article>();
- }else{
- articleList = (ArrayList<Article>) ois.readObject();
- }
- }
- } else if (command.startsWith("BUY")) { //$NON-NLS-1$
- if (oos != null) {
- oos.writeObject(command);
- if ((Boolean) ois.readObject()) {
- Exception shouldNotHappen = (Exception) ois
- .readObject();
- transmissionError(shouldNotHappen.getMessage());
- buyBool = false;
- } else {
- buyBool = (Boolean) ois.readObject();
- }
- }
- } else if (command.startsWith("BID")) { //$NON-NLS-1$
- if (oos != null) {
- oos.writeObject(command);
- if ((Boolean) ois.readObject()) {
- Exception shouldNotHappen = (Exception) ois
- .readObject();
- transmissionError(shouldNotHappen.getMessage());
- bidBool = false;
- } else {
- bidBool = (Boolean) ois.readObject();
- }
- }
- } else if (command.startsWith("SEARCH")) { //$NON-NLS-1$
- if (oos != null) {
- oos.writeObject(command);
- articleList = (ArrayList<Article>) ois.readObject();
- }
- } else if (command.startsWith("LOGOUT")) { //$NON-NLS-1$
- if (oos != null) {
- oos.writeObject(command);
- socket = null;
- ois = null;
- oos = null;
- }
- }
- } catch (IOException e) {
- JOptionPane
- .showMessageDialog(
- null,
- Messages.getString("GUI.FailedToConnect3"), //$NON-NLS-1$
- Messages.getString("GUI.ConnectionProblem3"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
- } catch (ClassNotFoundException e) {
- JOptionPane
- .showMessageDialog(
- null,
- Messages.getString("GUI.FailedToConnect4"), //$NON-NLS-1$
- Messages.getString("GUI.ConnectionProblem4"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
- }
- }
- /**
- *
- * @param input
- * String to be checked
- * @param type
- * format to Check
- * @return false if input is malformed, true if input is ok
- */
- public boolean checkForMalformedValues(String input, String type) {
- if (type.equals("username")) { //$NON-NLS-1$
- if (input.equals("")) { //$NON-NLS-1$
- JOptionPane
- .showMessageDialog(
- null,
- Messages.getString("GUI.NoUsername"), //$NON-NLS-1$
- Messages.getString("GUI.NoUsernameEntered"), //$NON-NLS-1$
- JOptionPane.WARNING_MESSAGE);
- return false;
- }
- if (input.contains(" ")) { //$NON-NLS-1$
- JOptionPane
- .showMessageDialog(
- null,
- Messages.getString("GUI.UsernameContainsA"), //$NON-NLS-1$
- Messages.getString("GUI.MalformedUsername"), //$NON-NLS-1$
- JOptionPane.WARNING_MESSAGE);
- return false;
- }
- } else if (type.equals("password")) { //$NON-NLS-1$
- if (input.equals("")) { //$NON-NLS-1$
- JOptionPane
- .showMessageDialog(
- null,
- Messages.getString("GUI.NoPasswordEnteredPlease"), //$NON-NLS-1$
- Messages.getString("GUI.NoPasswordEntered"), //$NON-NLS-1$
- JOptionPane.WARNING_MESSAGE);
- return false;
- }
- if (input.contains(" ")) { //$NON-NLS-1$
- JOptionPane
- .showMessageDialog(
- null,
- Messages.getString("GUI.PasswordContains"), //$NON-NLS-1$
- Messages.getString("GUI.MalformedPw"), //$NON-NLS-1$
- JOptionPane.WARNING_MESSAGE);
- return false;
- }
- } else if (type.equals("dateofbirth")) { //$NON-NLS-1$
- if (input.equals("")) { //$NON-NLS-1$
- JOptionPane
- .showMessageDialog(
- null,
- Messages.getString("GUI.NoDateOfBirth"), //$NON-NLS-1$
- Messages.getString("GUI.NoDateOfBirthEntered"), //$NON-NLS-1$
- JOptionPane.WARNING_MESSAGE);
- return false;
- }
- if (input.length() != 6 || !input.matches("\\d*")) { //$NON-NLS-1$
- JOptionPane.showMessageDialog(null,
- Messages.getString("GUI.DateOfBirthIsMalformed"), //$NON-NLS-1$
- Messages.getString("GUI.MalformedDateOfBirth"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
- return false;
- }
- } else if (type.equals("auctionend")) { //$NON-NLS-1$
- if (input.equals("") || input.equals("auction end date")) { //$NON-NLS-1$ //$NON-NLS-2$
- JOptionPane
- .showMessageDialog(
- null,
- Messages.getString("GUI.NoAuctionEndEntered"), //$NON-NLS-1$
- Messages.getString("GUI.NoAuctionEndEntered2"), //$NON-NLS-1$
- JOptionPane.WARNING_MESSAGE);
- return false;
- }
- if (input.length() != 13) {
- return false;
- }
- if (input.contains("-")) { //$NON-NLS-1$
- String[] tempStringArray = input.split("-"); //$NON-NLS-1$
- if (!tempStringArray[0].matches("\\d*") //$NON-NLS-1$
- || !tempStringArray[1].matches("\\d*")) { //$NON-NLS-1$
- JOptionPane.showMessageDialog(null,
- Messages.getString("GUI.AuctionEndIsMalformed"), //$NON-NLS-1$
- Messages.getString("GUI.MalformedActionEnd"), //$NON-NLS-1$
- JOptionPane.WARNING_MESSAGE);
- return false;
- }
- }
- } else if (type.equals("zip")) { //$NON-NLS-1$
- if (input.equals("")) { //$NON-NLS-1$
- JOptionPane.showMessageDialog(null,
- Messages.getString("GUI.NoZipEnteredPlease"), //$NON-NLS-1$
- Messages.getString("GUI.NoZipEntered"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
- return false;
- }
- if (!input.matches("\\d*")) { //$NON-NLS-1$
- JOptionPane.showMessageDialog(null,
- Messages.getString("GUI.ZipIsMalformed"), Messages.getString("GUI.MalformedZip"), //$NON-NLS-1$ //$NON-NLS-2$
- JOptionPane.WARNING_MESSAGE);
- return false;
- }
- } else if (type.equals("phoneno")) { //$NON-NLS-1$
- if (input.equals("")) { //$NON-NLS-1$
- JOptionPane
- .showMessageDialog(
- null,
- Messages.getString("GUI.NoPhoneNumberEntered"), //$NON-NLS-1$
- Messages.getString("GUI.NoPhoneNumberEntered2"), //$NON-NLS-1$
- JOptionPane.WARNING_MESSAGE);
- return false;
- }
- if (input.contains("-")) { //$NON-NLS-1$
- String[] tempStringArray = input.split("-"); //$NON-NLS-1$
- if (!tempStringArray[0].matches("\\d*") //$NON-NLS-1$
- || !tempStringArray[1].matches("\\d*")) { //$NON-NLS-1$
- // phoneno doesn't contain just digits
- JOptionPane.showMessageDialog(null,
- Messages.getString("GUI.PhoneNumberIsMalformed"), //$NON-NLS-1$
- Messages.getString("GUI.MalformedPhoneNo"), //$NON-NLS-1$
- JOptionPane.WARNING_MESSAGE);
- return false;
- }
- } else {
- // no - included in phoneno
- JOptionPane.showMessageDialog(null,
- Messages.getString("GUI.PhoneNoIs"), //$NON-NLS-1$
- Messages.getString("GUI.MalformedPhone"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
- return false;
- }
- } else if (type.equals("price")) { //$NON-NLS-1$
- if (input.equals("price") || input.equals("")) { //$NON-NLS-1$ //$NON-NLS-2$
- JOptionPane.showMessageDialog(null, Messages.getString("GUI.PleaseEnterAPrice"), //$NON-NLS-1$
- Messages.getString("GUI.NoPriceEntered"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
- return false;
- }
- try {
- double check = Double.parseDouble(input);
- if (check % 0.5 != 0) {
- JOptionPane
- .showMessageDialog(
- null,
- Messages.getString("GUI.ThePriceHasToBe"), //$NON-NLS-1$
- Messages.getString("GUI.MalformedPrice"), //$NON-NLS-1$
- JOptionPane.WARNING_MESSAGE);
- return false;
- }
- } catch (NumberFormatException e) {
- JOptionPane
- .showMessageDialog(
- null,
- Messages.getString("GUI.ThePriceHasTo"), //$NON-NLS-1$
- Messages.getString("GUI.MalformedPrice2"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
- return false;
- }
- } else if (type.equals("category")) { //$NON-NLS-1$
- if (input.contains(" ")) { //$NON-NLS-1$
- JOptionPane
- .showMessageDialog(
- null,
- Messages.getString("GUI.CategoriesMustNotContain"), //$NON-NLS-1$
- Messages.getString("GUI.MalformedCategory"), //$NON-NLS-1$
- JOptionPane.WARNING_MESSAGE);
- return false;
- }
- } else if (type.equals("email")) { //$NON-NLS-1$
- if (input.equals("")) { //$NON-NLS-1$
- JOptionPane
- .showMessageDialog(
- null,
- Messages.getString("GUI.NoE-mailAddress"), //$NON-NLS-1$
- Messages.getString("GUI.NoEMailAdrdressEntered1"), //$NON-NLS-1$
- JOptionPane.WARNING_MESSAGE);
- return false;
- }
- if (input.contains("@")) { //$NON-NLS-1$
- String[] emailArray = input.split("@"); //$NON-NLS-1$
- if (!emailArray[emailArray.length - 1].contains(".")) { //$NON-NLS-1$
- JOptionPane.showMessageDialog(null,
- Messages.getString("GUI.EmailAddressIs"), //$NON-NLS-1$
- Messages.getString("GUI.MalformedEmailAddress"), //$NON-NLS-1$
- JOptionPane.WARNING_MESSAGE);
- return false;
- }
- } else {
- JOptionPane
- .showMessageDialog(
- null,
- Messages.getString("GUI.EmailAddressIs2"), //$NON-NLS-1$
- Messages.getString("GUI.MalformedEmailAddress2"), //$NON-NLS-1$
- JOptionPane.WARNING_MESSAGE);
- return false;
- }
- }
- // no problems found? return true!
- return true;
- }
- /**
- * updates the category data represented by two comboboxes in the sell tab.
- * if no server connection is active it connects. if a connection is
- * available the client requests a categorylist from the server. the
- * categorylist is then convertet to an array of categorynames, which then
- * is added to the defaultcomboboxmodel
- *
- * @return DefaultComboBoxModel with updated category data
- */
- public DefaultComboBoxModel updateCategoryData() {
- if (socket == null) {
- connectToServer();
- execute("SHOW CATEGORIES"); //$NON-NLS-1$
- execute("LOGOUT"); //$NON-NLS-1$
- } else {
- execute("SHOW CATEGORIES"); //$NON-NLS-1$
- }
- String[] categoryData = new String[categoryList.size()];
- Iterator<Category> it = categoryList.iterator();
- if (categoryList.size() != 0) {
- int counter = 0;
- while (it.hasNext()) {
- Category actual = it.next();
- categoryData[counter] = actual.getCatName();
- counter++;
- }
- }
- DefaultComboBoxModel model = new DefaultComboBoxModel(categoryData);
- return model;
- }
- /**
- * Initialize the contents of the frame.
- */
- private void initialize() {
- frame = new JFrame("3,14159265bay"); //$NON-NLS-1$
- frame.setBounds(100, 100, 1100, 600);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.getContentPane().setLayout(
- new FormLayout(new ColumnSpec[] {
- FormFactory.RELATED_GAP_COLSPEC,
- ColumnSpec.decode("default:grow"), }, new RowSpec[] { //$NON-NLS-1$
- FormFactory.RELATED_GAP_ROWSPEC,
- RowSpec.decode("max(23dlu;default)"), //$NON-NLS-1$
- FormFactory.RELATED_GAP_ROWSPEC,
- RowSpec.decode("default:grow"), //$NON-NLS-1$
- FormFactory.RELATED_GAP_ROWSPEC,
- RowSpec.decode("default:grow"), })); //$NON-NLS-1$
- loginPanel = new JPanel();
- frame.getContentPane().add(loginPanel, "2, 2, fill, fill"); //$NON-NLS-1$
- welcomeLabel = new JLabel(""); //$NON-NLS-1$
- loginPanel.add(welcomeLabel);
- txtUsername = new JTextField();
- txtUsername.setText(Messages.getString("GUI.Username")); //$NON-NLS-1$
- txtUsername.setColumns(10);
- loginPanel.add(txtUsername);
- txtPassword = new JTextField();
- txtPassword.setText(Messages.getString("GUI.Password")); //$NON-NLS-1$
- txtPassword.setColumns(10);
- loginPanel.add(txtPassword);
- /**
- * takes the strings from txtUsername and txtPassword to log the user
- * in. therefore the login command is executed. after that the answer
- * from the server is processed. if the login was successful the
- * loginarea is set invisible and the logout button becomes visible.
- */
- btnLogin = new JButton(Messages.getString("GUI.Login")); //$NON-NLS-1$
- btnLogin.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- if (socket == null) {
- connectToServer();
- }
- execute("LOGIN " + txtUsername.getText() + " " //$NON-NLS-1$ //$NON-NLS-2$
- + txtPassword.getText());
- // save username for later use
- usernameTempSaved = txtUsername.getText();
- if (loginBool) {
- txtUsername.setVisible(false);
- txtPassword.setVisible(false);
- btnLogin.setVisible(false);
- btnLogout.setVisible(true);
- btnRegister.setVisible(false);
- welcomeLabel.setText(Messages.getString("GUI.Welcome") + usernameTempSaved); //$NON-NLS-1$
- // admin only gets the user control center with extra admin
- // panel
- if (usernameTempSaved.equals("Administrator")) {
- tabbedPane.removeAll();
- tabbedPane.addTab(Messages.getString("GUI.UserControlCenter"), null, //$NON-NLS-1$
- userControlCenterPanel, null);
- // admin can't change his userdata
- comboBoxChangeUserdata.setVisible(false);
- lblChange.setVisible(false);
- lblTo.setVisible(false);
- txtChangeNewValue.setVisible(false);
- btnChangeOk.setVisible(false);
- adminPanel.setVisible(true);
- // everyone else gets all tabs without admin panel
- } else {
- tabbedPane.removeAll();
- tabbedPane.addTab(Messages.getString("GUI.buy"), null, buyTabPanel, null); //$NON-NLS-1$
- tabbedPane.addTab(Messages.getString("GUI.sell"), null, sellTabPanel, null); //$NON-NLS-1$
- tabbedPane.addTab(Messages.getString("GUI.msgs"), null, messagePanel, null); //$NON-NLS-1$
- tabbedPane.addTab(Messages.getString("GUI.UCC"), null, //$NON-NLS-1$
- userControlCenterPanel, null);
- // user can change his userdata
- comboBoxChangeUserdata.setVisible(true);
- lblChange.setVisible(true);
- lblTo.setVisible(true);
- txtChangeNewValue.setVisible(true);
- btnChangeOk.setVisible(true);
- adminPanel.setVisible(false);
- //article details visible in buy tab
- articleDetailsPanel.setVisible(true);
- btnShowArticleDetails.setVisible(true);
- }
- // if login failed
- } else {
- JOptionPane.showMessageDialog(null,
- Messages.getString("GUI.PleaseEnterCorrectLogin"), Messages.getString("GUI.LoginFailed"), //$NON-NLS-1$ //$NON-NLS-2$
- JOptionPane.WARNING_MESSAGE);
- }
- // reset username and password text fields
- txtUsername.setText(Messages.getString("GUI.Username2")); //$NON-NLS-1$
- txtPassword.setText(Messages.getString("GUI.password")); //$NON-NLS-1$
- }
- });
- loginPanel.add(btnLogin);
- /**
- * executes the logout command and then resets the userinterface. login
- * panel becomes visible again.
- */
- btnLogout = new JButton(Messages.getString("GUI.Logout")); //$NON-NLS-1$
- btnLogout.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- txtUsername.setVisible(true);
- txtPassword.setVisible(true);
- btnLogin.setVisible(true);
- btnLogout.setVisible(false);
- welcomeLabel.setText(""); //$NON-NLS-1$
- btnRegister.setVisible(true);
- loginBool = false;
- usernameTempSaved = null;
- adminPanel.setVisible(false);
- // resetting elements in buy tab
- txtEnterSearchTerm.setText(Messages.getString("GUI.EnterSearchItem")); //$NON-NLS-1$
- lblArticleTitleHere.setText(""); //$NON-NLS-1$
- lblCurrentPriceHere.setText(""); //$NON-NLS-1$
- lblAuctionEndAnd.setText(""); //$NON-NLS-1$
- lblDisplayNoOfBids.setText(""); //$NON-NLS-1$
- articleDescriptionTextAreaBuyTab.setText(""); //$NON-NLS-1$
- lblArticlenoHere.setText(""); //$NON-NLS-1$
- lblVendorNameHere.setText(""); //$NON-NLS-1$
- lblPhonenoHere.setText(""); //$NON-NLS-1$
- lblEmailHere.setText(""); //$NON-NLS-1$
- lblMaxBidHere.setText(""); //$NON-NLS-1$
- // resetting elements in login panel
- txtUsername.setText(Messages.getString("GUI.Username3")); //$NON-NLS-1$
- txtPassword.setText(Messages.getString("GUI.Password2")); //$NON-NLS-1$
- //resetting elements in sell tab
- txtArticleTitle.setText(Messages.getString("GUI.ArticleTitle")); //$NON-NLS-1$
- articleDescriptionTextArea.setText(Messages.getString("GUI.ArticleDescription")); //$NON-NLS-1$
- txtNewCategory.setText(Messages.getString("GUI.newCategory")); //$NON-NLS-1$
- chckbxShowPhonenoOn.setSelected(false);
- chckbxShowEmailOn.setSelected(false);
- txtPrice.setText(Messages.getString("GUI.Price")); //$NON-NLS-1$
- txtAuctionEndDate.setText(Messages.getString("GUI.AuctionEndDate")); //$NON-NLS-1$
- txtrCurrentDescription.setText(""); //$NON-NLS-1$
- txtrAddToCurrentDescription.setText(""); //$NON-NLS-1$
- changeArticleDataNewCategoryTextField.setText(Messages.getString("GUI.newCategory2")); //$NON-NLS-1$
- changeArticleDataChangePriceTextField.setText(Messages.getString("GUI.Price2")); //$NON-NLS-1$
- // resetting elements in user control tab
- txtChangeNewValue.setText(""); //$NON-NLS-1$
- txtUsernameToEdit.setText(Messages.getString("GUI.UsernameToEdit")); //$NON-NLS-1$
- // resetting the article table in the buy tab
- Object[][] data = new Object[0][0];
- String[] columnNamesArticleTableBuyTab = { Messages.getString("GUI.title"), //$NON-NLS-1$
- Messages.getString("GUI.currentPrice"), Messages.getString("GUI.timeLeft") }; //$NON-NLS-1$ //$NON-NLS-2$
- articleTableBuyTab = new JTable(data,
- columnNamesArticleTableBuyTab);
- // resetting the article table in the sell tab
- Object[][] data2 = new Object[0][0];
- String[] columnNamesArticleListChangeArticle = { Messages.getString("GUI.ArticleNo"), //$NON-NLS-1$
- 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$
- Messages.getString("GUI.status") }; //$NON-NLS-1$
- showMyArticlesTable = new JTable(data2,
- columnNamesArticleListChangeArticle);
- tabbedPane.removeAll();
- tabbedPane.addTab(Messages.getString("GUI.buy1"), null, buyTabPanel, null); //$NON-NLS-1$
- // hide article details in buy tab until a user logs in
- articleDetailsPanel.setVisible(false);
- btnShowArticleDetails.setVisible(false);
- execute("LOGOUT"); //$NON-NLS-1$
- loginPanel.add(btnLogout);
- /**
- * opens a popup where user data can be entered to register a user.
- */
- btnRegister = new JButton(Messages.getString("GUI.register")); //$NON-NLS-1$
- btnRegister.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- JTextField txtRegUsername = new JTextField();
- JTextField txtRegPassword = new JTextField();
- JTextField txtRegLastname = new JTextField();
- JTextField txtRegFirstname = new JTextField();
- JTextField txtRegDateOfBirth = new JTextField();
- JTextField txtRegStreet = new JTextField();
- JTextField txtRegZip = new JTextField();
- JTextField txtRegLocation = new JTextField();
- JTextField txtRegPhoneNo = new JTextField();
- JTextField txtRegEmail = new JTextField();
- boolean sendFlag = true;
- Object[] registrationFields = {
- Messages.getString("GUI.Username(noSpace)"), //$NON-NLS-1$
- txtRegUsername,
- Messages.getString("GUI.Password(noSpace)"), //$NON-NLS-1$
- txtRegPassword, Messages.getString("GUI.LastName"), txtRegLastname, //$NON-NLS-1$
- Messages.getString("GUI.FirstName"), txtRegFirstname, //$NON-NLS-1$
- Messages.getString("GUI.DateOfBirth"), txtRegDateOfBirth, //$NON-NLS-1$
- Messages.getString("GUI.Street"), txtRegStreet, Messages.getString("GUI.ZIP"), txtRegZip, Messages.getString("GUI.Location"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- txtRegLocation,
- Messages.getString("GUI.Phoneno"), //$NON-NLS-1$
- txtRegPhoneNo, Messages.getString("GUI.Email"), txtRegEmail }; //$NON-NLS-1$
- JOptionPane registrationPane = new JOptionPane(
- registrationFields, JOptionPane.PLAIN_MESSAGE,
- JOptionPane.OK_CANCEL_OPTION);
- registrationPane.createDialog(null, "Register User") //$NON-NLS-1$
- .setVisible(true);
- String RegUsernameString = txtRegUsername.getText();
- String RegPasswordString = txtRegPassword.getText();
- String RegLastnameString = txtRegLastname.getText();
- String RegFirstnameString = txtRegFirstname.getText();
- String RegDateOfBirthString = txtRegDateOfBirth.getText();
- String RegStreetString = txtRegStreet.getText();
- String RegZipString = txtRegZip.getText();
- String RegLocationString = txtRegLocation.getText();
- String RegPhoneNoString = txtRegPhoneNo.getText();
- String RegEmailString = txtRegEmail.getText();
- // check username for malformation
- if (!checkForMalformedValues(RegUsernameString, "username")) { //$NON-NLS-1$
- sendFlag = false;
- }
- // check password for malformation
- if (!checkForMalformedValues(RegPasswordString, "password")) { //$NON-NLS-1$
- sendFlag = false;
- }
- // check date of birth for malformation
- if (!checkForMalformedValues(RegDateOfBirthString,
- "dateofbirth")) { //$NON-NLS-1$
- sendFlag = false;
- }
- // check zip for malformation
- if (!checkForMalformedValues(RegZipString, "zip")) { //$NON-NLS-1$
- sendFlag = false;
- }
- // check phoneno for malformation
- if (!checkForMalformedValues(RegPhoneNoString, "phoneno")) { //$NON-NLS-1$
- sendFlag = false;
- }
- // check email for malformation
- if (!checkForMalformedValues(RegEmailString, "email")) { //$NON-NLS-1$
- sendFlag = false;
- }
- // when no malformations were detected execute insert user
- if (sendFlag) {
- if (socket == null) {
- connectToServer();
- }
- execute("INSERT USER " + RegUsernameString + " " //$NON-NLS-1$ //$NON-NLS-2$
- + RegPasswordString + " " + "\"" //$NON-NLS-1$ //$NON-NLS-2$
- + RegLastnameString + "\"" + " " + "\"" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + RegFirstnameString + "\"" + " " //$NON-NLS-1$ //$NON-NLS-2$
- + RegDateOfBirthString + " " + "\"" //$NON-NLS-1$ //$NON-NLS-2$
- + RegStreetString + "\"" + " " + RegZipString + " " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + "\"" + RegLocationString + "\"" + " " + "\"" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + RegPhoneNoString + "\"" + " " + "\"" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + RegEmailString + "\""); //$NON-NLS-1$
- // if registration failed (username already taken)
- if (!regBool) {
- JOptionPane
- .showMessageDialog(
- null,
- Messages.getString("GUI.UsernameAlreadyTakenPlease"), //$NON-NLS-1$
- Messages.getString("GUI.UsernameAlreadyTaken"), //$NON-NLS-1$
- JOptionPane.WARNING_MESSAGE);
- }
- //
- if (regBool) {
- JOptionPane
- .showMessageDialog(
- null,
- "Congratulations. Your account has been created. You can now log in.",
- "User created",
- JOptionPane.WARNING_MESSAGE);
- }
- }
- }
- });
- loginPanel.add(btnRegister);
- /**
- * changes the language of the user interface between English and German
- */
- btnAufDeutschBitte = new JButton(Messages.getString("GUI.AufDeutschBitte")); //$NON-NLS-1$
- btnAufDeutschBitte.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- Messages.changeLanguage();
- // TODO @Marcel hier muss die GUI neu gestartet werden
- }
- });
- loginPanel.add(btnAufDeutschBitte);
- btnLogout.setVisible(false);
- /**
- * pane containing all the tabs
- */
- tabbedPane = new JTabbedPane(JTabbedPane.TOP);
- frame.getContentPane().add(tabbedPane, "2, 4, 1, 3"); //$NON-NLS-1$
- tabbedPane.setVisible(true);
- /**
- * the buy tab
- */
- buyTabPanel = new JPanel();
- tabbedPane.addTab(Messages.getString("GUI.Buy2"), null, buyTabPanel, null); //$NON-NLS-1$
- buyTabPanel.setLayout(new FormLayout(new ColumnSpec[] {
- FormFactory.RELATED_GAP_COLSPEC,
- ColumnSpec.decode("max(95dlu;min)"), //$NON-NLS-1$
- FormFactory.RELATED_GAP_COLSPEC,
- ColumnSpec.decode("55px"), //$NON-NLS-1$
- FormFactory.RELATED_GAP_COLSPEC,
- ColumnSpec.decode("80px"), //$NON-NLS-1$
- FormFactory.RELATED_GAP_COLSPEC,
- ColumnSpec.decode("310px"),
- FormFactory.RELATED_GAP_COLSPEC,
- ColumnSpec.decode("35px"),
- FormFactory.RELATED_GAP_COLSPEC,
- ColumnSpec.decode("330px"),
- FormFactory.RELATED_GAP_COLSPEC,
- FormFactory.DEFAULT_COLSPEC,},
- new RowSpec[] {
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- RowSpec.decode("default:grow"), //$NON-NLS-1$
- FormFactory.RELATED_GAP_ROWSPEC,
- RowSpec.decode("max(135dlu;default)"), //$NON-NLS-1$
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- RowSpec.decode("fill:max(80dlu;default):grow"),}));
- /**
- * textfield to enter a search term location: buy tab, left hand side
- */
- txtEnterSearchTerm = new JTextField();
- txtEnterSearchTerm.setText(Messages.getString("GUI.EnterSearchItem")); //$NON-NLS-1$
- buyTabPanel.add(txtEnterSearchTerm, "2, 2, fill, default"); //$NON-NLS-1$
- txtEnterSearchTerm.setColumns(10);
- /**
- * combobox to select the used search method location: buy tab, left
- * hand side
- */
- Object[] searchMethodsForComboBox = { Messages.getString("GUI.and"), Messages.getString("GUI.or") }; //$NON-NLS-1$ //$NON-NLS-2$
- searchMethodSelectionComboBox = new JComboBox(searchMethodsForComboBox);
- buyTabPanel.add(searchMethodSelectionComboBox, "4, 2, fill, default"); //$NON-NLS-1$
- /**
- * executes the search. takes the search term from txtEnterSearchTerm
- * and the search method from searchMethodSelectionComboBox and executes
- * a search. works if a user is logged in or not. location: buy tab,
- * left hand side
- */
- btnSearch = new JButton(Messages.getString("GUI.search")); //$NON-NLS-1$
- btnSearch.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- // works even if no user is logged in
- if (socket == null) {
- connectToServer();
- execute("SEARCH " //$NON-NLS-1$
- + searchMethodSelectionComboBox.getSelectedItem()
- + " \"" + txtEnterSearchTerm.getText() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
- execute("LOGOUT"); //$NON-NLS-1$
- } else {
- // gets all articles of selected category
- execute("SEARCH " //$NON-NLS-1$
- + searchMethodSelectionComboBox.getSelectedItem()
- + " \"" + txtEnterSearchTerm.getText() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
- }
- Iterator<Article> checkForSoldArticlesIterator = articleList
- .iterator();
- int numberOfSoldArticles = 0;
- while (checkForSoldArticlesIterator.hasNext()) {
- Article actual = checkForSoldArticlesIterator.next();
- if (actual.isSold()) {
- numberOfSoldArticles++;
- }
- }
- if (!articleList.isEmpty()) {
- // number of rows => number of articles minus the sold ones
- Object[][] data = new Object[articleList.size()
- - numberOfSoldArticles][4];
- String[] columnNamesArticleTableBuyTab = { Messages.getString("GUI.title3"), //$NON-NLS-1$
- Messages.getString("GUI.currentPrice2"), Messages.getString("GUI.TimeLeft3"), Messages.getString("GUI.ArticleNo2") }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- // counter to prevent running out of array bounds
- int counter = 0;
- // first the salesitems
- Iterator<Article> it = articleList.iterator();
- while (it.hasNext()) {
- Object actual = it.next();
- if (actual.getClass().getSimpleName().equals(
- "SalesItem")) { //$NON-NLS-1$
- // if article isn't sold add it to the list
- if (!((SalesItem) actual).isSold()) {
- data[counter][0] = ((SalesItem) actual)
- .getTitle();
- data[counter][1] = ((SalesItem) actual)
- .getPrice();
- data[counter][2] = ""; //$NON-NLS-1$
- data[counter][3] = ((SalesItem) actual)
- .getArticleNo();
- counter++;
- }
- }
- }
- // then the auction items
- Iterator<Article> it2 = articleList.iterator();
- while (it2.hasNext()) {
- Object actual = it2.next();
- if (actual.getClass().getSimpleName().equals(
- "AuctionArticle")) { //$NON-NLS-1$
- // if article isn't sold add it to the list
- if (!((AuctionArticle) actual).isSold()) {
- data[counter][0] = ((AuctionArticle) actual)
- .getTitle();
- data[counter][1] = ((AuctionArticle) actual)
- .getCurrentMaxBid();
- data[counter][2] = dateDifferenceToString(((AuctionArticle) actual)
- .getAuctionEnd());
- data[counter][3] = ((AuctionArticle) actual)
- .getArticleNo();
- counter++;
- }
- }
- }
- articleTableBuyTab = new JTable(new MyTableModel(columnNamesArticleTableBuyTab, data));
- articleTableBuyTab
- .setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
- articleTableBuyTab.setAutoCreateRowSorter(true);
- articleTableBuyTabScrollPane
- .setViewportView(articleTableBuyTab);
- // set column widths so that they fill the panel
- articleTableBuyTab.getColumnModel().getColumn(0)
- .setPreferredWidth(242);
- articleTableBuyTab.getColumnModel().getColumn(1)
- .setPreferredWidth(80);
- articleTableBuyTab.getColumnModel().getColumn(2)
- .setPreferredWidth(110);
- } else {
- JOptionPane
- .showMessageDialog(
- null,
- Messages.getString("GUI.YourSearchReturned0"), //$NON-NLS-1$
- Messages.getString("GUI.NoArticlesFound"), //$NON-NLS-1$
- JOptionPane.INFORMATION_MESSAGE);
- }
- ;
- buyTabPanel.add(btnSearch, "6, 2"); //$NON-NLS-1$
- /**
- * gets the categorylist from the server and adds it to the category
- * list location: buy tab, left hand side
- */
- btnRefreshCategories = new JButton(Messages.getString("GUI.RefreshCategories")); //$NON-NLS-1$
- btnRefreshCategories.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- // works even if no user is logged in
- if (socket == null) {
- connectToServer();
- execute("SHOW CATEGORIES"); //$NON-NLS-1$
- execute("LOGOUT"); //$NON-NLS-1$
- } else {
- // gets the categories
- execute("SHOW CATEGORIES"); //$NON-NLS-1$
- }
- // clear categorylist
- categoriesListModel.removeAllElements();
- Iterator<Category> it = categoryList.iterator();
- while (it.hasNext()) {
- Category actual = it.next();
- categoriesListModel.add(categoriesListModel.size(), actual
- .getCatName()
- + " (" + actual.getNumberOfUnsoldArticles() + ")");
- }
- }
- });
- buyTabPanel.add(btnRefreshCategories, "2, 6"); //$NON-NLS-1$
- lblArticlesInSelected = new JLabel(Messages.getString("GUI.ArticlesInSelectedC")); //$NON-NLS-1$
- buyTabPanel.add(lblArticlesInSelected, "4, 6, 5, 1"); //$NON-NLS-1$
- /**
- * panel containing all buttons and fields needed to buy an article
- */
- articleDetailsPanel = new JPanel();
- buyTabPanel.add(articleDetailsPanel, "10, 6, 3, 7, fill, fill"); //$NON-NLS-1$
- articleDetailsPanel.setLayout(new FormLayout(new ColumnSpec[] {
- FormFactory.RELATED_GAP_COLSPEC,
- ColumnSpec.decode("100px"),
- FormFactory.RELATED_GAP_COLSPEC,
- ColumnSpec.decode("240px"),},
- new RowSpec[] {
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- RowSpec.decode("75px"), //$NON-NLS-1$
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,}));
- /**
- * labels containing the title of the selected article
- */
- lblTitle = new JLabel("Title:"); //$NON-NLS-1$
- articleDetailsPanel.add(lblTitle, "2, 2, right, default"); //$NON-NLS-1$
- lblArticleTitleHere = new JLabel(""); //$NON-NLS-1$
- articleDetailsPanel.add(lblArticleTitleHere, "4, 2"); //$NON-NLS-1$
- /**
- * labels containing the current price/bid of the selected article
- */
- lblCurrentPrice = new JLabel("current price:"); //$NON-NLS-1$
- articleDetailsPanel.add(lblCurrentPrice, "2, 4, right, default"); //$NON-NLS-1$
- lblCurrentPriceHere = new JLabel(""); //$NON-NLS-1$
- articleDetailsPanel.add(lblCurrentPriceHere, "4, 4"); //$NON-NLS-1$
- /**
- * labels showing the time left until the auction end
- */
- lblAuctionEnd = new JLabel(Messages.getString("GUI.TimeLeft4")); //$NON-NLS-1$
- articleDetailsPanel.add(lblAuctionEnd, "2, 6, right, default"); //$NON-NLS-1$
- lblAuctionEndAnd = new JLabel(""); //$NON-NLS-1$
- articleDetailsPanel.add(lblAuctionEndAnd, "4, 6"); //$NON-NLS-1$
- /**
- * labels showing the number of bids on the article
- */
- lblNoOfBids = new JLabel(Messages.getString("GUI.NoOfBids")); //$NON-NLS-1$
- articleDetailsPanel.add(lblNoOfBids, "2, 8, right, default"); //$NON-NLS-1$
- lblDisplayNoOfBids = new JLabel(""); //$NON-NLS-1$
- articleDetailsPanel.add(lblDisplayNoOfBids, "4, 8"); //$NON-NLS-1$
- /**
- * label and text area showing the article description. text area is not
- * editable and has a scroll pane
- */
- lblDescription = new JLabel(Messages.getString("GUI.Description123")); //$NON-NLS-1$
- articleDetailsPanel.add(lblDescription, "2, 10, right, center"); //$NON-NLS-1$
- articleDescriptionTextAreaBuyTabScrollPane = new JScrollPane();
- articleDetailsPanel.add(articleDescriptionTextAreaBuyTabScrollPane,
- "4, 10, fill, fill"); //$NON-NLS-1$
- articleDescriptionTextAreaBuyTab = new JTextArea();
- articleDescriptionTextAreaBuyTabScrollPane
- .setViewportView(articleDescriptionTextAreaBuyTab);
- articleDescriptionTextAreaBuyTab.setLineWrap(true);
- /**
- * label showing the article number
- */
- lblArticleno = new JLabel(Messages.getString("GUI.ArtcleNo123")); //$NON-NLS-1$
- articleDetailsPanel.add(lblArticleno, "2, 12, right, default"); //$NON-NLS-1$
- lblArticlenoHere = new JLabel(""); //$NON-NLS-1$
- articleDetailsPanel.add(lblArticlenoHere, "4, 12"); //$NON-NLS-1$
- /**
- * label showing the article vendor
- */
- lblSoldBy = new JLabel(Messages.getString("GUI.SoldBy123")); //$NON-NLS-1$
- articleDetailsPanel.add(lblSoldBy, "2, 14, right, default"); //$NON-NLS-1$
- lblVendorNameHere = new JLabel(""); //$NON-NLS-1$
- articleDetailsPanel.add(lblVendorNameHere, "4, 14"); //$NON-NLS-1$
- /**
- * label showing the vendors phone number if he choose to show it
- */
- lblPhoneno = new JLabel(Messages.getString("GUI.PhoneNo123")); //$NON-NLS-1$
- articleDetailsPanel.add(lblPhoneno, "2, 16, right, default"); //$NON-NLS-1$
- lblPhonenoHere = new JLabel(""); //$NON-NLS-1$
- articleDetailsPanel.add(lblPhonenoHere, "4, 16"); //$NON-NLS-1$
- /**
- * label showing the vendors e-mail address if he choose to show it
- */
- lblEmail = new JLabel(Messages.getString("GUI.EMail123")); //$NON-NLS-1$
- articleDetailsPanel.add(lblEmail, "2, 18, right, default"); //$NON-NLS-1$
- lblEmailHere = new JLabel(""); //$NON-NLS-1$
- articleDetailsPanel.add(lblEmailHere, "4, 18"); //$NON-NLS-1$
- /**
- * button to purchase a sales item
- */
- btnBuyArticle = new JButton(Messages.getString("GUI.PurchaseArticle")); //$NON-NLS-1$
- btnBuyArticle.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked1(MouseEvent arg0) {
- // check because of possible transmission errors
- if (editArticle != null) {
- // check if it's a sales item to be safe
- if (editArticle.getClass().getSimpleName().equals(
- "SalesItem")) { //$NON-NLS-1$
- execute("BUY " + editArticle.getArticleNo()); //$NON-NLS-1$
- if (buyBool) {
- JOptionPane
- .showMessageDialog(
- null,
- Messages.getString("GUI.Congratulation"), //$NON-NLS-1$
- Messages.getString("GUI.ArticleBought"), //$NON-NLS-1$
- JOptionPane.INFORMATION_MESSAGE);
- } else {
- JOptionPane
- .showMessageDialog(
- null,
- Messages.getString("GUI.Sorry"), //$NON-NLS-1$
- Messages.getString("GUI.ArticleAlreadySold"), //$NON-NLS-1$
- JOptionPane.WARNING_MESSAGE);
- }
- }
- }
- ;
- articleDetailsPanel.add(btnBuyArticle, "4, 22"); //$NON-NLS-1$
- /**
- * labels showing the current max bid put on the article by the user
- */
- lblYourMaxBid = new JLabel(Messages.getString("GUI.YourMaxBid")); //$NON-NLS-1$
- articleDetailsPanel.add(lblYourMaxBid, "2, 20, right, default"); //$NON-NLS-1$
- lblMaxBidHere = new JLabel(""); //$NON-NLS-1$
- articleDetailsPanel.add(lblMaxBidHere, "4, 20"); //$NON-NLS-1$
- /**
- * button to bid an an article
- */
- btnBidOnArticle = new JButton(Messages.getString("GUI.BidOnArticle")); //$NON-NLS-1$
- btnBidOnArticle.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- JTextField newBid = new JTextField();
- Object[] newBidFields = {
- Messages.getString("GUI.PleaseEnterANewBid") //$NON-NLS-1$
- + ((AuctionArticle) editArticle)
- .getNextBidStep(), newBid };
- JOptionPane newBidPane = new JOptionPane(newBidFields,
- JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
- newBidPane.createDialog(null, Messages.getString("GUI.EnterNewBid")).setVisible(true); //$NON-NLS-1$
- if (checkForMalformedValues(newBid.getText(), "price")) { //$NON-NLS-1$
- double newBidValue = Double.parseDouble(newBid.getText());
- if (newBidValue >= ((AuctionArticle) editArticle)
- .getNextBidStep()) {
- execute("BID " + editArticle.getArticleNo() + " " //$NON-NLS-1$ //$NON-NLS-2$
- + newBidValue);
- } else {
- JOptionPane
- .showMessageDialog(
- null,
- Messages.getString("GUI.BidLow"), //$NON-NLS-1$
- Messages.getString("GUI.NewBidLow"), //$NON-NLS-1$
- JOptionPane.WARNING_MESSAGE);
- }
- }
- if (bidBool) {
- JOptionPane.showMessageDialog(null,
- Messages.getString("GUI.BidBeenAccepted"), //$NON-NLS-1$
- Messages.getString("GUI.BidAccepted"), JOptionPane.INFORMATION_MESSAGE); //$NON-NLS-1$
- } else {
- JOptionPane
- .showMessageDialog(
- null,
- Messages.getString("GUI.ProblemBid"), //$NON-NLS-1$
- Messages.getString("GUI.BidNotAccepted"), //$NON-NLS-1$
- JOptionPane.WARNING_MESSAGE);
- }
- }
- });
- articleDetailsPanel.add(btnBidOnArticle, "4, 24"); //$NON-NLS-1$
- /**
- * button to change the bid set on the article by the user. changes the
- * maxBid.
- */
- btnChangeBid = new JButton(Messages.getString("GUI.ChangeBid")); //$NON-NLS-1$
- btnChangeBid.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- JTextField newBid = new JTextField();
- Object[] newBidFields = {
- Messages.getString("GUI.PleaseNewBidMin") //$NON-NLS-1$
- + ((AuctionArticle) editArticle)
- .getNextBidStep(), newBid };
- JOptionPane newBidPane = new JOptionPane(newBidFields,
- JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
- newBidPane.createDialog(null, Messages.getString("GUI.EnterNewBid1")).setVisible(true); //$NON-NLS-1$
- if (checkForMalformedValues(newBid.getText(), "price")) { //$NON-NLS-1$
- double newBidValue = Double.parseDouble(newBid.getText());
- if (newBidValue >= ((AuctionArticle) editArticle)
- .getNextBidStep()) {
- execute("BID " + editArticle.getArticleNo() + " " //$NON-NLS-1$ //$NON-NLS-2$
- + newBidValue);
- } else {
- JOptionPane
- .showMessageDialog(
- null,
- Messages.getString("GUI.BidLowPlease"), //$NON-NLS-1$
- Messages.getString("GUI.NewBidToLow"), //$NON-NLS-1$
- JOptionPane.WARNING_MESSAGE);
- }
- }
- if (bidBool) {
- JOptionPane.showMessageDialog(null,
- Messages.getString("GUI.YourBidHasAccepted"), //$NON-NLS-1$
- Messages.getString("GUI.BidAccepted"), JOptionPane.INFORMATION_MESSAGE); //$NON-NLS-1$
- } else {
- JOptionPane
- .showMessageDialog(
- null,
- Messages.getString("GUI.ProblemWithBid"), //$NON-NLS-1$
- Messages.getString("GUI.BidNotAccepted2"), //$NON-NLS-1$
- JOptionPane.WARNING_MESSAGE);
- }
- }
- });
- articleDetailsPanel.add(btnChangeBid, "4, 26"); //$NON-NLS-1$
- articleTableBuyTabScrollPane = new JScrollPane();
- buyTabPanel.add(articleTableBuyTabScrollPane, "4, 8, 5, 1, fill, fill"); //$NON-NLS-1$
- /**
- * initial table for not having an empty spot in the gui
- */
- Object[][] data = new Object[0][0];
- String[] columnNamesArticleTableBuyTab = { Messages.getString("GUI.title5"), Messages.getString("GUI.cuurentPrice5"), //$NON-NLS-1$ //$NON-NLS-2$
- Messages.getString("GUI.timeLeft5") }; //$NON-NLS-1$
- articleTableBuyTab = new JTable(data, columnNamesArticleTableBuyTab);
- articleTableBuyTab.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
- articleTableBuyTab.setAutoCreateRowSorter(true);
- articleTableBuyTabScrollPane.setViewportView(articleTableBuyTab);
- categoryListBuyTabScrollPane = new JScrollPane();
- buyTabPanel.add(categoryListBuyTabScrollPane, "2, 8, fill, fill"); //$NON-NLS-1$
- /**
- * category list in buy tab. if a category is selected the
- * articleTableBuyTab table is filled with all articles from this
- * category
- */
- categoriesListModel = new DefaultListModel();
- categoryListBuyTab = new JList(categoriesListModel);
- categoryListBuyTab
- .addListSelectionListener(new ListSelectionListener() {
- public void valueChanged(ListSelectionEvent arg0) {
- if (arg0.getValueIsAdjusting()) {
- String selectedCategory = (String) categoryListBuyTab
- .getSelectedValue();
- String[] catNameSplit = selectedCategory.split(" "); //$NON-NLS-1$
- // works even if no user is logged in
- if (socket == null) {
- connectToServer();
- execute("LIST CATEGORY " + catNameSplit[0]); //$NON-NLS-1$
- execute("LOGOUT"); //$NON-NLS-1$
- } else {
- // gets all articles of selected category
- execute("LIST CATEGORY " + catNameSplit[0]); //$NON-NLS-1$
- }
- Iterator<Article> checkForSoldArticlesIterator = articleList
- .iterator();
- int numberOfSoldArticles = 0;
- while (checkForSoldArticlesIterator.hasNext()) {
- Article actual = checkForSoldArticlesIterator
- .next();
- if (actual.isSold()) {
- numberOfSoldArticles++;
- }
- }
- if (!articleList.isEmpty()) {
- // number of rows => number of articles minus
- // the sold ones
- Object[][] data = new Object[articleList.size()
- - numberOfSoldArticles][4];
- String[] columnNamesArticleTableBuyTab = {
- Messages.getString("GUI.title6"), Messages.getString("GUI.cuurentPrice6"), Messages.getString("GUI.timeLeft6"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- Messages.getString("GUI.ArticleNo6") }; //$NON-NLS-1$
- // counter to prevent running out of array
- // bounds
- int counter = 0;
- // first the salesitems
- Iterator<Article> it = articleList.iterator();
- while (it.hasNext()) {
- Object actual = it.next();
- if (actual.getClass().getSimpleName()
- .equals("SalesItem")) { //$NON-NLS-1$
- // if article isn't sold add it to the
- // list
- if (!((SalesItem) actual).isSold()) {
- data[counter][0] = ((SalesItem) actual)
- .getTitle();
- data[counter][1] = ((SalesItem) actual)
- .getPrice();
- data[counter][2] = ""; //$NON-NLS-1$
- data[counter][3] = ((SalesItem) actual)
- .getArticleNo();
- counter++;
- }
- }
- }
- // then the auction items
- Iterator<Article> it2 = articleList.iterator();
- while (it2.hasNext()) {
- Object actual = it2.next();
- if (actual.getClass().getSimpleName()
- .equals("AuctionArticle")) { //$NON-NLS-1$
- // if article isn't sold add it to the
- // list
- if (!((AuctionArticle) actual).isSold()) {
- data[counter][0] = ((AuctionArticle) actual)
- .getTitle();
- //if the minbiddingprice is higher than the currentmaxbid the minbidding price is shown
- //this should ONLY be the case if there is no bid yet. then the currentmaxbid is 0.00
- if( ((AuctionArticle) actual).getMinBiddingPrice() > ((AuctionArticle) actual).getCurrentMaxBid() ){
- data[counter][1] = ((AuctionArticle) actual).getMinBiddingPrice();
- //if the currentmaxbid is higher than the minbiddingprice show the currentmax bid
- }else{
- data[counter][1] = ((AuctionArticle) actual)
- .getCurrentMaxBid();
- }
- data[counter][2] = dateDifferenceToString(((AuctionArticle) actual)
- .getAuctionEnd());
- data[counter][3] = ((AuctionArticle) actual)
- .getArticleNo();
- counter++;
- }
- }
- }
- articleTableBuyTab = new JTable(new MyTableModel(columnNamesArticleTableBuyTab, data));
- articleTableBuyTab
- .setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
- articleTableBuyTab.setAutoCreateRowSorter(true);
- articleTableBuyTabScrollPane
- .setViewportView(articleTableBuyTab);
- // set column widths so that they fill the panel
- articleTableBuyTab.getColumnModel()
- .getColumn(0).setPreferredWidth(268);
- articleTableBuyTab.getColumnModel()
- .getColumn(1).setPreferredWidth(80);
- articleTableBuyTab.getColumnModel()
- .getColumn(2).setPreferredWidth(110);
- }
- }
- }
- });
- categoryListBuyTab
- .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
- categoryListBuyTab.setLayoutOrientation(JList.VERTICAL);
- categoryListBuyTab.setVisible(true);
- categoryListBuyTabScrollPane.setViewportView(categoryListBuyTab);
- //button will most likely be deleted
- // btnShowSelectedCategory = new JButton("show selected Category");
- // btnShowSelectedCategory.addMouseListener(new MouseAdapter() {
- // @Override
- // public void mouseClicked(MouseEvent arg0) {
- // String selectedCategory = (String)
- // categoryListBuyTab.getSelectedValue();
- // String[] catNameSplit = selectedCategory.split(" ");
- // execute("LIST CATEGORY "+catNameSplit[0]);
- //
- // if(!articleList.isEmpty()){
- // Object[][] data = new Object[articleList.size()][3];
- // String[] columnNamesArticleTableBuyTab = { "Title", "Current Price",
- // "Time left" };
- //
- // //counter to prevent running out of array bounds
- // int counter = 0;
- // //first the salesitems
- // Iterator<Article> it = articleList.iterator();
- // while (it.hasNext()){
- // Object actual = it.next();
- //
- // if(actual.getClass().getSimpleName().equals("SalesItem")){
- //
- // data[counter][0] = ((SalesItem) actual).getTitle();
- // data[counter][1] = ((SalesItem) actual).getPrice();
- // data[counter][2] = "";
- // counter++;
- // }
- // }
- //
- // //then the auction items
- // Iterator<Article> it2 = articleList.iterator();
- // while(it2.hasNext()){
- // Object actual = it2.next();
- //
- // if(actual.getClass().getSimpleName().equals("AuctionArticle")){
- // data[counter][0] = ((AuctionArticle) actual).getTitle();
- // data[counter][1] = ((AuctionArticle) actual).getCurrentMaxBid();
- // data[counter][2] = dateDifferenceToString(((AuctionArticle)
- // actual).getAuctionEnd());
- // counter++;
- // }
- // }
- //
- //
- // articleTableBuyTab = new JTable(data, columnNamesArticleTableBuyTab);
- // articleTableBuyTab.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
- // articleTableBuyTab.setAutoCreateRowSorter(true);
- // articleTableBuyTabScrollPane.setViewportView(articleTableBuyTab);
- //
- // //set column widths so that they fill the panel
- // articleTableBuyTab.getColumnModel().getColumn(0).setPreferredWidth(240);
- // articleTableBuyTab.getColumnModel().getColumn(1).setPreferredWidth(80);
- // articleTableBuyTab.getColumnModel().getColumn(2).setPreferredWidth(110);
- //
- //
- // }
- //
- // }
- // });
- // buyTabPanel.add(btnShowSelectedCategory, "2, 10, center, default");
- /**
- * shows the article details of the article selected in the
- * articleTableBuyTab jtable
- */
- btnShowArticleDetails = new JButton(Messages.getString("GUI.showArticleDetails")); //$NON-NLS-1$
- btnShowArticleDetails.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- // check if a row is selected (-1 means no row selected)
- if (articleTableBuyTab.getSelectedRow() != -1) {
- int articleToGetId = (Integer) articleTableBuyTab
- .getValueAt(articleTableBuyTab.getSelectedRow(), 3);
- execute("SHOW ARTICLE " + articleToGetId); //$NON-NLS-1$
- // check because of possible transmission errors
- if (editArticle != null) {
- lblArticleTitleHere.setText(editArticle.getTitle());
- if (editArticle.getClass().getSimpleName().equals(
- "SalesItem")) { //$NON-NLS-1$
- SalesItem tempItem = (SalesItem) editArticle;
- lblCurrentPriceHere.setText(String.valueOf(tempItem
- .getPrice()));
- // sales items don't have an auction end or bids and
- // you can't buy them
- lblAuctionEnd.setVisible(false);
- lblAuctionEndAnd.setVisible(false);
- lblNoOfBids.setVisible(false);
- lblDisplayNoOfBids.setVisible(false);
- btnBuyArticle.setVisible(true);
- btnBidOnArticle.setVisible(false);
- btnChangeBid.setVisible(false);
- lblMaxBidHere.setVisible(false);
- lblYourMaxBid.setVisible(false);
- } else if (editArticle.getClass().getSimpleName()
- .equals("AuctionArticle")) { //$NON-NLS-1$
- AuctionArticle tempArticle = (AuctionArticle) editArticle;
- //if the minbiddingprice is higher than the currentmaxbid the minbidding price is shown
- //this should ONLY be the case if there is no bid yet. then the currentmaxbid is 0.00
- if( tempArticle.getMinBiddingPrice() > tempArticle.getCurrentMaxBid() ){
- lblCurrentPriceHere.setText(String
- .valueOf(tempArticle.getMinBiddingPrice())
- + " EUR");
- //if the currentmaxbid is higher than the minbiddingprice show the currentmax bid
- }else{
- lblCurrentPriceHere.setText(String
- .valueOf(tempArticle.getCurrentMaxBid())
- + " EUR");
- }
- lblAuctionEndAnd
- .setText(dateDifferenceToString(tempArticle
- .getAuctionEnd())
- + " (" //$NON-NLS-1$
- + gregorianToString(tempArticle
- .getAuctionEnd(), "long") //$NON-NLS-1$
- + ")"); //$NON-NLS-1$
- lblDisplayNoOfBids.setText(String
- .valueOf(tempArticle.getBidList().size()));
- // //sales items don't have an auction end or bids
- // but auction articles do
- lblAuctionEnd.setVisible(true);
- lblAuctionEndAnd.setVisible(true);
- lblNoOfBids.setVisible(true);
- lblDisplayNoOfBids.setVisible(true);
- btnBuyArticle.setVisible(false);
- lblMaxBidHere.setVisible(true);
- lblYourMaxBid.setVisible(true);
- // determin whether to show the bid (for the first
- // time) on article or the change bid button
- Iterator<Bid> it = tempArticle.getBidList()
- .iterator();
- boolean userAlreadyBidOnArticle = false;
- double userCurrentMaxBid = 0;
- while (it.hasNext()) {
- Bid actual = it.next();
- System.out.println("user corresponding to the bid: "+actual.getCorrespondingUser().getUsername());
- System.out.println("user currently logged in: "+usernameTempSaved);
- System.out.println("are the the same? "+actual.getCorrespondingUser().getUsername().equals(usernameTempSaved));
- if (actual.getCorrespondingUser().getUsername().equals(
- usernameTempSaved)) {
- userAlreadyBidOnArticle = true;
- // user's current bid on article
- userCurrentMaxBid = actual.getMaxBid();
- System.out.println(usernameTempSaved+" max bid: "+actual.getMaxBid());
- }
- }
- if (userAlreadyBidOnArticle) {
- btnBidOnArticle.setVisible(false);
- btnChangeBid.setVisible(true);
- lblYourMaxBid.setVisible(true);
- lblMaxBidHere.setVisible(true);
- lblMaxBidHere.setText(String
- .valueOf(userCurrentMaxBid));
- } else {
- btnBidOnArticle.setVisible(true);
- btnChangeBid.setVisible(false);
- lblMaxBidHere.setVisible(false);
- lblYourMaxBid.setVisible(false);
- }
- }
- articleDescriptionTextAreaBuyTab.setText(editArticle
- .getDescription());
- lblArticlenoHere.setText(String.valueOf(editArticle
- .getArticleNo()));
- lblVendorNameHere.setText(editArticle.getVendor()
- .getUsername());
- // did the vendor select show phone?
- if (editArticle.isShowPhoneNoSet()) {
- lblPhonenoHere.setText(editArticle.getVendor()
- .getPhoneNo());
- } else {
- lblPhonenoHere.setText(Messages.getString("GUI.NotVisible")); //$NON-NLS-1$
- }
- // did the vendor select show email?
- if (editArticle.isShowEmailSet()) {
- lblEmailHere.setText(editArticle.getVendor()
- .getEmail());
- } else {
- lblEmailHere.setText(Messages.getString("GUI.NotVisible2")); //$NON-NLS-1$
- }
- }
- // index -1 => no article selected
- } else {
- JOptionPane
- .showMessageDialog(
- null,
- Messages.getString("GUI.NoSelected"), //$NON-NLS-1$
- Messages.getString("GUI.NoSelectedArticle"), //$NON-NLS-1$
- JOptionPane.WARNING_MESSAGE);
- }
- }
- });
- buyTabPanel.add(btnShowArticleDetails, "4, 10, 3, 1, center, default"); //$NON-NLS-1$
- /**
- * the sell tab
- */
- sellTabPanel = new JPanel();
- tabbedPane.addTab("Sell", null, sellTabPanel, null);
- sellTabPanel.setLayout(new FormLayout(new ColumnSpec[] {
- FormFactory.RELATED_GAP_COLSPEC,
- ColumnSpec.decode("210px"),
- FormFactory.RELATED_GAP_COLSPEC,
- ColumnSpec.decode("150px"),
- FormFactory.RELATED_GAP_COLSPEC,
- ColumnSpec.decode("30px"),
- FormFactory.RELATED_GAP_COLSPEC,
- ColumnSpec.decode("100px"),
- FormFactory.RELATED_GAP_COLSPEC,
- ColumnSpec.decode("160px"),
- FormFactory.RELATED_GAP_COLSPEC,
- ColumnSpec.decode("150px"),
- FormFactory.RELATED_GAP_COLSPEC,
- ColumnSpec.decode("140px"),
- FormFactory.RELATED_GAP_COLSPEC,
- FormFactory.DEFAULT_COLSPEC,},
- new RowSpec[] {
- FormFactory.RELATED_GAP_ROWSPEC,
- RowSpec.decode("default:grow"),
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- RowSpec.decode("default:grow"),
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- RowSpec.decode("max(19dlu;min)"),
- FormFactory.RELATED_GAP_ROWSPEC,
- RowSpec.decode("max(19dlu;min)"),
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,}));
- /**
- * combobox representing choices for article insertion (sales item or
- * auction article) location: sell tab, left hand side
- */
- String[] articleInsertionChoices = { Messages.getString("GUI.InsertSalesItem"), //$NON-NLS-1$
- Messages.getString("GUI.inerstAuctionArticle") }; //$NON-NLS-1$
- comboBox = new JComboBox(articleInsertionChoices);
- comboBox.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- if (comboBox.getSelectedItem().equals(Messages.getString("GUI.InsertSalesItem2"))) { //$NON-NLS-1$
- txtAuctionEndDate.setVisible(false);
- lblFormatYymmdd.setVisible(false);
- } else if (comboBox.getSelectedItem().equals(
- Messages.getString("GUI.inerstAuctionArticle2"))) { //$NON-NLS-1$
- txtAuctionEndDate.setVisible(true);
- lblFormatYymmdd.setVisible(true);
- }
- }
- });
- sellTabPanel.add(comboBox, "2, 2"); //$NON-NLS-1$
- /**
- * updates the article list shown in the sell tab. shows the articles
- * offered by the user currently logged in. location: selll tab, right
- * hand side
- */
- btnUpdateArticleList = new JButton(Messages.getString("GUI.UpdateList")); //$NON-NLS-1$
- btnUpdateArticleList.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- String[] columnNamesArticleListChangeArticle = { Messages.getString("GUI.ArtNo"), //$NON-NLS-1$
- 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$
- Messages.getString("GUI.Status7") }; //$NON-NLS-1$
- String articlesByUser = usernameTempSaved;
- if (checkForMalformedValues(articlesByUser, Messages.getString("GUI.Username7"))) { //$NON-NLS-1$
- execute("LIST USER " + articlesByUser); //$NON-NLS-1$
- Object[][] data = new Object[articleList.size()][6];
- if (articleList.size() != 0) {
- // counter to prevent running out of array bounds
- int counter = 0;
- // first the salesitems
- Iterator<Article> it = articleList.iterator();
- while (it.hasNext()) {
- Object actual = it.next();
- if (actual.getClass().getSimpleName().equals(
- "SalesItem")) { //$NON-NLS-1$
- data[counter][0] = ((SalesItem) actual)
- .getArticleNo();
- data[counter][1] = ((SalesItem) actual)
- .getTitle();
- data[counter][2] = ((SalesItem) actual)
- .getDescription();
- data[counter][3] = ((SalesItem) actual)
- .getPrice();
- data[counter][4] = ""; //$NON-NLS-1$
- if (((SalesItem) actual).isSold()) {
- data[counter][5] = "sold"; //$NON-NLS-1$
- } else {
- data[counter][5] = "available"; //$NON-NLS-1$
- }
- counter++;
- }
- }
- // then the auction items
- Iterator<Article> it2 = articleList.iterator();
- while (it2.hasNext()) {
- Object actual = it2.next();
- if (actual.getClass().getSimpleName().equals(
- "AuctionArticle")) { //$NON-NLS-1$
- data[counter][0] = ((AuctionArticle) actual)
- .getArticleNo();
- data[counter][1] = ((AuctionArticle) actual)
- .getTitle();
- data[counter][2] = ((AuctionArticle) actual)
- .getDescription();
- //if the minbiddingprice is higher than the currentmaxbid the minbidding price is shown
- //this should ONLY be the case if there is no bid yet. then the currentmaxbid is 0.00
- if( ((AuctionArticle) actual).getMinBiddingPrice() > ((AuctionArticle) actual).getCurrentMaxBid() ){
- data[counter][3] = ((AuctionArticle) actual).getMinBiddingPrice();
- //if the currentmaxbid is higher than the minbiddingprice show the currentmax bid
- }else{
- data[counter][3] = ((AuctionArticle) actual)
- .getCurrentMaxBid();
- }
- data[counter][4] = dateDifferenceToString(((AuctionArticle) actual)
- .getAuctionEnd());
- if (((AuctionArticle) actual).isSold()) {
- data[counter][5] = "sold"; //$NON-NLS-1$
- } else {
- data[counter][5] = "available"; //$NON-NLS-1$
- }
- counter++;
- }
- }
- //reset fields
- //TODO reset jtable on right side of sell tab
- currentArticleCategoriesListModel.removeAllElements();
- txtrCurrentDescription.setText("current description");
- txtrAddToCurrentDescription.setText("add to current description");
- changeArticleDataNewCategoryTextField.setText("new Category");
- changeArticleDataChangePriceTextField.setText("price");
- showMyArticlesTable = new JTable(new MyTableModel(columnNamesArticleListChangeArticle, data));
- showMyArticlesTable
- .setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
- showMyArticlesTable.setAutoCreateRowSorter(true);
- showMyArticlesTableScrollPane
- .setViewportView(showMyArticlesTable);
- }else{
- //show empty jtable
- showMyArticlesTable.removeAll();
- Object[][] data2 = new Object[0][0];
- showMyArticlesTable.setModel(new MyTableModel(columnNamesArticleListChangeArticle, data2));
- showMyArticlesTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
- showMyArticlesTable.setAutoCreateRowSorter(true);
- showMyArticlesTableScrollPane.setViewportView(showMyArticlesTable);
- JOptionPane.showMessageDialog(null,
- "You don't sell anything. So we cannot show you what you sell. Sounds reasonable doesn't it?",
- "No items found", JOptionPane.WARNING_MESSAGE);
- }
- }
- }
- });
- sellTabPanel.add(btnUpdateArticleList, "10, 2"); //$NON-NLS-1$
- /**
- * loads the article selected in showMyArticlesTable into the article
- * change interface location: sell tab. right hand side
- */
- btnEditSelectedArticle = new JButton(Messages.getString("GUI.EditArticle")); //$NON-NLS-1$
- btnEditSelectedArticle.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- // check if an article is selected
- if (showMyArticlesTable.getSelectedRow() != -1) {
- int articleIdToChange = (Integer) showMyArticlesTable
- .getValueAt(showMyArticlesTable.getSelectedRow(), 0);
- execute("SHOW ARTICLE " + articleIdToChange); //$NON-NLS-1$
- // check because of possible transmission errors
- if (editArticle != null) {
- txtrCurrentDescription.setText(editArticle
- .getDescription());
- if (editArticle.getClass().getSimpleName().equals(
- "AuctionArticle")) { //$NON-NLS-1$
- changeArticleDataChangePriceTextField
- .setVisible(false);
- btnSetNewPrice.setVisible(false);
- } else if (editArticle.getClass().getSimpleName()
- .equals("SalesItem")) { //$NON-NLS-1$
- changeArticleDataChangePriceTextField
- .setVisible(true);
- SalesItem sale = (SalesItem) editArticle;
- changeArticleDataChangePriceTextField
- .setText(String.valueOf(sale.getPrice()));
- btnSetNewPrice.setVisible(true);
- }
- // clear categorylist in edit panel
- currentArticleCategoriesListModel.removeAllElements();
- ArrayList<Category> tempCategoryList = editArticle
- .getCategoryList();
- Iterator<Category> it = tempCategoryList.iterator();
- while (it.hasNext()) {
- Category actual = it.next();
- currentArticleCategoriesListModel.add(
- currentArticleCategoriesListModel.size(),
- actual.getCatName());
- }
- }
- } else {
- JOptionPane.showMessageDialog(null,
- Messages.getString("GUI.SelectArticle"), //$NON-NLS-1$
- Messages.getString("GUI.NoSelectArticle"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
- }
- }
- });
- sellTabPanel.add(btnEditSelectedArticle, "12, 2"); //$NON-NLS-1$
- showMyArticlesPanel = new JPanel();
- sellTabPanel.add(showMyArticlesPanel, "10, 3, 3, 7, fill, fill"); //$NON-NLS-1$
- showMyArticlesPanel.setLayout(new FormLayout(new ColumnSpec[] {
- FormFactory.RELATED_GAP_COLSPEC,
- ColumnSpec.decode("default:grow"), }, new RowSpec[] { //$NON-NLS-1$
- FormFactory.RELATED_GAP_ROWSPEC,
- RowSpec.decode("default:grow"), })); //$NON-NLS-1$
- String[] columnNamesArticleListChangeArticle = { "ArticleNo",
- "Title", "Description", "Current Price", "Time left",
- "Status" };
- showMyArticlesTable = new JTable();
- showMyArticlesTable.setModel(new MyTableModel(columnNamesArticleListChangeArticle,new Object[0][0]));
- showMyArticlesTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
- showMyArticlesTable.setAutoCreateRowSorter(true);
- /**
- * scrollpane for showMyArticlesTable
- */
- showMyArticlesTableScrollPane = new JScrollPane();
- showMyArticlesPanel.add(showMyArticlesTableScrollPane,
- "2, 2, fill, fill");
- showMyArticlesTableScrollPane.setViewportView(showMyArticlesTable);
- /**
- * deleted the selected article if it is not sold and in case of an
- * auction article if there is no bid on it
- */
- btnDeleteSelectedArticle = new JButton(
- Messages.getString("GUI.deletArticle")); //$NON-NLS-1$
- btnDeleteSelectedArticle.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- if (showMyArticlesTable.getSelectedRow() != -1) {
- int articleIdToChange = (Integer) showMyArticlesTable
- .getValueAt(showMyArticlesTable.getSelectedRow(), 0);
- execute("SHOW ARTICLE " + articleIdToChange); //$NON-NLS-1$
- // check because of possible transmission errors
- if (editArticle != null) {
- // is the article to be deleted an auction article?
- if (editArticle.getClass().getSimpleName().equals(
- "AuctionArticle")) { //$NON-NLS-1$
- AuctionArticle auction = (AuctionArticle) editArticle;
- // are bids given for this auction article? if no,
- // go on
- if (auction.getBidList().isEmpty()) {
- // is the auction article sold? if no, go on
- // delete it.
- // probably unnecessary check but better save
- // than sorry.
- if (!auction.isSold()) {
- execute("DELETE ARTICLE " //$NON-NLS-1$
- + articleIdToChange);
- }
- // bids on article -> cannot delete it
- } else if (!auction.getBidList().isEmpty()) {
- JOptionPane
- .showMessageDialog(
- null,
- Messages.getString("GUI.ConnotDelete"), //$NON-NLS-1$
- Messages.getString("GUI.DeletionError"), //$NON-NLS-1$
- JOptionPane.WARNING_MESSAGE);
- }
- // or is the article to be deleted a sales item?
- } else if (editArticle.getClass().getSimpleName()
- .equals("SalesItem")) { //$NON-NLS-1$
- SalesItem sale = (SalesItem) editArticle;
- // is sales item already sold? if no, delete it
- if (!sale.isSold()) {
- execute("DELETE ARTICLE " + articleIdToChange); //$NON-NLS-1$
- }
- }
- }
- }
- }
- });
- txtArticleTitle = new JTextField();
- txtArticleTitle.setText(Messages.getString("GUI.ArticleTitle")); //$NON-NLS-1$
- sellTabPanel.add(txtArticleTitle, "2, 4, fill, default"); //$NON-NLS-1$
- txtArticleTitle.setColumns(10);
- sellTabPanel.add(btnDeleteSelectedArticle, "14, 4"); //$NON-NLS-1$
- /**
- * article title textfield for article insertion location: sell tab,
- * left hand side
- */
- /**
- * sets the selected article to unsold if the article was sold and the
- * buyer didn't pay
- */
- // work-around with html to be able to have a two line button
- btnSetSelectedArticle = new JButton(
- Messages.getString("GUI.selectedArticleTo")); //$NON-NLS-1$
- btnSetSelectedArticle.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- // check if an article is selected
- if (showMyArticlesTable.getSelectedRow() != -1) {
- int articleIdToChange = (Integer) showMyArticlesTable
- .getValueAt(showMyArticlesTable.getSelectedRow(), 0);
- execute("SHOW ARTICLE " + articleIdToChange); //$NON-NLS-1$
- // check because of possible transmission errors
- if (editArticle != null) {
- // if the article is marked as sold, change it
- if (editArticle.isSold()) {
- if (editArticle.getClass().getSimpleName().equals(
- "AuctionArticle")) { //$NON-NLS-1$
- // get the new auction end date
- JTextField newAuctionEndDate = new JTextField();
- Object[] newAuctionEndDateFields = {
- Messages.getString("GUI.PleaseEnterNewAuction"), //$NON-NLS-1$
- newAuctionEndDate };
- JOptionPane newAuctionEndDatePane = new JOptionPane(
- newAuctionEndDateFields,
- JOptionPane.PLAIN_MESSAGE,
- JOptionPane.OK_CANCEL_OPTION);
- newAuctionEndDatePane.createDialog(null,
- Messages.getString("GUI.AuctionEndDate0")) //$NON-NLS-1$
- .setVisible(true);
- String newAuctionEndDateString = newAuctionEndDate
- .getText();
- if (checkForMalformedValues(
- newAuctionEndDateString, "auctionend")) { //$NON-NLS-1$
- execute("UNSOLD " + articleIdToChange); //$NON-NLS-1$
- execute("CHANGE AUCTIONEND " //$NON-NLS-1$
- + articleIdToChange + " TO " //$NON-NLS-1$
- + newAuctionEndDateString);
- //if the change to unsold was successfull show it
- if(changeSoldFlagBool){
- JOptionPane
- .showMessageDialog(
- null,
- "The article is now set to unsold.",
- "Article set to unsold",
- JOptionPane.WARNING_MESSAGE);
- //if not show it too
- }else{
- JOptionPane
- .showMessageDialog(
- null,
- "The article couldn't be set to unsold.",
- "Article NOT set to unsold",
- JOptionPane.WARNING_MESSAGE);
- }
- }
- } else if (editArticle.getClass().getSimpleName()
- .equals("SalesItem")) {
- execute("UNSOLD " + articleIdToChange);
- //if the change to unsold was successfull show it
- if(changeSoldFlagBool){
- JOptionPane
- .showMessageDialog(
- null,
- "The article is now set to unsold.",
- "Article set to unsold",
- JOptionPane.WARNING_MESSAGE);
- //if not show it too
- }else{
- JOptionPane
- .showMessageDialog(
- null,
- "The article couldn't be set to unsold.",
- "Article NOT set to unsold",
- JOptionPane.WARNING_MESSAGE);
- }
- }
- // i have no idea how to make this easier. so
- // another big piece of copy paste code
- // ///////////start copy paste code
- String[] columnNamesArticleListChangeArticle = {
- Messages.getString("GUI.ArticleNo8"), Messages.getString("GUI.Title8"), Messages.getString("GUI.Description8"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- Messages.getString("GUI.CurrentPrice8"), Messages.getString("GUI.TimeLeft8"), Messages.getString("GUI.Status") }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- String articlesByUser = usernameTempSaved;
- if (checkForMalformedValues(articlesByUser,
- Messages.getString("GUI.username8"))) { //$NON-NLS-1$
- execute("LIST USER " + articlesByUser); //$NON-NLS-1$
- Object[][] data = new Object[articleList.size()][6];
- if (articleList.size() != 0) {
- // counter to prevent running out of array
- // bounds
- int counter = 0;
- // first the salesitems
- Iterator<Article> it = articleList
- .iterator();
- while (it.hasNext()) {
- Object actual = it.next();
- if (actual.getClass().getSimpleName()
- .equals("SalesItem")) { //$NON-NLS-1$
- data[counter][0] = ((SalesItem) actual)
- .getArticleNo();
- data[counter][1] = ((SalesItem) actual)
- .getTitle();
- data[counter][2] = ((SalesItem) actual)
- .getDescription();
- data[counter][3] = ((SalesItem) actual)
- .getPrice();
- data[counter][4] = ""; //$NON-NLS-1$
- if (((SalesItem) actual).isSold()) {
- data[counter][5] = "sold"; //$NON-NLS-1$
- } else {
- data[counter][5] = "available"; //$NON-NLS-1$
- }
- counter++;
- }
- }
- // then the auction items
- Iterator<Article> it2 = articleList
- .iterator();
- while (it2.hasNext()) {
- Object actual = it2.next();
- if (actual.getClass().getSimpleName()
- .equals("AuctionArticle")) { //$NON-NLS-1$
- data[counter][0] = ((AuctionArticle) actual)
- .getArticleNo();
- data[counter][1] = ((AuctionArticle) actual)
- .getTitle();
- data[counter][2] = ((AuctionArticle) actual)
- .getDescription();
- //if the minbiddingprice is higher than the currentmaxbid the minbidding price is shown
- //this should ONLY be the case if there is no bid yet. then the currentmaxbid is 0.00
- if( ((AuctionArticle) actual).getMinBiddingPrice() > ((AuctionArticle) actual).getCurrentMaxBid() ){
- data[counter][3] = ((AuctionArticle) actual).getMinBiddingPrice();
- //if the currentmaxbid is higher than the minbiddingprice show the currentmax bid
- }else{
- data[counter][3] = ((AuctionArticle) actual)
- .getCurrentMaxBid();
- }
- data[counter][4] = dateDifferenceToString(((AuctionArticle) actual)
- .getAuctionEnd());
- if (((AuctionArticle) actual)
- .isSold()) {
- data[counter][5] = "sold"; //$NON-NLS-1$
- } else {
- data[counter][5] = "available"; //$NON-NLS-1$
- }
- counter++;
- }
- }
- showMyArticlesTable = new JTable(data,
- columnNamesArticleListChangeArticle);
- showMyArticlesTable
- .setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
- showMyArticlesTable
- .setAutoCreateRowSorter(true);
- showMyArticlesTableScrollPane
- .setViewportView(showMyArticlesTable);
- }
- }
- // /////////end copy paste code
- // if the article isn't marked as sold let the user
- // know he cannot fool the application
- } else if (!editArticle.isSold()) {
- JOptionPane
- .showMessageDialog(
- null,
- Messages.getString("GUI.ArticleIsntSold"), //$NON-NLS-1$
- Messages.getString("GUI.ConnotUnsold"), //$NON-NLS-1$
- JOptionPane.WARNING_MESSAGE);
- }
- }
- } else {
- JOptionPane.showMessageDialog(null,
- Messages.getString("GUI.PleaseSelect"), //$NON-NLS-1$
- Messages.getString("GUI.NoSelected3"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
- }
- }
- });
- sellTabPanel.add(btnSetSelectedArticle, "14, 8"); //$NON-NLS-1$
- /**
- * article description textarea for article insertion location: sell
- * tab, left hand side
- */
- articleDescriptionTextArea = new JTextArea(Messages.getString("GUI.ArticleDescription")); //$NON-NLS-1$
- articleDescriptionTextArea.setLineWrap(true);
- /**
- * scrollpane for article description textarea
- */
- articleDescriptionTextAreaScrollPane = new JScrollPane();
- articleDescriptionTextAreaScrollPane
- .setViewportView(articleDescriptionTextArea);
- sellTabPanel.add(articleDescriptionTextAreaScrollPane,
- "2, 6, 1, 3, fill, fill"); //$NON-NLS-1$
- /**
- * combobox for category selection. used while inserting articles
- * location: sell tab, left hand side
- */
- categorySelectionComboBox = new JComboBox(updateCategoryData());
- sellTabPanel.add(categorySelectionComboBox, "2, 10, fill, default"); //$NON-NLS-1$
- /**
- * add category button. used while inserting articles. adds the selected
- * category to the jlist containing all article categories location:
- * sell tab, left hand side
- */
- btnAddCategory = new JButton(Messages.getString("GUI.AddCategory1")); //$NON-NLS-1$
- btnAddCategory.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- // adds the selected category from the category selection
- // combobox at the end of the selected category list
- currentCategorySelectionListModel.add(
- currentCategorySelectionList.getModel().getSize(),
- categorySelectionComboBox.getSelectedItem());
- }
- });
- sellTabPanel.add(btnAddCategory, "4, 10"); //$NON-NLS-1$
- /**
- * text area displaying current description. used while editing article
- * data. location: sell tab, right hand side
- */
- txtrCurrentDescription = new JTextArea(Messages.getString("GUI.currentDescription")); //$NON-NLS-1$
- txtrCurrentDescription.setRows(3);
- txtrCurrentDescription.setEditable(false);
- txtrCurrentDescription.setLineWrap(true);
- /**
- * scroll pane for text area displaying current description. see above
- * location: sell tab, right hand side
- */
- txtrCurrentDescriptionScrollPane = new JScrollPane();
- txtrCurrentDescriptionScrollPane
- .setViewportView(txtrCurrentDescription);
- sellTabPanel.add(txtrCurrentDescriptionScrollPane,
- "10, 10, 3, 1, fill, fill"); //$NON-NLS-1$
- /**
- * text field for a adding an new category location: sell tab, left hand
- * side
- */
- txtNewCategory = new JTextField();
- txtNewCategory.setText(Messages.getString("GUI.NewCategory")); //$NON-NLS-1$
- sellTabPanel.add(txtNewCategory, "2, 12, fill, default"); //$NON-NLS-1$
- txtNewCategory.setColumns(10);
- /**
- * button to add a new category. adds category to jlist with all article
- * categories. checks if the "new" category is really new and then adds
- * it to the jlist. after that all comboboxes containing the
- * categorylist are updated. location: sell tab, left hand side
- */
- btnAddNewCategory = new JButton(Messages.getString("GUI.addNewCategory")); //$NON-NLS-1$
- btnAddNewCategory.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- boolean alreadyExistingCategory = false;
- // if category name doesn't contain a space character ->
- // continue
- if (checkForMalformedValues(txtNewCategory.getText(),
- "category")) { //$NON-NLS-1$
- // check if new category name already exists (if so it's in
- // the categoryselectioncombobox)
- for (int i = 0; i < categorySelectionComboBox
- .getItemCount(); i++) {
- if (categorySelectionComboBox.getItemAt(i).equals(
- txtNewCategory.getText())) {
- alreadyExistingCategory = true;
- }
- }
- // category is new? then add it to the list
- if (!alreadyExistingCategory) {
- // adds the selected category from the new category
- // textfield at the end of the selected category list
- currentCategorySelectionListModel.add(
- currentCategorySelectionList.getModel()
- .getSize(), txtNewCategory.getText());
- //update category comboboxes with new category data
- categorySelectionComboBox.setModel(updateCategoryData());
- editArticleCategorySelectionComboBox.setModel(updateCategoryData());
- // category already exists? let the user know about that
- } else if (alreadyExistingCategory) {
- JOptionPane
- .showMessageDialog(
- null,
- Messages.getString("GUI.CategoryExistsPlease"), //$NON-NLS-1$
- Messages.getString("GUI.CategoryExistsAlreday"), //$NON-NLS-1$
- JOptionPane.WARNING_MESSAGE);
- }
- }
- }
- });
- sellTabPanel.add(btnAddNewCategory, "4, 12"); //$NON-NLS-1$
- /**
- * text area to gather additional description text for article.
- * location: sell tab, right hand side
- */
- txtrAddToCurrentDescription = new JTextArea();
- txtrAddToCurrentDescription.setLineWrap(true);
- txtrAddToCurrentDescription.setText(Messages.getString("GUI.AddToCurrentDescrip")); //$NON-NLS-1$
- /**
- * scroll pane for txtrAddToCurrentDescription text area. location: sell
- * tab, right hand side
- */
- addToCurrentDescriptionScrollPane = new JScrollPane();
- addToCurrentDescriptionScrollPane
- .setViewportView(txtrAddToCurrentDescription);
- sellTabPanel.add(addToCurrentDescriptionScrollPane,
- "10, 12, 3, 3, fill, fill"); //$NON-NLS-1$
- /**
- * listmodel to alter currentCategorySelectionList data
- *
- */
- currentCategorySelectionListModel = new DefaultListModel();
- /**
- * list containing all currently selected categories for new article
- * location: sell tab, left hand side
- */
- currentCategorySelectionList = new JList(
- currentCategorySelectionListModel);
- currentCategorySelectionList
- .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
- currentCategorySelectionList.setLayoutOrientation(JList.VERTICAL);
- currentCategorySelectionList.setVisibleRowCount(3);
- /**
- * scroll pane for currentCategorySelectionList location: sell tab, left
- * hand side
- */
- currentCategorySelectionListScrollPane = new JScrollPane();
- currentCategorySelectionListScrollPane
- .setViewportView(currentCategorySelectionList);
- sellTabPanel.add(currentCategorySelectionListScrollPane,
- "2, 14, 1, 3, fill, fill"); //$NON-NLS-1$
- /**
- * lable beside currentCategorySelectionList location: sell tab, left
- * hand side
- */
- lblSelectedCategories = new JLabel(Messages.getString("GUI.SelectedCategory1")); //$NON-NLS-1$
- sellTabPanel.add(lblSelectedCategories, "4, 14, 1, 2"); //$NON-NLS-1$
- /**
- * removes the selected category from the currentCategorySelectionList
- * location: sell tab, left hand side
- */
- btnRemoveSelectedCategory = new JButton(Messages.getString("GUI.removeCategory")); //$NON-NLS-1$
- btnRemoveSelectedCategory.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- int selectedIndex = currentCategorySelectionList
- .getSelectedIndex();
- if (selectedIndex != -1) {
- currentCategorySelectionListModel.remove(selectedIndex);
- }
- }
- });
- sellTabPanel.add(btnRemoveSelectedCategory, "4, 16"); //$NON-NLS-1$
- /**
- * adds the new description text from txtrAddToCurrentDescription to the
- * already existing description text
- */
- btnAddToDescription = new JButton(Messages.getString("GUI.AddToDescription")); //$NON-NLS-1$
- btnAddToDescription.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- // check because of possible transmission errors
- if (editArticle != null) {
- execute("ADD DESCRIPTION " + editArticle.getArticleNo()
- + " \"" + "\n"+txtrAddToCurrentDescription.getText()
- + "\"");
- }
- }
- });
- sellTabPanel.add(btnAddToDescription, "12, 16");
- /**
- * checkbox to indicate whether the phone number should be visible on
- * article details location: sell tab, left hand side
- */
- chckbxShowPhonenoOn = new JCheckBox(Messages.getString("GUI.ShowPhoneNo")); //$NON-NLS-1$
- sellTabPanel.add(chckbxShowPhonenoOn, "2, 18, 3, 1"); //$NON-NLS-1$
- /**
- * takes selected category from editArticleCategorySelectionComboBox and
- * adds the category to the article. location: sell tab, right hand side
- */
- editArticleAddCategoryButton = new JButton(Messages.getString("GUI.AddCategory8")); //$NON-NLS-1$
- editArticleAddCategoryButton.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- String newCategory = (String) editArticleCategorySelectionComboBox
- .getSelectedItem();
- // check because of possible transmission errors
- if (editArticle != null) {
- execute("ADD CATEGORY " + editArticle.getArticleNo() + " " //$NON-NLS-1$ //$NON-NLS-2$
- + newCategory);
- currentArticleCategoriesListModel.add(
- currentArticleCategoriesListModel.size(),
- editArticleCategorySelectionComboBox
- .getSelectedItem());
- }
- }
- });
- /**
- * combobox showing all availible categories while editing article
- * location: sell tab, right hand side
- */
- editArticleCategorySelectionComboBox = new JComboBox(
- updateCategoryData());
- sellTabPanel.add(editArticleCategorySelectionComboBox,
- "10, 18, fill, default");
- sellTabPanel.add(editArticleAddCategoryButton, "12, 18");
- /**
- * checkbox to indicate whether the e-mail address should be visible on
- * article details location: sell tab, left hand side
- */
- chckbxShowEmailOn = new JCheckBox(Messages.getString("GUI.ShowEmailOn")); //$NON-NLS-1$
- sellTabPanel.add(chckbxShowEmailOn, "2, 20, 3, 1"); //$NON-NLS-1$
- /**
- * text field to add a new category to the article being edited
- * location: sell tab, right hand side
- */
- changeArticleDataNewCategoryTextField = new JTextField();
- changeArticleDataNewCategoryTextField.setText(Messages.getString("GUI.NewCategory8")); //$NON-NLS-1$
- changeArticleDataNewCategoryTextField.setColumns(10);
- sellTabPanel.add(changeArticleDataNewCategoryTextField,
- "10, 20, fill, default");
- /**
- * adds a new, formerly unknown, category to the article being edited.
- * checks if the "new" category is really new. if so it adds it to the
- * jlist with the article categories and executes "ADD CATEGORY".
- * location: sell tab, right hand side
- */
- changeArticleDataAddNewCategoryButton = new JButton(Messages.getString("GUI.AddNewCategory8")); //$NON-NLS-1$
- changeArticleDataAddNewCategoryButton
- .addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- boolean alreadyExistingCategory = false;
- // if category name doesn't contain a space character ->
- // continue
- if (checkForMalformedValues(
- changeArticleDataNewCategoryTextField.getText(),
- "category")) { //$NON-NLS-1$
- // check if new category name already exists (if so
- // it's in the categoryselectioncombobox)
- for (int i = 0; i < editArticleCategorySelectionComboBox
- .getItemCount(); i++) {
- if (editArticleCategorySelectionComboBox
- .getItemAt(i).equals(
- changeArticleDataNewCategoryTextField
- .getText())) {
- alreadyExistingCategory = true;
- }
- }
- // category is new? then add it to the list
- if (!alreadyExistingCategory) {
- // adds the selected category from the new
- // category textfield at the end of the selected
- // category list
- currentArticleCategoriesListModel.add(
- currentArticleCategoriesList.getModel()
- .getSize(),
- changeArticleDataNewCategoryTextField
- .getText());
- // check because of possible transmission errors
- if (editArticle != null) {
- execute("ADD CATEGORY " //$NON-NLS-1$
- + editArticle.getArticleNo()
- + " " //$NON-NLS-1$
- + changeArticleDataNewCategoryTextField
- .getText());
- //update category comboboxes with new category data
- categorySelectionComboBox.setModel(updateCategoryData());
- editArticleCategorySelectionComboBox.setModel(updateCategoryData());
- }
- // category already exists? let the user know
- // about that
- } else if (alreadyExistingCategory) {
- JOptionPane
- .showMessageDialog(
- null,
- Messages.getString("GUI.CategoryAlreadyExistsPlease"), //$NON-NLS-1$
- Messages.getString("GUI.CategoryAlreadyExists"), //$NON-NLS-1$
- JOptionPane.WARNING_MESSAGE);
- }
- }
- }
- });
- sellTabPanel.add(changeArticleDataAddNewCategoryButton, "12, 20");
- /**
- * default list model to be able to edit currentArticleCategoriesList
- * data
- */
- currentArticleCategoriesListModel = new DefaultListModel();
- /**
- * jlist containing all categories currently added to the article being
- * edited location: sell tab, right hand side
- */
- currentArticleCategoriesList = new JList(
- currentArticleCategoriesListModel);
- currentArticleCategoriesList
- .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
- currentArticleCategoriesList.setLayoutOrientation(JList.VERTICAL);
- currentArticleCategoriesList.setVisibleRowCount(3);
- /**
- * scroll pane for currentArticleCategoriesList location: sell tab,
- * right hand side
- */
- currentArticleCategoriesListScrollPane = new JScrollPane();
- currentArticleCategoriesListScrollPane
- .setViewportView(currentArticleCategoriesList);
- sellTabPanel.add(currentArticleCategoriesListScrollPane,
- "10, 22, 1, 3, fill, fill");
- /**
- * textfield containing the price of the article being inserted
- * location: sell tab, left hand side
- */
- txtPrice = new JTextField();
- txtPrice.setText(Messages.getString("GUI.Price9")); //$NON-NLS-1$
- sellTabPanel.add(txtPrice, "2, 22, fill, default"); //$NON-NLS-1$
- /**
- * label beside txtPrice. location: sell tab, left hand side
- */
- lblMultiplesOf = new JLabel(Messages.getString("GUI.multiples")); //$NON-NLS-1$
- sellTabPanel.add(lblMultiplesOf, "4, 22"); //$NON-NLS-1$
- changeArticleDataSelectedCategoriesLabel = new JLabel(
- Messages.getString("GUI.selectedCategories6")); //$NON-NLS-1$
- sellTabPanel.add(changeArticleDataSelectedCategoriesLabel, "12, 22"); //$NON-NLS-1$
- /**
- * textfield to enter a auction end date while inserting a new article
- * location: sell tab, left hand side
- */
- txtAuctionEndDate = new JTextField();
- txtAuctionEndDate.setText(Messages.getString("GUI.auctionEndDate")); //$NON-NLS-1$
- sellTabPanel.add(txtAuctionEndDate, "2, 24, fill, default"); //$NON-NLS-1$
- // standard selection is sales item => invisible
- txtAuctionEndDate.setVisible(false);
- /**
- * label indicating the format to be used when entering the auction end
- * date in txtAuctionEndDate. sales item is the standard selection when
- * inserting a new article. the label is invisible by default. location:
- * sell tab, left hand side
- */
- lblFormatYymmdd = new JLabel(Messages.getString("GUI.Format")); //$NON-NLS-1$
- sellTabPanel.add(lblFormatYymmdd, "4, 24, 3, 1"); //$NON-NLS-1$
- //standard selection is sales item => invisible
- lblFormatYymmdd.setVisible(false);
- /**
- * button to enter a new article into the system. checks for various
- * malformations before inserting the article location: sell tab, left
- * hand side
- */
- /**
- * button to remove a category from the jlist containing all categories
- * from the article being edited location: sell tab, right hand side
- */
- changeArticleDataRemoveSelectedCategoryButton = new JButton(
- Messages.getString("GUI.RemoveCatego")); //$NON-NLS-1$
- changeArticleDataRemoveSelectedCategoryButton
- .addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- if (currentArticleCategoriesList.getSelectedIndex() != -1) {
- // check because of possible transmission errors
- if (editArticle != null) {
- execute("DELETE CATEGORY " //$NON-NLS-1$
- + editArticle.getArticleNo()
- + " " //$NON-NLS-1$
- + currentArticleCategoriesList
- .getSelectedValue());
- currentArticleCategoriesListModel
- .remove(currentArticleCategoriesList
- .getSelectedIndex());
- }
- }
- }
- });
- sellTabPanel.add(changeArticleDataRemoveSelectedCategoryButton,
- "12, 24");
- /**
- * textfield to change the price of a salesitem location: sell tab,
- * right hand side
- */
- btnInsertArticle = new JButton(Messages.getString("GUI.insertArticle")); //$NON-NLS-1$
- btnInsertArticle.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- // check for empty or default fields
- if (!txtArticleTitle.getText().isEmpty()
- && !articleDescriptionTextArea.getText().isEmpty()
- && !txtArticleTitle.getText().equals("Article title") //$NON-NLS-1$
- && !articleDescriptionTextArea.getText().equals(
- "Article description")) { //$NON-NLS-1$
- // check if price is properly formed (X.X, multiple of 0.5,
- // no letters, no empty field, no default "price" string)
- if (checkForMalformedValues(txtPrice.getText(), "price")) { //$NON-NLS-1$
- // do you want to add a sales item?
- if (comboBox.getSelectedItem().equals(
- "Insert Sales Item")) { //$NON-NLS-1$
- execute("INSERT SALE \"" //$NON-NLS-1$
- + txtArticleTitle.getText() + "\" " //$NON-NLS-1$
- + txtPrice.getText());
- if (newSetArticleNo != -1) {
- execute("ADD DESCRIPTION " + newSetArticleNo //$NON-NLS-1$
- + " \"" //$NON-NLS-1$
- + articleDescriptionTextArea.getText()
- + "\""); //$NON-NLS-1$
- }
- // or do you want to add an auction article?
- } else if (comboBox.getSelectedItem().equals(
- "Insert Auction Article")) { //$NON-NLS-1$
- // is auction end in format YYMMDD-HHMMSS, not empty
- // and no just filled with default string?
- if (checkForMalformedValues(txtAuctionEndDate
- .getText(), "auctionend")) { //$NON-NLS-1$
- execute("INSERT AUCTION \"" //$NON-NLS-1$
- + txtArticleTitle.getText() + "\" " //$NON-NLS-1$
- + txtPrice.getText() + " " //$NON-NLS-1$
- + txtAuctionEndDate.getText());
- if (newSetArticleNo != -1) {
- execute("ADD DESCRIPTION " //$NON-NLS-1$
- + newSetArticleNo
- + " \"" //$NON-NLS-1$
- + articleDescriptionTextArea
- .getText() + "\""); //$NON-NLS-1$
- }
- }
- }
- // if adding the article was successful, add the other
- // data
- if (newSetArticleNo != -1) {
- String[] categoriesToBeSet = new String[currentCategorySelectionListModel
- .size()];
- currentCategorySelectionListModel
- .copyInto(categoriesToBeSet);
- for (int i = 0; i < categoriesToBeSet.length; i++) {
- execute("ADD CATEGORY " + newSetArticleNo + " " //$NON-NLS-1$ //$NON-NLS-2$
- + categoriesToBeSet[i]);
- }
- if (chckbxShowPhonenoOn.isSelected()) {
- execute("SHOW PHONE " + newSetArticleNo //$NON-NLS-1$
- + " TRUE"); //$NON-NLS-1$
- }
- if (chckbxShowEmailOn.isSelected()) {
- execute("SHOW EMAIL " + newSetArticleNo //$NON-NLS-1$
- + " TRUE"); //$NON-NLS-1$
- }
- JOptionPane.showMessageDialog(null,
- "Your Article was successfully inserted. It has the ArticleNo: "+newSetArticleNo,
- "Article successfully inserted", JOptionPane.WARNING_MESSAGE);
- }
- // reset the articleno value
- newSetArticleNo = -1;
- //TODO Maritjes translations. currently everything is reset to english.
- //reset the rest of the fields in the left half of the sell tab
- currentCategorySelectionListModel.removeAllElements();
- comboBox.setSelectedIndex(0);
- txtArticleTitle.setText("Article title");
- articleDescriptionTextArea.setText("Article description");
- txtNewCategory.setText("new Category");
- chckbxShowPhonenoOn.setSelected(false);
- chckbxShowEmailOn.setSelected(false);
- txtPrice.setText("price");
- txtAuctionEndDate.setText("auction end date");
- }
- // if a field is empty, ask user to fill out all fields
- } else {
- JOptionPane.showMessageDialog(null,
- Messages.getString("GUI.PleaseFill"), //$NON-NLS-1$
- Messages.getString("GUI.MissingInfo"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
- }
- }
- });
- sellTabPanel.add(btnInsertArticle, "2, 26"); //$NON-NLS-1$
- changeArticleDataChangePriceTextField = new JTextField();
- changeArticleDataChangePriceTextField.setText(Messages.getString("GUI.Price0")); //$NON-NLS-1$
- sellTabPanel.add(changeArticleDataChangePriceTextField,
- "10, 26, fill, default");
- /**
- * takes the value from changeArticleDataChangePriceTextField, checks it
- * for malformation and then sets the price to the new value. only works
- * for sales items! location: sell tab, right hand side
- */
- btnSetNewPrice = new JButton(Messages.getString("GUI.setNewPrice1")); //$NON-NLS-1$
- btnSetNewPrice.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- if (checkForMalformedValues(
- changeArticleDataChangePriceTextField.getText(),
- "price")) { //$NON-NLS-1$
- // check because of possible transmission errors
- if (editArticle != null) {
- execute("SET PRICE " //$NON-NLS-1$
- + editArticle.getArticleNo()
- + " " //$NON-NLS-1$
- + changeArticleDataChangePriceTextField
- .getText());
- }
- }
- }
- });
- sellTabPanel.add(btnSetNewPrice, "12, 26");
- /**
- * messagetab
- */
- messagePanel = new JPanel();
- tabbedPane.addTab(Messages.getString("GUI.Messages1"), null, messagePanel, null); //$NON-NLS-1$
- messagePanel.setLayout(new FormLayout(
- new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC,
- FormFactory.DEFAULT_COLSPEC,
- FormFactory.RELATED_GAP_COLSPEC,
- FormFactory.DEFAULT_COLSPEC,
- FormFactory.RELATED_GAP_COLSPEC,
- FormFactory.DEFAULT_COLSPEC,
- FormFactory.RELATED_GAP_COLSPEC,
- ColumnSpec.decode("650px"), //$NON-NLS-1$
- FormFactory.RELATED_GAP_COLSPEC,
- FormFactory.DEFAULT_COLSPEC,
- FormFactory.RELATED_GAP_COLSPEC,
- FormFactory.DEFAULT_COLSPEC, }, new RowSpec[] {
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC, }));
- /**
- * gets all messages for the user from the server and shows them in a
- * table
- */
- btnShowMessages = new JButton(Messages.getString("GUI.showMessages1")); //$NON-NLS-1$
- btnShowMessages.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- execute("SHOW MESSAGES"); //$NON-NLS-1$
- String[] columnNamesMessagelist = { Messages.getString("GUI.SendDate"), //$NON-NLS-1$
- Messages.getString("GUI.Title0"), Messages.getString("GUI.MessageContent") }; //$NON-NLS-1$ //$NON-NLS-2$
- Object[][] dataMessagelist = new Object[messageList.size()][columnNamesMessagelist.length];
- // if messages exist, show them
- if (messageList.size() != 0) {
- int counter = 0;
- Iterator<Message> it = messageList.iterator();
- while (it.hasNext()) {
- Message actual = it.next();
- dataMessagelist[counter][0] = gregorianToString(actual
- .getSendDate(), "short"); //$NON-NLS-1$
- dataMessagelist[counter][1] = actual.getTitle();
- dataMessagelist[counter][2] = actual.getMsgText();
- counter++;
- }
- }
- messageTable = new JTable(new MyTableModel(columnNamesMessagelist, dataMessagelist));
- messageTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
- // senddate column
- messageTable.getColumnModel().getColumn(0).setPreferredWidth(
- 125);
- // title column
- messageTable.getColumnModel().getColumn(1).setPreferredWidth(
- 150);
- // message content column
- messageTable.getColumnModel().getColumn(2).setPreferredWidth(
- 650);
- messageTable.setAutoCreateRowSorter(true);
- messageTableScrollPane.setViewportView(messageTable);
- }
- });
- messagePanel.add(btnShowMessages, "2, 2"); //$NON-NLS-1$
- /**
- * sends the remove oldmessages command to the server and then updates
- * the message table
- */
- btnHideOldMessages = new JButton(Messages.getString("GUI.HideOldMsg")); //$NON-NLS-1$
- btnHideOldMessages.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- execute("REMOVE OLDMESSAGES"); //$NON-NLS-1$
- // buton.doClick() doesn't work because it's a mouseevent. so i
- // have to reuse the code
- execute("SHOW MESSAGES"); //$NON-NLS-1$
- String[] columnNamesMessagelist = { Messages.getString("GUI.SendDate()"), //$NON-NLS-1$
- Messages.getString("GUI.title0"), Messages.getString("GUI.messageConent") }; //$NON-NLS-1$ //$NON-NLS-2$
- Object[][] dataMessagelist = new Object[messageList.size()][columnNamesMessagelist.length];
- // if messages exist, show them
- if (messageList.size() != 0) {
- int counter = 0;
- Iterator<Message> it = messageList.iterator();
- while (it.hasNext()) {
- Message actual = it.next();
- dataMessagelist[counter][0] = gregorianToString(actual
- .getSendDate(), "short"); //$NON-NLS-1$
- dataMessagelist[counter][1] = actual.getTitle();
- dataMessagelist[counter][2] = actual.getMsgText();
- counter++;
- }
- }
- messageTable = new JTable(new MyTableModel(columnNamesMessagelist, dataMessagelist));
- messageTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
- // senddate column
- messageTable.getColumnModel().getColumn(0).setPreferredWidth(
- 125);
- // title column
- messageTable.getColumnModel().getColumn(1).setPreferredWidth(
- 150);
- // message content column
- messageTable.getColumnModel().getColumn(2).setPreferredWidth(
- 650);
- messageTable.setAutoCreateRowSorter(true);
- messageTableScrollPane.setViewportView(messageTable);
- }
- });
- messagePanel.add(btnHideOldMessages, "4, 2"); //$NON-NLS-1$
- messageTableScrollPane = new JScrollPane();
- messagePanel.add(messageTableScrollPane, "2, 4, 7, 1, fill, fill"); //$NON-NLS-1$
- messageTable = new JTable();
- String[] columnNamesMessagelist = {"Send date (YY.MM.DD)", "Title", "Message content"};
- messageTable.setModel(new MyTableModel(columnNamesMessagelist, new Object[0][0]));
- messageTableScrollPane.setViewportView(messageTable);
- /**
- * user control tab
- */
- userControlCenterPanel = new JPanel();
- tabbedPane.addTab(Messages.getString("GUI.UCC3"), null, userControlCenterPanel, //$NON-NLS-1$
- null);
- userControlCenterPanel.setLayout(new FormLayout(new ColumnSpec[] {
- FormFactory.RELATED_GAP_COLSPEC,
- FormFactory.DEFAULT_COLSPEC,
- FormFactory.RELATED_GAP_COLSPEC,
- ColumnSpec.decode("max(40dlu;default)"), //$NON-NLS-1$
- FormFactory.RELATED_GAP_COLSPEC,
- ColumnSpec.decode("left:max(87dlu;default)"), //$NON-NLS-1$
- ColumnSpec.decode("max(33dlu;default)"), //$NON-NLS-1$
- FormFactory.RELATED_GAP_COLSPEC,
- ColumnSpec.decode("max(100dlu;pref)"),
- FormFactory.RELATED_GAP_COLSPEC,
- FormFactory.DEFAULT_COLSPEC,
- FormFactory.RELATED_GAP_COLSPEC,
- ColumnSpec.decode("20px"),
- FormFactory.RELATED_GAP_COLSPEC,
- ColumnSpec.decode("max(113dlu;default)"), //$NON-NLS-1$
- FormFactory.RELATED_GAP_COLSPEC,
- ColumnSpec.decode("100px"),
- FormFactory.RELATED_GAP_COLSPEC,
- ColumnSpec.decode("max(34dlu;default)"),},
- new RowSpec[] {
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- FormFactory.DEFAULT_ROWSPEC,
- FormFactory.RELATED_GAP_ROWSPEC,
- RowSpec.decode("default:grow"),}));
- /**
- * label in user data change panel location: user control center tab,
- * upper window area
- */
- lblChange = new JLabel(Messages.getString("GUI.Change0")); //$NON-NLS-1$
- userControlCenterPanel.add(lblChange, "4, 4, right, default"); //$NON-NLS-1$
- /**
- * values that can be changed for combobox
- */
- /**
- * combobox containing all values that can be changed by the user
- * location: user control center tab, upper window area
- */
- comboBoxChangeUserdata = new JComboBox(LanguagePack.possibleChangeValues());
- comboBoxChangeUserdata.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- changeSuccessLabel.setText("");
- }
- });
- userControlCenterPanel.add(comboBoxChangeUserdata,
- "6, 4, fill, default"); //$NON-NLS-1$
- /**
- * label in user data change panel location: user control center tab,
- * upper window area
- */
- lblTo = new JLabel(Messages.getString("GUI.to")); //$NON-NLS-1$
- userControlCenterPanel.add(lblTo, "7, 4, center, default"); //$NON-NLS-1$
- /**
- * textfield containing the new value for the value to be changed
- * location: user control center tab, upper window area
- */
- txtChangeNewValue = new JTextField();
- userControlCenterPanel.add(txtChangeNewValue, "9, 4, fill, default"); //$NON-NLS-1$
- /**
- * button to execute change in user data. various checks are performed
- * before changing the value location: user control center tab, upper
- * window area
- */
- btnChangeOk = new JButton(Messages.getString("GUI.ok")); //$NON-NLS-1$
- btnChangeOk.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- // password change
- if (comboBoxChangeUserdata.getSelectedItem().equals("password")) { //$NON-NLS-1$
- if (checkForMalformedValues(txtChangeNewValue.getText(),
- "password")) { //$NON-NLS-1$
- execute("CHANGE USER " + usernameTempSaved //$NON-NLS-1$
- + " PASSWORD " + txtChangeNewValue.getText()); //$NON-NLS-1$
- }
- // last name change
- } else if (comboBoxChangeUserdata.getSelectedItem().equals(
- "last name")) { //$NON-NLS-1$
- execute("CHANGE USER " + usernameTempSaved + " LASTNAME \"" //$NON-NLS-1$ //$NON-NLS-2$
- + txtChangeNewValue.getText() + "\""); //$NON-NLS-1$
- // first name change
- } else if (comboBoxChangeUserdata.getSelectedItem().equals(
- "first name")) { //$NON-NLS-1$
- execute("CHANGE USER " + usernameTempSaved //$NON-NLS-1$
- + " FIRSTNAME \"" + txtChangeNewValue.getText() //$NON-NLS-1$
- + "\""); //$NON-NLS-1$
- // dateofbirth change
- } else if (comboBoxChangeUserdata.getSelectedItem().equals(
- "birthday")) { //$NON-NLS-1$
- if (checkForMalformedValues(txtChangeNewValue.getText(),
- "dateofbirth")) { //$NON-NLS-1$
- execute("CHANGE USER " + usernameTempSaved //$NON-NLS-1$
- + " BIRTHDAY " + txtChangeNewValue.getText()); //$NON-NLS-1$
- }
- // street change
- } else if (comboBoxChangeUserdata.getSelectedItem().equals(
- "street")) { //$NON-NLS-1$
- execute("CHANGE USER " + usernameTempSaved + " STREET \"" //$NON-NLS-1$ //$NON-NLS-2$
- + txtChangeNewValue.getText() + "\""); //$NON-NLS-1$
- // zip change
- } else if (comboBoxChangeUserdata.getSelectedItem().equals(
- "zip")) { //$NON-NLS-1$
- if (checkForMalformedValues(txtChangeNewValue.getText(),
- "zip")) { //$NON-NLS-1$
- execute("CHANGE USER " + usernameTempSaved + " ZIP " //$NON-NLS-1$ //$NON-NLS-2$
- + txtChangeNewValue.getText());
- }
- // location change
- } else if (comboBoxChangeUserdata.getSelectedItem().equals(
- "location")) { //$NON-NLS-1$
- execute("CHANGE USER " + usernameTempSaved + " CITY \"" //$NON-NLS-1$ //$NON-NLS-2$
- + txtChangeNewValue.getText() + "\""); //$NON-NLS-1$
- // phone change
- } else if (comboBoxChangeUserdata.getSelectedItem().equals(
- "phone")) { //$NON-NLS-1$
- if (checkForMalformedValues(txtChangeNewValue.getText(),
- "phoneno")) { //$NON-NLS-1$
- execute("CHANGE USER " + usernameTempSaved + " PHONE " //$NON-NLS-1$ //$NON-NLS-2$
- + txtChangeNewValue.getText());
- }
- // email change
- // TODO deutsche Begriffe
- } else if (comboBoxChangeUserdata.getSelectedItem().equals(
- "e-mail")) { //$NON-NLS-1$
- if (checkForMalformedValues(txtChangeNewValue.getText(),
- "email")) { //$NON-NLS-1$
- execute("CHANGE USER " + usernameTempSaved + " EMAIL " //$NON-NLS-1$ //$NON-NLS-2$
- + txtChangeNewValue.getText());
- }
- }
- // change user was successful
- if (changeBool) {
- changeSuccessLabel.setText("Value successfully changed!"); //$NON-NLS-1$
- // reset changeBool
- changeBool = false;
- }
- }
- });
- userControlCenterPanel.add(btnChangeOk, "11, 4"); //$NON-NLS-1$
- /**
- * empty label to get some space between btnChangeOk and
- * changeSuccessLabel location: user control center tab, upper window
- * area
- */
- changeUserLabel = new JLabel(""); //$NON-NLS-1$
- userControlCenterPanel.add(changeUserLabel, "13, 4"); //$NON-NLS-1$
- /**
- * label indicating when user data change was successful location: user
- * control center tab, upper window area
- */
- changeSuccessLabel = new JLabel(""); //$NON-NLS-1$
- userControlCenterPanel.add(changeSuccessLabel, "15, 4"); //$NON-NLS-1$
- /**
- * panel with admin functions location: user control center tab, under
- * change value area
- */
- adminPanel = new JPanel();
- // adminpanel is invisible by default
- adminPanel.setVisible(false);
- userControlCenterPanel.add(adminPanel, "4, 8, 14, 1, left, fill"); //$NON-NLS-1$
- adminPanel.setLayout(new BorderLayout(0, 0));
- /**
- * panel on adminPanel containing all the elements
- */
- adminControlsPanel = new JPanel();
- adminPanel.add(adminControlsPanel, BorderLayout.NORTH);
- /**
- * textfield containing the username of the user to be edited. location:
- * user control center tab, under change value area
- */
- txtUsernameToEdit = new JTextField();
- txtUsernameToEdit.setText(Messages.getString("GUI.UserToEdit")); //$NON-NLS-1$
- adminControlsPanel.add(txtUsernameToEdit);
- /**
- * button that deletes the user entered in txtUsernameToEdit. before
- * deleting a check is performed whether the user still has articles
- * entered into the system. if so the admin has to confirm if the user
- * should be deleted anyways location: user control center tab, under
- * change value area
- */
- btnDelete = new JButton(Messages.getString("GUI.Delete0")); //$NON-NLS-1$
- btnDelete.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- String userToBeDeleted = txtUsernameToEdit.getText();
- // request articles by user to be deleted to see if he still has
- // listed articles
- execute("LIST USER " + userToBeDeleted); //$NON-NLS-1$
- // check is username is malformed
- if (checkForMalformedValues(userToBeDeleted, "username")) { //$NON-NLS-1$
- // are articles by user to be deleted in the system?
- // no. delete him right away
- if (articleList.size() == 0) {
- execute("DELETE USER " + userToBeDeleted); //$NON-NLS-1$
- // yes. check back with admin
- } else {
- Object[] options = { Messages.getString("GUI.YesDelete") + userToBeDeleted, //$NON-NLS-1$
- Messages.getString("GUI.NoDeleteHim") }; //$NON-NLS-1$
- int n = JOptionPane
- .showOptionDialog(
- frame,
- Messages.getString("GUI.DoYoureallyDelte") //$NON-NLS-1$
- + userToBeDeleted
- + Messages.getString("GUI.evenThoughHeStill"), //$NON-NLS-1$
- Messages.getString("GUI.DeletionWarning"), //$NON-NLS-1$
- JOptionPane.YES_NO_CANCEL_OPTION,
- JOptionPane.QUESTION_MESSAGE, null,
- options, options[1]);
- if (n == 0) {
- execute("DELETE USER " + userToBeDeleted); //$NON-NLS-1$
- }
- }
- }
- }
- });
- adminControlsPanel.add(btnDelete);
- /**
- * locks the username entered in txtUsernameToEdit location: user
- * control center tab, under change value area
- */
- btnLock = new JButton(Messages.getString("GUI.Lock")); //$NON-NLS-1$
- btnLock.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- String userToBeLocked = txtUsernameToEdit.getText();
- // check if username is malformed
- if (checkForMalformedValues(userToBeLocked, "username")) { //$NON-NLS-1$
- execute("LOCK USER " + userToBeLocked); //$NON-NLS-1$
- // user was successfully locked
- if (lockBool) {
- JOptionPane.showMessageDialog(null, Messages.getString("GUI.user0") //$NON-NLS-1$
- + userToBeLocked + Messages.getString("GUI.successfullyLocked"), //$NON-NLS-1$
- Messages.getString("GUI.UsersuccessfullyLocked"), //$NON-NLS-1$
- JOptionPane.WARNING_MESSAGE);
- // user was not successfully locked. user doesn't exist
- // etc.
- } else if (!lockBool) {
- JOptionPane
- .showMessageDialog(null, Messages.getString("GUI.User01") //$NON-NLS-1$
- + userToBeLocked
- + Messages.getString("GUI.coudntLock"), //$NON-NLS-1$
- Messages.getString("GUI.UserFailed"), //$NON-NLS-1$
- JOptionPane.WARNING_MESSAGE);
- }
- }
- }
- });
- adminControlsPanel.add(btnLock);
- /**
- * unlocks the username entered in txtUsernameToEdit location: user
- * control center tab, under change value area
- */
- btnUnlock = new JButton(Messages.getString("GUI.Unlock")); //$NON-NLS-1$
- btnUnlock.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- String userToBeUnlocked = txtUsernameToEdit.getText();
- // check if username is malformed
- if (checkForMalformedValues(userToBeUnlocked, "username")) { //$NON-NLS-1$
- execute("UNLOCK USER " + userToBeUnlocked); //$NON-NLS-1$
- // user was successfully unlocked
- if (unlockBool) {
- JOptionPane.showMessageDialog(null, Messages.getString("GUI.User02") //$NON-NLS-1$
- + userToBeUnlocked + Messages.getString("GUI.successfullyUnlocked"), //$NON-NLS-1$
- Messages.getString("GUI.UsersuccessfullyUnlocked"), //$NON-NLS-1$
- JOptionPane.WARNING_MESSAGE);
- // user was not successfully unlocked. user doesn't
- // exist etc.
- } else if (!unlockBool) {
- JOptionPane
- .showMessageDialog(
- null,
- Messages.getString("GUI.User03") //$NON-NLS-1$
- + userToBeUnlocked
- + Messages.getString("GUI.NotBeUnlocked"), //$NON-NLS-1$
- Messages.getString("GUI.UnlockedUser"), //$NON-NLS-1$
- JOptionPane.WARNING_MESSAGE);
- }
- }
- }
- });
- adminControlsPanel.add(btnUnlock);
- /**
- * lists all users location: user control center tab, under change value
- * area
- */
- btnShowUsers = new JButton(Messages.getString("GUI.ShowUsers0")); //$NON-NLS-1$
- btnShowUsers.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- String[] columnNamesUserlist = { Messages.getString("GUI.LastName0"), Messages.getString("GUI.FirstName0"), //$NON-NLS-1$ //$NON-NLS-2$
- 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$
- Messages.getString("GUI.Location0"), Messages.getString("GUI.PhoneNo0"), Messages.getString("GUI.email0") }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- execute("SHOW USERS"); //$NON-NLS-1$
- Object[][] dataUserlist = new Object[userList.size()][10];
- if (userList.size() != 0) {
- // counter to prevent running out of array bounds
- int counter = 0;
- Iterator<User> it = userList.iterator();
- // add one after another. list already sorted by last name
- // and first name on serverside
- while (it.hasNext()) {
- User actual = it.next();
- dataUserlist[counter][0] = actual.getLastName();
- dataUserlist[counter][1] = actual.getFirstName();
- dataUserlist[counter][2] = actual.getUsername();
- dataUserlist[counter][3] = actual.isLocked();
- dataUserlist[counter][4] = gregorianToString(actual
- .getDateOfBirth(), "short"); //$NON-NLS-1$
- dataUserlist[counter][5] = actual.getStreet();
- dataUserlist[counter][6] = actual.getZip();
- dataUserlist[counter][7] = actual.getLocation();
- dataUserlist[counter][8] = actual.getPhoneNo();
- dataUserlist[counter][9] = actual.getEmail();
- counter++;
- }
- }
- /**
- * table containing all the user data
- */
- adminArticleTable = new JTable(dataUserlist,
- columnNamesUserlist);
- adminArticleTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
- adminArticleTable.setAutoCreateRowSorter(true);
- adminArticleTableScrollPane.setViewportView(adminArticleTable);
- }
- });
- adminControlsPanel.add(btnShowUsers);
- /**
- * shows all messages entered in the system
- */
- btnShowAllMessages = new JButton(Messages.getString("GUI.ShowAllMsgs0")); //$NON-NLS-1$
- btnShowAllMessages.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- execute("SHOW MESSAGES"); //$NON-NLS-1$
- String[] columnNamesMessagelist = { Messages.getString("GUI.to0"), Messages.getString("GUI.sendDate0"), Messages.getString("GUI.Title0"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- Messages.getString("GUI.MessageContent") }; //$NON-NLS-1$
- Object[][] dataMessagelist = new Object[messageList.size()][columnNamesMessagelist.length];
- // if messages exist, show them
- if (messageList.size() != 0) {
- int counter = 0;
- Iterator<Message> it = messageList.iterator();
- while (it.hasNext()) {
- Message actual = it.next();
- dataMessagelist[counter][0] = actual.getReceiver()
- .getUsername();
- dataMessagelist[counter][1] = gregorianToString(actual
- .getSendDate(), "short"); //$NON-NLS-1$
- dataMessagelist[counter][2] = actual.getTitle();
- dataMessagelist[counter][3] = actual.getMsgText();
- counter++;
- }
- }
- /**
- * table containing all the messages
- */
- adminArticleTable = new JTable(dataMessagelist,
- columnNamesMessagelist);
- adminArticleTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
- adminArticleTable.setAutoCreateRowSorter(true);
- adminArticleTableScrollPane.setViewportView(adminArticleTable);
- }
- });
- adminControlsPanel.add(btnShowAllMessages);
- /**
- * shows all the articles entered by the user entered in
- * txtUsernameToEdit
- */
- btnShowArticles = new JButton(Messages.getString("GUI.showArticlesByUser")); //$NON-NLS-1$
- btnShowArticles.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- String[] columnNamesArticleListAdmin = { Messages.getString("GUI.ArticleNo0"), Messages.getString("GUI.Title01"), //$NON-NLS-1$ //$NON-NLS-2$
- Messages.getString("GUI.decription0"), Messages.getString("GUI.currentPrice01"), Messages.getString("GUI.TimeLeft01"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- Messages.getString("GUI.VendorName") }; //$NON-NLS-1$
- String articlesByUser = txtUsernameToEdit.getText();
- if (checkForMalformedValues(articlesByUser, Messages.getString("GUI.UserName0"))) { //$NON-NLS-1$
- execute("LIST USER " + articlesByUser); //$NON-NLS-1$
- Object[][] data = new Object[articleList.size()][6];
- if (articleList.size() != 0) {
- // counter to prevent running out of array bounds
- int counter = 0;
- // first the salesitems
- Iterator<Article> it = articleList.iterator();
- while (it.hasNext()) {
- Object actual = it.next();
- if (actual.getClass().getSimpleName().equals(
- "SalesItem")) { //$NON-NLS-1$
- data[counter][0] = ((SalesItem) actual)
- .getArticleNo();
- data[counter][1] = ((SalesItem) actual)
- .getTitle();
- data[counter][2] = ((SalesItem) actual)
- .getDescription();
- data[counter][3] = ((SalesItem) actual)
- .getPrice();
- data[counter][4] = ""; //$NON-NLS-1$
- data[counter][5] = ((SalesItem) actual)
- .getVendor();
- counter++;
- }
- }
- // then the auction items
- Iterator<Article> it2 = articleList.iterator();
- while (it2.hasNext()) {
- Object actual = it2.next();
- if (actual.getClass().getSimpleName().equals(
- "AuctionArticle")) { //$NON-NLS-1$
- data[counter][0] = ((AuctionArticle) actual)
- .getArticleNo();
- data[counter][1] = ((AuctionArticle) actual)
- .getTitle();
- data[counter][2] = ((AuctionArticle) actual)
- .getDescription();
- //if the minbiddingprice is higher than the currentmaxbid the minbidding price is shown
- //this should ONLY be the case if there is no bid yet. then the currentmaxbid is 0.00
- if( ((AuctionArticle) actual).getMinBiddingPrice() > ((AuctionArticle) actual).getCurrentMaxBid() ){
- data[counter][3] = ((AuctionArticle) actual).getMinBiddingPrice();
- //if the currentmaxbid is higher than the minbiddingprice show the currentmax bid
- }else{
- data[counter][3] = ((AuctionArticle) actual)
- .getCurrentMaxBid();
- }
- data[counter][4] = dateDifferenceToString(((AuctionArticle) actual)
- .getAuctionEnd());
- data[counter][5] = ((AuctionArticle) actual)
- .getVendor();
- counter++;
- }
- }
- /**
- * table containing all the article data
- */
- adminArticleTable = new JTable(data,
- columnNamesArticleListAdmin);
- adminArticleTable
- .setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
- adminArticleTable.setAutoCreateRowSorter(true);
- adminArticleTableScrollPane
- .setViewportView(adminArticleTable);
- }
- }
- }
- });
- adminControlsPanel.add(btnShowArticles);
- /**
- * east side of admincontrolpanel
- */
- adminControlsPanel2 = new JPanel();
- adminPanel.add(adminControlsPanel2, BorderLayout.EAST);
- /**
- * deletes the article selected from the article table
- */
- btnDeleteArticle = new JButton(Messages.getString("GUI.DeleteSelectedArticle")); //$NON-NLS-1$
- btnDeleteArticle.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent arg0) {
- // hardcoded column 0 because articleNo is always in column 0
- int articleNoToBeDeleted = (Integer) adminArticleTable
- .getValueAt(adminArticleTable.getSelectedRow(), 0);
- execute("DELETE ARTICLE " + articleNoToBeDeleted); //$NON-NLS-1$
- if (deleteArticleBool) {
- JOptionPane.showMessageDialog(null, Messages.getString("GUI.Article04") //$NON-NLS-1$
- + articleNoToBeDeleted + Messages.getString("GUI.successfullyDeleted"), //$NON-NLS-1$
- Messages.getString("GUI.ArticleDelte01"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
- } else if (!deleteArticleBool) {
- JOptionPane.showMessageDialog(null, Messages.getString("GUI.Article711") //$NON-NLS-1$
- + articleNoToBeDeleted + Messages.getString("GUI.CouldntDeleted712"), //$NON-NLS-1$
- Messages.getString("GUI.ArticleFailed713"), //$NON-NLS-1$
- JOptionPane.WARNING_MESSAGE);
- }
- }
- });
- adminControlsPanel2.add(btnDeleteArticle);
- /**
- * scroll panel for adminArticleTable
- */
- adminArticleTableScrollPane = new JScrollPane();
- adminPanel.add(adminArticleTableScrollPane, BorderLayout.CENTER);
- // remove sell tab
- tabbedPane.removeTabAt(1);
- // remove message tab
- tabbedPane.removeTabAt(1);
- // remove usercontrolcenter tab
- tabbedPane.removeTabAt(1);
- // hide article details in buy tab until a user logs in
- articleDetailsPanel.setVisible(false);
- btnShowArticleDetails.setVisible(false);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement