public void actionPerformed(ActionEvent e) {
   try {
     String scannedDestination = ((JTextField) e.getSource()).getText().toUpperCase();
     validateDestinationScan(scannedDestination);
     DefaultListModel listModel = (DefaultListModel) destinationsList.getModel();
     int lastPosition = listModel.getSize();
     int seedsCount = 0;
     // todo: do we have to worry about more trays than required..?
     for (int i = 0; i < seedPlates.length; i++) {
       if (seedPlates[i].getSeedPlateBarcode() != null
           && SCANNED.equals(seedPlates[i].getStatus())
           && !isContainedInList(seedPlates[i].getSeedPlateBarcode(), failedPlatesList)) {
         seedsCount++;
       }
     }
     if (lastPosition >= seedsCount) {
       throw new ChippingManagerException(DESTINATIONS_LIMIT_EXCEEDED);
     }
     addDestination(scannedDestination);
   } catch (Throwable cmException) {
     logger.error("Unable to scan destination ", cmException);
     JOptionPane.showMessageDialog(
         new JFrame(),
         cmException.getMessage(),
         TITLE_CHIPPING_MANAGER,
         JOptionPane.WARNING_MESSAGE);
   }
   scanDestination.setText(BLANK);
 }
 public void actionPerformed(ActionEvent e) {
   DefaultListModel listModel = null;
   if (((JButton) e.getSource()).getName().equals(REMOVE_ALL)) {
     listModel = (DefaultListModel) failedPlatesList.getModel();
   } else {
     listModel = (DefaultListModel) destinationsList.getModel();
   }
   listModel.removeAllElements();
 }
 private int findDestinationListIndex(
     DefaultListModel destinationsListModel,
     int[] destinationsLoadCount,
     int destinationsListIndex,
     int i) {
   if (seedPlates[i].getSeedPlateBarcode() != null) {
     if (destinationsListIndex == destinationsListModel.getSize()) {
       for (int k = 0; k < destinationsListModel.getSize(); k++) {
         if (destinationsLoadCount[k] < MAX_NUMBER_IN_SEED_DESTINATION) {
           destinationsListIndex = k;
           break;
         }
       }
     }
   }
   return destinationsListIndex;
 }
 public void actionPerformed(ActionEvent e) {
   DefaultListModel listModel = null;
   JList list = null;
   if (((JButton) e.getSource()).getName().equals(REMOVE_SELECTED)) {
     list = failedPlatesList;
     listModel = (DefaultListModel) failedPlatesList.getModel();
   } else {
     list = destinationsList;
     listModel = (DefaultListModel) destinationsList.getModel();
   }
   if (list.getSelectedIndices().length > 0) {
     int[] temp = list.getSelectedIndices();
     int[] selectedIndices = list.getSelectedIndices();
     for (int i = temp.length - 1; i >= 0; i--) {
       selectedIndices = list.getSelectedIndices();
       listModel.removeElementAt(selectedIndices[i]);
     }
   }
 }
 public void validateUnloadPlatesDialog() throws ChippingManagerException {
   StringBuffer stBuff = new StringBuffer(CORRECT_ERRORS_TO_CONTINUE);
   DefaultListModel destinationListModel = (DefaultListModel) destinationsList.getModel();
   int numberOfDestinations = destinationListModel.getSize();
   // Get the number of seed plates
   int seedPlatesCount = numberOfValidSeedPlates();
   String destinationsMessage =
       seedChipperGUIController
           .getSeedChipperController()
           .validateDestinations(numberOfDestinations, seedPlatesCount);
   if (destinationsMessage != null) {
     stBuff.append("\n- " + destinationsMessage);
   }
   if (userIDComboBox.getSelectedIndex() == 0) {
     stBuff.append("\n- " + USER_NAME_NOT_SELECTED + "\n");
   }
   if (!stBuff.toString().equals(CORRECT_ERRORS_TO_CONTINUE)) {
     throw new ChippingManagerException(stBuff.toString());
   }
 }
 public void unloadPlates() throws ChippingManagerException {
   seedChipperGUIController.getSeedChipperController().validateChangePriorToSave();
   //        List<Plate> platesToUnload = getFailedChiplates();
   DefaultListModel destinationsListModel = (DefaultListModel) destinationsList.getModel();
   int[] destinationsLoadCount = new int[destinationsListModel.getSize()];
   // Assign destinations to the seed plates
   int destinationsListIndex = 0;
   updateSeedPlateStatus();
   updateChipPlateStatus();
   // Set the respective locations in the seed plates
   for (int i = 0; i < seedPlates.length; i++) {
     // todo: unload criteria to be refactored to plate object....
     if (SCANNED.equals(seedPlates[i].getStatus()) && seedPlates[i].getPrescanStatus() != null) {
       destinationsListIndex =
           findDestinationListIndex(
               destinationsListModel, destinationsLoadCount, destinationsListIndex, i);
       // Decide the destination
       String seedPlateDestination =
           destinationsListModel.getElementAt(destinationsListIndex).toString();
       logger.info(
           "assigning seed  plates to plate "
               + seedPlates[i].getDeckNest()
               + " ->> "
               + seedPlateDestination);
       seedPlates[i].setStorageLocation(seedPlateDestination);
       destinationsLoadCount[destinationsListIndex]++;
       destinationsListIndex++;
       seedPlates[i].setPrescanStatus(CHIPPED);
     }
   }
   seedChipperGUIController
       .getSeedChipperController()
       .unloadChipperRun(userIDComboBox.getSelectedItem().toString());
   //
   // seedChipperGUIController.getSeedChipperController().syncPrescannedPlatesList(platesToUnload,
   // seedPlates, chipPlates);
   seedChipperGUIController.drawDeck();
   seedChipperGUIController.drawRunsOnDeck();
   logger.info("Plates unloaded to seed store");
   this.dispose();
 }
 /**
  * Determines if a given String is present in the list
  *
  * @param scan the String to look for in the list
  * @param list the list of values to examine
  * @return true if the list contains the String, false otherwise
  */
 public boolean isContainedInList(String scan, JList list) {
   DefaultListModel listModel = (DefaultListModel) list.getModel();
   return listModel.contains(scan);
 }
 public void addDestination(String scannedDestination) {
   DefaultListModel listModel = (DefaultListModel) destinationsList.getModel();
   int lastPosition = listModel.getSize();
   listModel.add(lastPosition, scannedDestination);
 }
 public void addToUnloadPlatesList(String scannerInput) {
   DefaultListModel listModel = (DefaultListModel) failedPlatesList.getModel();
   int lastPosition = listModel.getSize();
   listModel.add(lastPosition, scannerInput);
 }