From 57e689fea06d6abac70612f16744ea3c4e1880ad Mon Sep 17 00:00:00 2001 From: Alexander Christoph Date: Tue, 7 May 2019 20:04:55 +0000 Subject: [PATCH] =?UTF-8?q?Dateien=20hochladen=20nach=20=E2=80=9Econtrolle?= =?UTF-8?q?r=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/AdressenOeffnen.java | 77 +++++++++++++++++++++++++++++++ controller/AdressenSpeichern.java | 73 +++++++++++++++++++++++++++++ controller/DatenHinzufuegen.java | 50 ++++++++++++++++++++ controller/DatenLoeschen.java | 76 ++++++++++++++++++++++++++++++ controller/UndoController.java | 52 +++++++++++++++++++++ 5 files changed, 328 insertions(+) create mode 100644 controller/AdressenOeffnen.java create mode 100644 controller/AdressenSpeichern.java create mode 100644 controller/DatenHinzufuegen.java create mode 100644 controller/DatenLoeschen.java create mode 100644 controller/UndoController.java 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