Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.91 KB | None | 0 0
  1. else if (e.getSource() == this.deleteButton) {
  2.                 JPanel panel = new JPanel();
  3.                 JLabel label = new JLabel("Enter a password:");
  4.                 JPasswordField pass = new JPasswordField(10);
  5.                 panel.add(label);
  6.                 panel.add(pass);
  7.                 String[] options = new String[] { "OK", "Cancel" };
  8.  
  9.                 int option = JOptionPane.showOptionDialog(null, panel, "Delete - Operation", JOptionPane.NO_OPTION,
  10.                         JOptionPane.OK_CANCEL_OPTION, null, options, options[1]);
  11.  
  12.                 if (option == 0) {
  13.                     char[] password = pass.getPassword();
  14.                     if (this.password.compareTo(new String(password)) == 0) {
  15.  
  16.                         if (selectedRows == null)
  17.                             JOptionPane.showMessageDialog(null, "You didn't select anything ?");
  18.                         else {
  19.                             ArrayList<Screw> AllScrews = new ArrayList<Screw>(db.getCollScrew());
  20.                             InputStream inp = new FileInputStream(fileName);
  21.                             Workbook wb = WorkbookFactory.create(inp);
  22.                             Sheet sheet = wb.getSheetAt(0);
  23.                             ArrayList<Screw> toDeleteScrews = new ArrayList<Screw>();
  24.                             Arrays.sort(selectedRows);
  25.                            
  26.                            
  27.                             for (int i = 0; i < selectedRows.length; i++) {
  28.                                 Screw toRemoveobject = AllScrews.get(selectedRows[i]);
  29.                                 toDeleteScrews.add(toRemoveobject);
  30.                                 db.getCollScrew().remove(toRemoveobject);  
  31.                                 tmScrew.fireTableRowsDeleted(selectedRows[i], selectedRows[i]);
  32.                        
  33.                             }
  34.                            
  35.                             db.notifyObservers();
  36.                             tmScrew.fireTableDataChanged();
  37.                             tmScrew.fireTableStructureChanged();
  38.                        
  39.                             ArrayList<Integer> foundIndexes = findRealIndexesFromExcel(fileName, toDeleteScrews);
  40.                             Collections.reverse(foundIndexes);
  41.                            
  42.                             for (int i = 0; i < foundIndexes.size(); i++) {
  43.                                     removeRow(sheet, foundIndexes.get(i));
  44.                             }
  45.                             System.out.println("done");
  46.                            
  47.                             FileOutputStream fileOut = new FileOutputStream(fileName);
  48.                             wb.write(fileOut);
  49.                             fileOut.close();                       
  50.                         }
  51.  
  52.                     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement