Package test

Examples of test.ShoppingItem


  storageControllerPanel = new JPanel();
  diskPanel = new JPanel();
  buttonPanel = new JPanel();

  shoppingItem = new ArrayList <ShoppingItem>();
  item = new ShoppingItem();

  baseUnitLabel = new JLabel("Base Unit ");
  storageControllerLabel = new JLabel("Storage Controller");
  diskLabel = new JLabel("Disk");
  descriptionLabel = new JLabel("Description");

  serverBox = new JComboBox();
  serverBox.setEnabled(false);
  laptopBox = new JComboBox ();
  laptopBox.setEnabled(false);
  storageControllerBox = new JComboBox();
  storageControllerBox.setEnabled(false);
  diskBox = new JComboBox();
  diskBox.setEnabled(false);

  serverButton = new JRadioButton("Server ");
  serverButton.setSelected(false);
  laptopButton = new JRadioButton("Laptop ");
  buttonGroup = new ButtonGroup();

  descriptionField = new JTextField();

  addSc = new JButton("Add Storage");
  addSc.setEnabled(false);
  addDisk = new JButton("Add Disk");
  addDisk.setEnabled(false);
  checkOutButton = new JButton("Check Out & View the Shopping list");
  checkOutButton.setEnabled(false);

  SwingUtilities.invokeLater(new Runnable() {
   public void run() {
    createAndShowGUI();
   }
  });

  serverButton.addActionListener (new ActionListener() {
   public void actionPerformed(ActionEvent ae){
    ++serverChanged;

    serverBox.setEnabled(true);
    laptopBox.setEnabled(false);
    storageControllerBox.setEnabled(true);
    addSc.setEnabled(true);
    diskBox.setEnabled(true);
    addDisk.setEnabled(true);
   }

  });

  laptopButton.addActionListener (new ActionListener() {
   public void actionPerformed(ActionEvent ae){
    ++laptopChanged;
    laptopBox.setEnabled(true);
    serverBox.setEnabled(false);
    storageControllerBox.setEnabled(false);
    addSc.setEnabled(false);
    diskBox.setEnabled(true);
    addDisk.setEnabled(true);
   }
  });

  for (ServerInfo sii: ss.getServerInfos()) {
   serverBox.addItem(sii.getModel());
  }

  for (LaptopInfo lii: ls.getLaptopInfos()) {
   laptopBox.addItem(lii.getModel());
  }

  for (StorageControllerInfo scii: scs.getStorageControllerInfos()) {
   storageControllerBox.addItem(scii.getModel());
  }

  for (DiskInfo dii: ds.getDiskInfos()) {
   diskBox.addItem(dii.getModel());
  }

  serverBox.addItemListener(new ItemListener(){
   public void itemStateChanged(ItemEvent ie){

    ++serverChanged;
    storageControllerBox.setEnabled(true);
    addSc.setEnabled(true);
    diskBox.setEnabled(true);
    addDisk.setEnabled(true);

    descriptionField.setText(null);
    String model = (String)serverBox.getSelectedItem();
    int warehouseId = 0;
    String manufacturer = null;
    try {
     for (ServerInfo si: ss.getServerInfos()) {
      if (model.equals(si.getModel()) ) {
       warehouseId = si.getWareHouseID();
       manufacturer = si.getManufacturer();
       continue;
      }
     }
    } catch (IOException e) {
     e.printStackTrace();
    }
    descriptionField.setText("Warehouse ID: " + warehouseId +  " Manufacturer : " + manufacturer + " Model : " + model );
   }
  });

  laptopBox.addItemListener(new ItemListener(){
   public void itemStateChanged(ItemEvent ie){

    ++laptopChanged;
    diskBox.setEnabled(true);
    addDisk.setEnabled(true);
    descriptionField.setText(null);
    String model = (String)laptopBox.getSelectedItem();
    int warehouseId = 0;
    String manufacturer = null;

    try {
     for (LaptopInfo li: ls.getLaptopInfos()) {
      if (model.equals(li.getModel()) ) {
       warehouseId = li.getWareHouseID();
       manufacturer = li.getManufacturer();
       continue;
      }
     }
    } catch (IOException e) {
     e.printStackTrace();
    }
    descriptionField.setText("Warehouse ID: " + warehouseId +  " Manufacturer : " + manufacturer + " Model : " + model );
   }
  });

  storageControllerBox.addItemListener(new ItemListener(){
   public void itemStateChanged(ItemEvent ie){
    descriptionField.setText(null);
    String model = (String)storageControllerBox.getSelectedItem();
    int warehouseId = 0;
    String manufacturer = null;

    try {
     for (StorageControllerInfo sci: scs.getStorageControllerInfos()) {
      if (model.equals(sci.getModel()) ) {
       warehouseId = sci.getWareHouseID();
       manufacturer = sci.getManufacturer();
       continue;
      }
     }
    } catch (IOException e) {
     e.printStackTrace();
    }
    descriptionField.setText("Warehouse ID: " + warehouseId +  " Manufacturer : " + manufacturer + " Model : " + model );
   }
  });


  diskBox.addItemListener(new ItemListener(){
   public void itemStateChanged(ItemEvent ie){
    descriptionField.setText(null);
    String model = (String)diskBox.getSelectedItem();
    int warehouseId = 0;
    String manufacturer = null;
    try {
     for (DiskInfo di: ds.getDiskInfos()) {
      if (model.equals(di.getModel()) ) {
       warehouseId = di.getWareHouseID();
       manufacturer = di.getManufacturer();
       continue;
      }
     }
    } catch (IOException e) {
     e.printStackTrace();
    }
    descriptionField.setText("Warehouse ID: " + warehouseId +  " Manufacturer : " + manufacturer + " Model : " + model );
   }
  });

  addSc.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent evt) {
    serverSelected = (String)serverBox.getSelectedItem();
    sCSelected = (String)storageControllerBox.getSelectedItem();
    boolean valid =true;
    item = new ShoppingItem();
    checkOutButton.setEnabled(true);

    try {
     for (ServerInfo sii: ss.getServerInfos()) {
      if (serverSelected.equals(sii.getModel())  && (serverChanged > 0)) {
       si = sii;
       sIList.add(sii);
       item.setsManufacturer(sii.getManufacturer());
       item.setsModel(sii.getModel());
       item.setsWarehouseId(sii.getWareHouseID());
       shoppingItem.add(item);
       serverChanged = 0;
      }
     }
     item = new ShoppingItem();
     for (StorageControllerInfo scii: scs.getStorageControllerInfos()) {
      if (sCSelected.equals(scii.getModel() ) ) {
       sCIList.add(scii);
       valid = ss.validate(si, sCIList);
       if (valid == false) {
        JOptionPane.showMessageDialog(null,"Storage control with BUS " +
          "PCI more than what is allowed with this type of Server");
        sCIList.remove(scii);
       }
       else {
        item.setsCManufacturer(scii.getManufacturer());
        item.setsCModel(scii.getModel());
        item.setsCWarehouseId(scii.getWareHouseID());
        shoppingItem.add(item);
       }
      }      
     }

    } catch (IOException e) {
     e.printStackTrace();
    }
   }
  });

  addDisk.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent evt) {
    checkOutButton.setEnabled(true);

    if (serverButton.isSelected()) {
     sCSelected = (String)storageControllerBox.getSelectedItem();
     diskSelected = (String)diskBox.getSelectedItem();
     item = new ShoppingItem();
     boolean valid = true;
     try {
      for (StorageControllerInfo scii: scs.getStorageControllerInfos()) {
       if (sCSelected.equals(scii.getModel())) {
        sci = scii;
       }
      }
      for (DiskInfo dii: ds.getDiskInfos()) {
       if (diskSelected.equals(dii.getModel())) {
        valid = scs.validate(sci, dii);
        if (valid) {
         dServerList.add(dii);
         item.setsdManufacturer(dii.getManufacturer());
         item.setsdModel(dii.getModel());
         item.setsdWarehouseId(dii.getWareHouseID());
         shoppingItem.add(item);

        }
        else {
         JOptionPane.showMessageDialog(null,"Disk port and Disk is not compatible (Compatible: " +
           "SCSI -> SCSI, SAS -> (SAS & SATA), SATA -> SATA )");
         break;
        }
       }
      }
     }
     catch (IOException e) {
      e.printStackTrace();
     }
    }
    if (laptopButton.isSelected()) {
     laptopSelected = (String)laptopBox.getSelectedItem();
     diskSelected = (String)diskBox.getSelectedItem();
     item = new ShoppingItem();
     boolean valid = true;
     try {
      for (LaptopInfo lii: ls.getLaptopInfos()) {
       if (laptopSelected.equals(lii.getModel()) && (laptopChanged > 0)) {
        lIList.add(lii);
        item.setlManufacturer(lii.getManufacturer());
        item.setlModel(lii.getModel());
        item.setlWarehouseId(lii.getWareHouseID());
        shoppingItem.add(item);
        laptopChanged = 0;
       }
      }
      item = new ShoppingItem();
      for (DiskInfo dii: ds.getDiskInfos()) {
       if (diskSelected.equals(dii.getModel())) {
        valid = ls.validate(dii);
        if (valid) {
         dLaptopList.add(dii);
View Full Code Here

TOP

Related Classes of test.ShoppingItem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.