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.

CommandDelete.java 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 commands;
  7. import java.io.File;
  8. import java.util.Stack;
  9. import java.util.prefs.Preferences;
  10. import model.model;
  11. import view.gui;
  12. /**
  13. * Delete Command
  14. * @author matthias
  15. */
  16. public class CommandDelete implements CommandInterface {
  17. private File data;
  18. private gui g;
  19. private model mdl;
  20. private Preferences prfs;
  21. private String pid;
  22. private Stack adressEintraegeDaten;
  23. private Stack pos;
  24. public CommandDelete(gui G, Preferences p, model mdl, String pid)
  25. {
  26. this.g = G;
  27. this.mdl = mdl;
  28. this.prfs = p;
  29. this.pid = pid;
  30. this.data = null;
  31. adressEintraegeDaten = new Stack();
  32. this.pos = new Stack();
  33. }
  34. /**
  35. * overrides execute vom CommandInterface
  36. * hier wird eeintragLoeschen vom Model aufgerufen
  37. * davor werden die gelöschten Daten im Stack gespeichert
  38. */
  39. @Override
  40. @SuppressWarnings("unchecked")
  41. public void execute() {
  42. try
  43. {
  44. int sel = this.g.getContentTable1().getjTable().getSelectedRow();
  45. for(int i = 0; i < mdl.getColumnCount(); i++)
  46. {
  47. Object v = mdl.getValueAt(sel, i);
  48. this.adressEintraegeDaten.push(v);
  49. }
  50. this.pos.push(sel);
  51. this.mdl.eintragLoeschen(sel);
  52. }
  53. catch(Exception ex)
  54. {
  55. System.err.println(ex);
  56. }
  57. //System.out.println(this.pref.get(PATH_ID, "xyz"));
  58. }
  59. /**
  60. * overrides undo vom CommandInterface
  61. * hier werden die gelöschten Daten wieder ins Modell geschrieben
  62. */
  63. @Override
  64. public void undo() {
  65. System.out.println("del_undo");
  66. int pos_i = (int) this.pos.pop();
  67. this.mdl.eintragHinzufuegenAt(pos_i);
  68. for(int i = mdl.getColumnCount()-1; i >= 0; i--)
  69. {
  70. this.mdl.setValueAt(this.adressEintraegeDaten.pop(), pos_i, i);
  71. }
  72. this.mdl.fireTableDataChanged();
  73. }
  74. }