Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- else if (e.getSource() == this.deleteButton) {
- JPanel panel = new JPanel();
- JLabel label = new JLabel("Enter a password:");
- JPasswordField pass = new JPasswordField(10);
- panel.add(label);
- panel.add(pass);
- String[] options = new String[] { "OK", "Cancel" };
- int option = JOptionPane.showOptionDialog(null, panel, "Delete - Operation", JOptionPane.NO_OPTION,
- JOptionPane.OK_CANCEL_OPTION, null, options, options[1]);
- if (option == 0) {
- char[] password = pass.getPassword();
- if (this.password.compareTo(new String(password)) == 0) {
- if (selectedRows == null)
- JOptionPane.showMessageDialog(null, "You didn't select anything ?");
- else {
- ArrayList<Screw> AllScrews = new ArrayList<Screw>(db.getCollScrew());
- InputStream inp = new FileInputStream(fileName);
- Workbook wb = WorkbookFactory.create(inp);
- Sheet sheet = wb.getSheetAt(0);
- ArrayList<Screw> toDeleteScrews = new ArrayList<Screw>();
- Arrays.sort(selectedRows);
- for (int i = 0; i < selectedRows.length; i++) {
- Screw toRemoveobject = AllScrews.get(selectedRows[i]);
- toDeleteScrews.add(toRemoveobject);
- db.getCollScrew().remove(toRemoveobject);
- tmScrew.fireTableRowsDeleted(selectedRows[i], selectedRows[i]);
- }
- db.notifyObservers();
- tmScrew.fireTableDataChanged();
- tmScrew.fireTableStructureChanged();
- ArrayList<Integer> foundIndexes = findRealIndexesFromExcel(fileName, toDeleteScrews);
- Collections.reverse(foundIndexes);
- for (int i = 0; i < foundIndexes.size(); i++) {
- removeRow(sheet, foundIndexes.get(i));
- }
- System.out.println("done");
- FileOutputStream fileOut = new FileOutputStream(fileName);
- wb.write(fileOut);
- fileOut.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement