diff --git a/controller/AdressenOeffnen.java b/controller/AdressenOeffnen.java new file mode 100644 index 0000000..021b01b --- /dev/null +++ b/controller/AdressenOeffnen.java @@ -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; + } +} diff --git a/controller/AdressenSpeichern.java b/controller/AdressenSpeichern.java new file mode 100644 index 0000000..65a9a1a --- /dev/null +++ b/controller/AdressenSpeichern.java @@ -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; + } +} diff --git a/controller/DatenHinzufuegen.java b/controller/DatenHinzufuegen.java new file mode 100644 index 0000000..455ec57 --- /dev/null +++ b/controller/DatenHinzufuegen.java @@ -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; + } +} diff --git a/controller/DatenLoeschen.java b/controller/DatenLoeschen.java new file mode 100644 index 0000000..68666ff --- /dev/null +++ b/controller/DatenLoeschen.java @@ -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> 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 inhalt = new ArrayList<>(); + for(int i=0; i