@@ -0,0 +1,77 @@ | |||
/* | |||
* 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 gui_adressverwaltung.Controller; | |||
import gui_adressverwaltung.Controller.Interface.CommandInterface; | |||
import gui_adressverwaltung.model.AdressverwaltungModel; | |||
import gui_adressverwaltung.view.Hauptfenster; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import java.util.logging.Level; | |||
import java.util.logging.Logger; | |||
import javax.swing.JFileChooser; | |||
/** | |||
* | |||
* @author am | |||
*/ | |||
public class AdressenOeffnen implements CommandInterface | |||
{ | |||
private AdressverwaltungModel model; | |||
private Hauptfenster view; | |||
/** | |||
* | |||
* @param model | |||
* @param view | |||
*/ | |||
public AdressenOeffnen(AdressverwaltungModel model, Hauptfenster view) | |||
{ | |||
this.model = model; | |||
this.view = view; | |||
} | |||
/** | |||
* Führt den Befehl aus | |||
*/ | |||
@Override | |||
public void execute() | |||
{ | |||
JFileChooser chooser = new JFileChooser(); | |||
chooser.showOpenDialog(view); | |||
File file = chooser.getSelectedFile(); | |||
try | |||
{ | |||
model.datenLesen(file); | |||
view.getLblStatus().setText("Neue Datei geöffnet"); | |||
} | |||
catch(IOException | ClassNotFoundException ex) | |||
{ | |||
Logger.getLogger(AdressenOeffnen.class.getName()).log(Level.SEVERE, null, ex); | |||
} | |||
} | |||
/** | |||
* Macht den Befehl rückgängig | |||
*/ | |||
@Override | |||
public void undo() | |||
{ | |||
} | |||
/** | |||
* Gibt zurück ob die Aktion rücknehmbar ist | |||
*/ | |||
@Override | |||
public boolean isUndoable() | |||
{ | |||
return false; | |||
} | |||
} |
@@ -0,0 +1,73 @@ | |||
/* | |||
* 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 gui_adressverwaltung.Controller; | |||
import gui_adressverwaltung.Controller.Interface.CommandInterface; | |||
import gui_adressverwaltung.model.AdressverwaltungModel; | |||
import gui_adressverwaltung.view.Hauptfenster; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import java.util.logging.Level; | |||
import java.util.logging.Logger; | |||
import javax.swing.JFileChooser; | |||
/** | |||
* | |||
* @author nobody | |||
*/ | |||
public class AdressenSpeichern implements CommandInterface | |||
{ | |||
private AdressverwaltungModel model; | |||
private Hauptfenster view; | |||
public AdressenSpeichern(AdressverwaltungModel model, Hauptfenster view) | |||
{ | |||
this.model = model; | |||
this.view = view; | |||
} | |||
/** | |||
* Führt den Befehl aus | |||
*/ | |||
@Override | |||
public void execute() | |||
{ | |||
JFileChooser chooser = new JFileChooser(); | |||
chooser.showSaveDialog(view); | |||
File file = chooser.getSelectedFile(); | |||
try | |||
{ | |||
model.datenSpeichern(file); | |||
view.getLblStatus().setText("Adressen wurden gespeichert"); | |||
} | |||
catch(IOException ex) | |||
{ | |||
Logger.getLogger(AdressenSpeichern.class.getName()).log(Level.SEVERE, null, ex); | |||
} | |||
} | |||
/** | |||
* Nimmt den Befehl zurück | |||
*/ | |||
@Override | |||
public void undo() | |||
{ | |||
} | |||
/** | |||
* Giubt zurück ob der Befehl rücknehmbar ist | |||
*/ | |||
@Override | |||
public boolean isUndoable() | |||
{ | |||
return false; | |||
} | |||
} |
@@ -0,0 +1,50 @@ | |||
/* | |||
* 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 gui_adressverwaltung.Controller; | |||
import gui_adressverwaltung.Controller.Interface.CommandInterface; | |||
import gui_adressverwaltung.model.AdressverwaltungModel; | |||
import gui_adressverwaltung.view.Hauptfenster; | |||
/** | |||
* | |||
* @author nobody | |||
*/ | |||
public class DatenHinzufuegen implements CommandInterface | |||
{ | |||
private AdressverwaltungModel model; | |||
private Hauptfenster view; | |||
public DatenHinzufuegen(AdressverwaltungModel model, Hauptfenster view) | |||
{ | |||
this.model = model; | |||
this.view = view; | |||
} | |||
/** | |||
* Fühhrt den Befehl aus | |||
*/ | |||
@Override | |||
public void execute() | |||
{ | |||
view.getLblStatus().setText("Zeile hinzugefügt"); | |||
model.eintragHinzufuegen(); | |||
} | |||
@Override | |||
public void undo() | |||
{ | |||
} | |||
@Override | |||
public boolean isUndoable() | |||
{ | |||
return false; | |||
} | |||
} |
@@ -0,0 +1,76 @@ | |||
/* | |||
* 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 gui_adressverwaltung.Controller; | |||
import gui_adressverwaltung.Controller.Interface.CommandInterface; | |||
import gui_adressverwaltung.model.AdressverwaltungModel; | |||
import gui_adressverwaltung.view.Hauptfenster; | |||
import java.util.ArrayList; | |||
import java.util.Stack; | |||
/** | |||
* | |||
* @author nobody | |||
*/ | |||
public class DatenLoeschen implements CommandInterface | |||
{ | |||
private AdressverwaltungModel model; | |||
private Hauptfenster view; | |||
private Stack<ArrayList<String>> datenStack; | |||
public DatenLoeschen(AdressverwaltungModel model, Hauptfenster view) | |||
{ | |||
this.model = model; | |||
this.view = view; | |||
this.datenStack = new Stack<>(); | |||
} | |||
/** | |||
* Fühhrt den Befehl aus | |||
*/ | |||
@Override | |||
public void execute() | |||
{ | |||
try | |||
{ | |||
int reihe = view.getTblAdressen().getSelectedRow(); | |||
ArrayList<String> inhalt = new ArrayList<>(); | |||
for(int i=0; i<model.getColumnCount();i++) | |||
{ | |||
inhalt.add(model.getValueAt(reihe, i).toString()); | |||
} | |||
datenStack.push(inhalt); | |||
model.eintragLoeschen(reihe); | |||
view.getLblStatus().setText("Zeile gelöscht"); | |||
} | |||
catch(Exception ex) | |||
{ | |||
view.getLblStatus().setText("Keine Zeile zum Löschen ausgewählt"); | |||
} | |||
} | |||
@Override | |||
public void undo() | |||
{ | |||
view.getLblStatus().setText("Fälschlicherweise gelöschte Zeile wieder eingefügt"); | |||
model.eintragHinzufuegen(); | |||
int endreihe = model.getRowCount(); | |||
for(int i=0; i<model.getColumnCount();i++) | |||
{ | |||
model.setValueAt(datenStack.lastElement().get(i), endreihe, i); | |||
} | |||
datenStack.removeElementAt(datenStack.size()); | |||
} | |||
@Override | |||
public boolean isUndoable() | |||
{ | |||
return true; | |||
} | |||
} |
@@ -0,0 +1,52 @@ | |||
/* | |||
* 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 gui_adressverwaltung.Controller; | |||
import gui_adressverwaltung.model.AdressverwaltungModel; | |||
import gui_adressverwaltung.view.Hauptfenster; | |||
import java.awt.event.ActionEvent; | |||
import java.awt.event.ActionListener; | |||
import java.util.logging.Level; | |||
import java.util.logging.Logger; | |||
/** | |||
* | |||
* @author nobody | |||
*/ | |||
public class UndoController implements ActionListener | |||
{ | |||
private Hauptfenster view; | |||
private AdressverwaltungModel model; | |||
private CommandInvoker invoker; | |||
public UndoController(Hauptfenster view, AdressverwaltungModel model, CommandInvoker invoker) | |||
{ | |||
this.view = view; | |||
this.model = model; | |||
this.invoker = invoker; | |||
} | |||
public void registerEvents() | |||
{ | |||
view.getMndUndo().addActionListener(this); | |||
view.getBtnUndo().addActionListener(this); | |||
} | |||
@Override | |||
public void actionPerformed(ActionEvent e) | |||
{ | |||
try{ | |||
view.getLblStatus().setText("Undo Trigger"); | |||
invoker.undoCommand(); | |||
} | |||
catch(Exception ex){ | |||
view.getLblStatus().setText("Fehler"); | |||
Logger.getLogger(AdressenSpeichern.class.getName()).log(Level.SEVERE, null, ex); | |||
} | |||
} | |||
} |