1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- /*
- * 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 controller.commands;
-
- import model.AdressverwaltungModel;
- import controller.Interface;
- import java.util.Stack;
- import javax.swing.JOptionPane;
- import prfourgui.CommandDeleteRowDataContainer;
- import prfourgui.View.AdressbuchView;
-
- /**
- *
- * @author jechowma68968
- */
- public class CommandDeleteRow implements Interface
- {
- private final AdressbuchView view;
- private final AdressverwaltungModel model;
- private final Stack<CommandDeleteRowDataContainer> deleteHistory;
-
-
- public CommandDeleteRow(AdressbuchView view, AdressverwaltungModel model)
- {
- this.view = view;
- this.model = model;
- this.deleteHistory = new Stack();
- }
-
- @Override
- public void execute()
- {
- int rowCount = view.getAdressTable2().getTblAdressbuch().getSelectedRowCount();
- if (rowCount != 1){
- JOptionPane.showMessageDialog(view, "Genau eine Zeile auswählen zum löschen.", "Ein Satz mit x, das war wohl nox...", JOptionPane.INFORMATION_MESSAGE);
- }
- else{
- int row = view.getAdressTable2().getTblAdressbuch().getSelectedRow();
- deleteHistory.push(new CommandDeleteRowDataContainer(model.getValueAt(row, 0).toString(), model.getValueAt(row, 1).toString()));
- model.eintragLoeschen(row);
- }
- }
-
- @Override
- public void undo()
- {
- CommandDeleteRowDataContainer c = deleteHistory.pop();
- model.eintragHinzufuegen();
- System.out.println(c.name);
- System.out.println(c.telephone);
- System.out.println(model.getRowCount());
- model.setValueAt(c.name, model.getRowCount()-1, 0);
- model.setValueAt(c.telephone, model.getRowCount()-1, 1);
- }
- }
|