You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CommandDeleteRow.java 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package controller.commands;
  7. import model.AdressverwaltungModel;
  8. import controller.Interface;
  9. import java.util.Stack;
  10. import javax.swing.JOptionPane;
  11. import prfourgui.CommandDeleteRowDataContainer;
  12. import prfourgui.View.AdressbuchView;
  13. /**
  14. *
  15. * @author jechowma68968
  16. */
  17. public class CommandDeleteRow implements Interface
  18. {
  19. private final AdressbuchView view;
  20. private final AdressverwaltungModel model;
  21. private final Stack<CommandDeleteRowDataContainer> deleteHistory;
  22. public CommandDeleteRow(AdressbuchView view, AdressverwaltungModel model)
  23. {
  24. this.view = view;
  25. this.model = model;
  26. this.deleteHistory = new Stack();
  27. }
  28. @Override
  29. public void execute()
  30. {
  31. int rowCount = view.getAdressTable2().getTblAdressbuch().getSelectedRowCount();
  32. if (rowCount != 1){
  33. JOptionPane.showMessageDialog(view, "Genau eine Zeile auswählen zum löschen.", "Ein Satz mit x, das war wohl nox...", JOptionPane.INFORMATION_MESSAGE);
  34. }
  35. else{
  36. int row = view.getAdressTable2().getTblAdressbuch().getSelectedRow();
  37. deleteHistory.push(new CommandDeleteRowDataContainer(model.getValueAt(row, 0).toString(), model.getValueAt(row, 1).toString()));
  38. model.eintragLoeschen(row);
  39. }
  40. }
  41. @Override
  42. public void undo()
  43. {
  44. CommandDeleteRowDataContainer c = deleteHistory.pop();
  45. model.eintragHinzufuegen();
  46. System.out.println(c.name);
  47. System.out.println(c.telephone);
  48. System.out.println(model.getRowCount());
  49. model.setValueAt(c.name, model.getRowCount()-1, 0);
  50. model.setValueAt(c.telephone, model.getRowCount()-1, 1);
  51. }
  52. }