/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package commands; import java.io.File; import java.util.Stack; import java.util.prefs.Preferences; import model.model; import view.gui; /** * Delete Command * @author matthias */ public class CommandDelete implements CommandInterface { private File data; private gui g; private model mdl; private Preferences prfs; private String pid; private Stack adressEintraegeDaten; private Stack pos; public CommandDelete(gui G, Preferences p, model mdl, String pid) { this.g = G; this.mdl = mdl; this.prfs = p; this.pid = pid; this.data = null; adressEintraegeDaten = new Stack(); this.pos = new Stack(); } /** * overrides execute vom CommandInterface * hier wird eeintragLoeschen vom Model aufgerufen * davor werden die gelöschten Daten im Stack gespeichert */ @Override @SuppressWarnings("unchecked") public void execute() { try { int sel = this.g.getContentTable1().getjTable().getSelectedRow(); for(int i = 0; i < mdl.getColumnCount(); i++) { Object v = mdl.getValueAt(sel, i); this.adressEintraegeDaten.push(v); } this.pos.push(sel); this.mdl.eintragLoeschen(sel); } catch(Exception ex) { System.err.println(ex); } //System.out.println(this.pref.get(PATH_ID, "xyz")); } /** * overrides undo vom CommandInterface * hier werden die gelöschten Daten wieder ins Modell geschrieben */ @Override public void undo() { System.out.println("del_undo"); int pos_i = (int) this.pos.pop(); this.mdl.eintragHinzufuegenAt(pos_i); for(int i = mdl.getColumnCount()-1; i >= 0; i--) { this.mdl.setValueAt(this.adressEintraegeDaten.pop(), pos_i, i); } this.mdl.fireTableDataChanged(); } }