From ee74f34071b858307a7695eab3f1e3ec6b9e9369 Mon Sep 17 00:00:00 2001 From: Richard van Heest Date: Thu, 23 Jul 2015 15:00:42 +0200 Subject: [PATCH 1/8] filter + cast = ofType --- .../application/working/RekeningTab.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/working/RekeningTab.java b/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/working/RekeningTab.java index fb6016d..e88f341 100644 --- a/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/working/RekeningTab.java +++ b/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/working/RekeningTab.java @@ -95,24 +95,19 @@ else if (file.getName().endsWith(".xml")) { Observable factuur = ioWorker.load(file); Observable aangenomen = factuur - .filter(a -> a instanceof AangenomenFactuur) - .cast(AangenomenFactuur.class) + .ofType(AangenomenFactuur.class) .map(fact -> new AangenomenController(fact, database)); Observable mutaties = factuur - .filter(m -> m instanceof MutatiesFactuur) - .cast(MutatiesFactuur.class) + .ofType(MutatiesFactuur.class) .map(fact -> new MutatiesController(fact, database)); Observable offerte = factuur - .filter(o -> o instanceof Offerte) - .cast(Offerte.class) + .ofType(Offerte.class) .map(fact -> new OfferteController(fact, database)); Observable particulier = factuur - .filter(p -> p instanceof ParticulierFactuur) - .cast(ParticulierFactuur.class) + .ofType(ParticulierFactuur.class) .map(fact -> new ParticulierController(fact, database)); Observable reparaties = factuur - .filter(m -> m instanceof ReparatiesFactuur) - .cast(ReparatiesFactuur.class) + .ofType(ReparatiesFactuur.class) .map(fact -> new ReparatiesController(fact, database)); return Observable.merge(aangenomen, mutaties, offerte, particulier, reparaties) From cd65ea19d7014a4afc37ac52731361ae10ed4488 Mon Sep 17 00:00:00 2001 From: Richard van Heest Date: Thu, 23 Jul 2015 15:09:07 +0200 Subject: [PATCH 2/8] Check if LAST_SAVE_LOCATION still exists Fix for #25 --- .../application/working/MainPane.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/working/MainPane.java b/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/working/MainPane.java index 17eb0e8..e61ea3b 100644 --- a/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/working/MainPane.java +++ b/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/working/MainPane.java @@ -183,6 +183,10 @@ private Observable showOpenFileChooser(Stage stage) { File initDir = new File(this.properties.getProperty(PropertyModelEnum.LAST_SAVE_LOCATION) .orElse(System.getProperty("user.dir"))); + if (!initDir.exists()) { + initDir = new File(System.getProperty("user.dir")); + } + FileChooser chooser = new FileChooser(); chooser.setTitle("Open een factuur"); chooser.setInitialDirectory(initDir); @@ -196,6 +200,10 @@ private Optional showSaveFileChooser(Stage stage) { File initDir = new File(this.properties.getProperty(PropertyModelEnum.LAST_SAVE_LOCATION) .orElse(System.getProperty("user.dir"))); + if (!initDir.exists()) { + initDir = new File(System.getProperty("user.dir")); + } + FileChooser chooser = new FileChooser(); chooser.setTitle("Sla een factuur op"); chooser.setInitialDirectory(initDir); @@ -208,6 +216,10 @@ private Optional showExportFileChooser(Stage stage) { File initDir = new File(this.properties.getProperty(PropertyModelEnum.LAST_SAVE_LOCATION) .orElse(System.getProperty("user.dir"))); + if (!initDir.exists()) { + initDir = new File(System.getProperty("user.dir")); + } + FileChooser chooser = new FileChooser(); chooser.setTitle("Exporteer een factuur"); chooser.setInitialDirectory(initDir); From 014f9889d025ac118781883250df87625296d2e7 Mon Sep 17 00:00:00 2001 From: Richard van Heest Date: Thu, 23 Jul 2015 15:41:48 +0200 Subject: [PATCH 3/8] Added extra default save location for the offerte --- Rekeningsysteem/config.properties | 1 + .../application/working/MainPane.java | 79 ++++++++++++++----- .../properties/PropertyModelEnum.java | 1 + 3 files changed, 60 insertions(+), 21 deletions(-) diff --git a/Rekeningsysteem/config.properties b/Rekeningsysteem/config.properties index 55fbb19..557b362 100644 --- a/Rekeningsysteem/config.properties +++ b/Rekeningsysteem/config.properties @@ -13,6 +13,7 @@ valutaiso4217=EUR dateformat=dd-MM-yyyy loonbtwpercentage=6 lastsavelocation=G\:\\Richard van Heest\\Rekeningsysteem-Bouwbedrijf-Mackloet\\Rekeningsysteem\\Testfacturen +lastsavelocationofferte=G\:\\Richard van Heest\\Rekeningsysteem-Bouwbedrijf-Mackloet\\Rekeningsysteem\\src\\test\\resources\\pdf factuurnummer=42015 pdfmutatiestemplate=resources\\LaTeX\\MutatiesFactuur.tex materiaalbtwpercentage=21 diff --git a/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/working/MainPane.java b/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/working/MainPane.java index e61ea3b..b9787b4 100644 --- a/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/working/MainPane.java +++ b/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/working/MainPane.java @@ -21,8 +21,10 @@ import org.rekeningsysteem.application.Main; import org.rekeningsysteem.application.settings.SettingsPane; +import org.rekeningsysteem.data.offerte.Offerte; import org.rekeningsysteem.io.database.Database; import org.rekeningsysteem.properties.PropertiesWorker; +import org.rekeningsysteem.properties.PropertyKey; import org.rekeningsysteem.properties.PropertyModelEnum; import org.rekeningsysteem.rxjavafx.Observables; import org.rekeningsysteem.ui.aangenomen.AangenomenController; @@ -115,29 +117,51 @@ private void initButtonHandlers(Stage stage) { }); this.initSaveObservable() - .doOnNext(tab -> { - if (!tab.getSaveFile().isPresent()) { - this.showSaveFileChooser(stage).ifPresent(file -> { - this.saveLastSaveLocationProperty(file); - tab.setSaveFile(file); - tab.initFactuurnummer(); - }); - } - }) + .flatMap(tab -> tab.getModel() + .map(rekening -> rekening instanceof Offerte) + .doOnNext(isOfferte -> { + if (!tab.getSaveFile().isPresent()) { + if (isOfferte) { + this.showSaveFileChooserOfferte(stage).ifPresent(file -> { + this.saveLastSaveLocationOfferteProperty(file); + tab.setSaveFile(file); + tab.initFactuurnummer(); + }); + } + else { + this.showSaveFileChooser(stage).ifPresent(file -> { + this.saveLastSaveLocationProperty(file); + tab.setSaveFile(file); + tab.initFactuurnummer(); + }); + } + } + }), (tab, isOfferte) -> tab) .filter(tab -> tab.getSaveFile().isPresent()) .subscribe(RekeningTab::save); this.initExportObservable() - .doOnNext(tab -> { - if (!tab.getSaveFile().isPresent()) { - this.showSaveFileChooser(stage).ifPresent(file -> { - this.saveLastSaveLocationProperty(file); - tab.setSaveFile(file); - tab.initFactuurnummer(); - }); - tab.save(); - } - }) + .flatMap(tab -> tab.getModel() + .map(rekening -> rekening instanceof Offerte) + .doOnNext(isOfferte -> { + if (!tab.getSaveFile().isPresent()) { + if (isOfferte) { + this.showSaveFileChooserOfferte(stage).ifPresent(file -> { + this.saveLastSaveLocationOfferteProperty(file); + tab.setSaveFile(file); + tab.initFactuurnummer(); + }); + } + else { + this.showSaveFileChooser(stage).ifPresent(file -> { + this.saveLastSaveLocationProperty(file); + tab.setSaveFile(file); + tab.initFactuurnummer(); + }); + } + tab.save(); + } + }), (tab, isOfferte) -> tab) .subscribe(tab -> this.showExportFileChooser(stage).ifPresent(file -> { this.saveLastSaveLocationProperty(file); tab.export(file); @@ -179,6 +203,11 @@ private void saveLastSaveLocationProperty(File file) { file.getParentFile().getPath()); } + private void saveLastSaveLocationOfferteProperty(File file) { + this.properties.setProperty(PropertyModelEnum.LAST_SAVE_LOCATION_OFFERTE, + file.getParentFile().getPath()); + } + private Observable showOpenFileChooser(Stage stage) { File initDir = new File(this.properties.getProperty(PropertyModelEnum.LAST_SAVE_LOCATION) .orElse(System.getProperty("user.dir"))); @@ -196,8 +225,8 @@ private Observable showOpenFileChooser(Stage stage) { .filter(Objects::nonNull); } - private Optional showSaveFileChooser(Stage stage) { - File initDir = new File(this.properties.getProperty(PropertyModelEnum.LAST_SAVE_LOCATION) + private Optional showSaveFileChooser(PropertyKey key, Stage stage) { + File initDir = new File(this.properties.getProperty(key) .orElse(System.getProperty("user.dir"))); if (!initDir.exists()) { @@ -211,6 +240,14 @@ private Optional showSaveFileChooser(Stage stage) { return Optional.ofNullable(chooser.showSaveDialog(stage)); } + + private Optional showSaveFileChooser(Stage stage) { + return this.showSaveFileChooser(PropertyModelEnum.LAST_SAVE_LOCATION, stage); + } + + private Optional showSaveFileChooserOfferte(Stage stage) { + return this.showSaveFileChooser(PropertyModelEnum.LAST_SAVE_LOCATION_OFFERTE, stage); + } private Optional showExportFileChooser(Stage stage) { File initDir = new File(this.properties.getProperty(PropertyModelEnum.LAST_SAVE_LOCATION) diff --git a/Rekeningsysteem/src/main/java/org/rekeningsysteem/properties/PropertyModelEnum.java b/Rekeningsysteem/src/main/java/org/rekeningsysteem/properties/PropertyModelEnum.java index 21e85bc..90a136a 100644 --- a/Rekeningsysteem/src/main/java/org/rekeningsysteem/properties/PropertyModelEnum.java +++ b/Rekeningsysteem/src/main/java/org/rekeningsysteem/properties/PropertyModelEnum.java @@ -20,6 +20,7 @@ public enum PropertyModelEnum implements PropertyKey { DATABASE("database"), LAST_SAVE_LOCATION("lastsavelocation"), + LAST_SAVE_LOCATION_OFFERTE("lastsavelocationofferte"), PDF_AANGENOMEN_TEMPLATE("pdfaangenomentemplate"), PDF_MUTATIES_TEMPLATE("pdfmutatiestemplate"), From 887b5092bf5dd5ca28e3249eaee45db2a50cdd4c Mon Sep 17 00:00:00 2001 From: Richard van Heest Date: Sun, 26 Jul 2015 13:00:18 +0200 Subject: [PATCH 4/8] Text file to support default footer text for offerte --- Rekeningsysteem/config.properties | 1 + Rekeningsysteem/resources/default offerte tekst.txt | 2 ++ .../java/org/rekeningsysteem/properties/PropertyModelEnum.java | 1 + 3 files changed, 4 insertions(+) create mode 100644 Rekeningsysteem/resources/default offerte tekst.txt diff --git a/Rekeningsysteem/config.properties b/Rekeningsysteem/config.properties index 557b362..79f56e8 100644 --- a/Rekeningsysteem/config.properties +++ b/Rekeningsysteem/config.properties @@ -19,3 +19,4 @@ pdfmutatiestemplate=resources\\LaTeX\\MutatiesFactuur.tex materiaalbtwpercentage=21 factuurnummerfile=resources\\factuurnummer.txt pdfreparatiestemplate=resources\\LaTeX\\ReparatiesFactuur.tex +offertedefaulttextlocation=resources\\default offerte tekst.txt diff --git a/Rekeningsysteem/resources/default offerte tekst.txt b/Rekeningsysteem/resources/default offerte tekst.txt new file mode 100644 index 0000000..033b925 --- /dev/null +++ b/Rekeningsysteem/resources/default offerte tekst.txt @@ -0,0 +1,2 @@ +This is a testing text! +Here you can put your name, adres, etc. \ No newline at end of file diff --git a/Rekeningsysteem/src/main/java/org/rekeningsysteem/properties/PropertyModelEnum.java b/Rekeningsysteem/src/main/java/org/rekeningsysteem/properties/PropertyModelEnum.java index 90a136a..d8d7448 100644 --- a/Rekeningsysteem/src/main/java/org/rekeningsysteem/properties/PropertyModelEnum.java +++ b/Rekeningsysteem/src/main/java/org/rekeningsysteem/properties/PropertyModelEnum.java @@ -7,6 +7,7 @@ public enum PropertyModelEnum implements PropertyKey { OFFERTENUMMER("offertenummer"), OFFERTENUMMERFILE("offertenummerfile"), + OFFERTE_DEFAULT_TEXT_LOCATION("offertedefaulttextlocation"), LOONBTWPERCENTAGE("loonbtwpercentage"), MATERIAALBTWPERCENTAGE("materiaalbtwpercentage"), From 509fa92df575a252c4d0110856174232d746723d Mon Sep 17 00:00:00 2001 From: Richard van Heest Date: Sun, 26 Jul 2015 13:00:51 +0200 Subject: [PATCH 5/8] File IO for default offerte footer --- .../exception/NoSuchFileException.java | 10 ++++ .../offerte/DefaultOfferteTextHandler.java | 50 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 Rekeningsysteem/src/main/java/org/rekeningsysteem/exception/NoSuchFileException.java create mode 100644 Rekeningsysteem/src/main/java/org/rekeningsysteem/logic/offerte/DefaultOfferteTextHandler.java diff --git a/Rekeningsysteem/src/main/java/org/rekeningsysteem/exception/NoSuchFileException.java b/Rekeningsysteem/src/main/java/org/rekeningsysteem/exception/NoSuchFileException.java new file mode 100644 index 0000000..10914f6 --- /dev/null +++ b/Rekeningsysteem/src/main/java/org/rekeningsysteem/exception/NoSuchFileException.java @@ -0,0 +1,10 @@ +package org.rekeningsysteem.exception; + +public class NoSuchFileException extends Exception { + + private static final long serialVersionUID = -5684032056630170886L; + + public NoSuchFileException(String error) { + super(error); + } +} diff --git a/Rekeningsysteem/src/main/java/org/rekeningsysteem/logic/offerte/DefaultOfferteTextHandler.java b/Rekeningsysteem/src/main/java/org/rekeningsysteem/logic/offerte/DefaultOfferteTextHandler.java new file mode 100644 index 0000000..44a0d30 --- /dev/null +++ b/Rekeningsysteem/src/main/java/org/rekeningsysteem/logic/offerte/DefaultOfferteTextHandler.java @@ -0,0 +1,50 @@ +package org.rekeningsysteem.logic.offerte; + +import java.io.File; +import java.io.IOException; +import java.util.Optional; + +import org.apache.commons.io.FileUtils; +import org.apache.log4j.Logger; +import org.rekeningsysteem.exception.NoSuchFileException; +import org.rekeningsysteem.logging.ApplicationLogger; +import org.rekeningsysteem.properties.PropertiesWorker; +import org.rekeningsysteem.properties.PropertyModelEnum; + +public class DefaultOfferteTextHandler { + + private final Optional file; + private final Logger logger = ApplicationLogger.getInstance(); + + public DefaultOfferteTextHandler() { + this.file = PropertiesWorker.getInstance() + .getProperty(PropertyModelEnum.OFFERTE_DEFAULT_TEXT_LOCATION) + .map(File::new); + } + + public String getDefaultText() { + return this.file.filter(File::exists) + .map(f -> { + try { + return FileUtils.readFileToString(f); + } + catch (IOException e) { + // TODO throw exception? + this.logger.error(e.getMessage(), e); + return ""; + } + }) + .orElse(""); + } + + public void setDefaultText(String s) throws IOException, NoSuchFileException { + if (this.file.isPresent()) { + File f = this.file.get(); + FileUtils.writeStringToFile(f, s, false); + } + else { + throw new NoSuchFileException("Er bestaat geen file waarin deze tekst kan " + + "worden opgeslagen."); + } + } +} From adec6e8142e1f6468cc5a1a23ee3e99b2f1dea96 Mon Sep 17 00:00:00 2001 From: Richard van Heest Date: Sun, 26 Jul 2015 13:01:30 +0200 Subject: [PATCH 6/8] Default offerte footer text in application --- .../rekeningsysteem/ui/offerte/TextPaneController.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Rekeningsysteem/src/main/java/org/rekeningsysteem/ui/offerte/TextPaneController.java b/Rekeningsysteem/src/main/java/org/rekeningsysteem/ui/offerte/TextPaneController.java index 1e5461e..ffa0705 100644 --- a/Rekeningsysteem/src/main/java/org/rekeningsysteem/ui/offerte/TextPaneController.java +++ b/Rekeningsysteem/src/main/java/org/rekeningsysteem/ui/offerte/TextPaneController.java @@ -1,5 +1,6 @@ package org.rekeningsysteem.ui.offerte; +import org.rekeningsysteem.logic.offerte.DefaultOfferteTextHandler; import org.rekeningsysteem.ui.WorkingPane; import org.rekeningsysteem.ui.WorkingPaneController; @@ -30,6 +31,13 @@ public String getTitle() { this.ui = ui; this.model = this.ui.getText(); + + DefaultOfferteTextHandler textHandler = new DefaultOfferteTextHandler(); + String text = textHandler.getDefaultText(); + if (!text.startsWith("\n\n")) { + text = "\n\n" + text; + } + this.ui.setText(text); } public Observable getModel() { From 1a5966288089929c50157a8f5bdfc31b83a84bd6 Mon Sep 17 00:00:00 2001 From: Richard van Heest Date: Sun, 26 Jul 2015 16:27:09 +0200 Subject: [PATCH 7/8] Set default text for offerte via settings pane --- .../application/settings/SettingsPane.java | 4 +- .../DebiteurSettingsTabController.java | 2 +- .../offerte/DefaultOfferteTextPane.java | 73 +++++++++++++++++++ .../DefaultOfferteTextPaneController.java | 47 ++++++++++++ .../offerte/DefaultOfferteTextTab.java | 10 +++ .../DefaultOfferteTextTabController.java | 18 +++++ .../offerte/DefaultOfferteTextHandler.java | 10 ++- 7 files changed, 160 insertions(+), 4 deletions(-) create mode 100644 Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/offerte/DefaultOfferteTextPane.java create mode 100644 Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/offerte/DefaultOfferteTextPaneController.java create mode 100644 Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/offerte/DefaultOfferteTextTab.java create mode 100644 Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/offerte/DefaultOfferteTextTabController.java diff --git a/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/SettingsPane.java b/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/SettingsPane.java index 25d9dd9..a6e5507 100644 --- a/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/SettingsPane.java +++ b/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/SettingsPane.java @@ -1,6 +1,7 @@ package org.rekeningsysteem.application.settings; import org.rekeningsysteem.application.settings.debiteur.DebiteurSettingsTabController; +import org.rekeningsysteem.application.settings.offerte.DefaultOfferteTextTabController; import org.rekeningsysteem.io.database.Database; import javafx.scene.control.ButtonBase; @@ -15,7 +16,8 @@ public SettingsPane(Stage stage, ButtonBase closeButton, Database database) { PrijslijstIO prijslijstTab = new PrijslijstIO(stage, closeButton); DebiteurSettingsTabController debiteurTab = new DebiteurSettingsTabController(database); + DefaultOfferteTextTabController offerteTab = new DefaultOfferteTextTabController(); - this.getTabs().addAll(prijslijstTab, debiteurTab.getUI()); + this.getTabs().addAll(prijslijstTab, debiteurTab.getUI(), offerteTab.getUI()); } } diff --git a/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/debiteur/DebiteurSettingsTabController.java b/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/debiteur/DebiteurSettingsTabController.java index a648192..7cd22c2 100644 --- a/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/debiteur/DebiteurSettingsTabController.java +++ b/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/debiteur/DebiteurSettingsTabController.java @@ -4,7 +4,7 @@ public class DebiteurSettingsTabController { - private DebiteurSettingsTab ui; + private final DebiteurSettingsTab ui; public DebiteurSettingsTabController(Database database) { this(new DebiteurTablePaneController(database)); diff --git a/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/offerte/DefaultOfferteTextPane.java b/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/offerte/DefaultOfferteTextPane.java new file mode 100644 index 0000000..01aa95a --- /dev/null +++ b/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/offerte/DefaultOfferteTextPane.java @@ -0,0 +1,73 @@ +package org.rekeningsysteem.application.settings.offerte; + +import javafx.event.ActionEvent; +import javafx.geometry.Insets; +import javafx.geometry.Pos; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.control.TextArea; +import javafx.scene.layout.HBox; +import javafx.scene.layout.VBox; + +import org.rekeningsysteem.rxjavafx.Observables; + +import rx.Observable; + +public class DefaultOfferteTextPane extends VBox { + + private final TextArea textTA = new TextArea(); + private final Button saveButton = new Button("Opslaan"); + private final Button cancelButton = new Button("Cancel"); + + private final Observable text = Observables.fromProperty(this.textTA.textProperty()); + private final Observable save = Observables.fromNodeEvents(this.saveButton, ActionEvent.ACTION); + private final Observable cancel = Observables.fromNodeEvents(this.cancelButton, ActionEvent.ACTION); + + public DefaultOfferteTextPane() { + this.getStyleClass().addAll("working-pane", "page"); + this.setAlignment(Pos.TOP_CENTER); + this.setPadding(new Insets(15)); + this.setSpacing(10); + + Label header = new Label("Standaard offerte tekst"); + header.setId("title"); + + this.textTA.setPrefColumnCount(50); + this.textTA.setPrefRowCount(20); + this.textTA.setWrapText(true); + + this.cancelButton.setId("cancelButton"); + this.cancelButton.setMinWidth(74); + this.cancelButton.setPrefWidth(74); + HBox.setMargin(this.cancelButton, new Insets(0, 8, 0, 0)); + + this.saveButton.setId("addButton"); + this.saveButton.setMinWidth(74); + this.saveButton.setPrefWidth(74); + this.saveButton.setDefaultButton(true); + + HBox buttons = new HBox(0, this.cancelButton, this.saveButton); + buttons.setAlignment(Pos.BASELINE_RIGHT); + VBox.setMargin(buttons, new Insets(10, 5, 5, 5)); + + VBox content = new VBox(this.textTA, buttons); + + this.getChildren().addAll(header, content); + } + + public Observable getText() { + return this.text; + } + + public void setText(String text) { + this.textTA.setText(text); + } + + public Observable getSaveButtonEvent() { + return this.save; + } + + public Observable getCancelButtonEvent() { + return this.cancel; + } +} diff --git a/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/offerte/DefaultOfferteTextPaneController.java b/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/offerte/DefaultOfferteTextPaneController.java new file mode 100644 index 0000000..006d330 --- /dev/null +++ b/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/offerte/DefaultOfferteTextPaneController.java @@ -0,0 +1,47 @@ +package org.rekeningsysteem.application.settings.offerte; + +import java.io.IOException; + +import javafx.event.ActionEvent; + +import org.rekeningsysteem.exception.NoSuchFileException; +import org.rekeningsysteem.logic.offerte.DefaultOfferteTextHandler; + +import rx.Observable; + +public class DefaultOfferteTextPaneController { + + private final DefaultOfferteTextPane ui; + private final DefaultOfferteTextHandler handler = new DefaultOfferteTextHandler(); + + public DefaultOfferteTextPaneController() { + this.ui = new DefaultOfferteTextPane(); + + Observable text = this.ui.getText(); + Observable save = this.ui.getSaveButtonEvent(); + Observable cancel = this.ui.getCancelButtonEvent(); + + this.ui.setText(this.handler.getDefaultText()); + + text.sample(save) + .subscribe(s -> { + try { + this.handler.setDefaultText(s); + } + catch (IOException e) { + e.printStackTrace(); + } + catch (NoSuchFileException e) { + e.printStackTrace(); + } + }); + cancel.subscribe(e -> { + String s = this.handler.getDefaultText(); + this.ui.setText(s); + }); + } + + public DefaultOfferteTextPane getUI() { + return this.ui; + } +} diff --git a/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/offerte/DefaultOfferteTextTab.java b/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/offerte/DefaultOfferteTextTab.java new file mode 100644 index 0000000..f3ae175 --- /dev/null +++ b/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/offerte/DefaultOfferteTextTab.java @@ -0,0 +1,10 @@ +package org.rekeningsysteem.application.settings.offerte; + +import javafx.scene.control.Tab; + +public class DefaultOfferteTextTab extends Tab { + + public DefaultOfferteTextTab(DefaultOfferteTextPane pane) { + super("Offerte", pane); + } +} diff --git a/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/offerte/DefaultOfferteTextTabController.java b/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/offerte/DefaultOfferteTextTabController.java new file mode 100644 index 0000000..3c1d94a --- /dev/null +++ b/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/offerte/DefaultOfferteTextTabController.java @@ -0,0 +1,18 @@ +package org.rekeningsysteem.application.settings.offerte; + +public class DefaultOfferteTextTabController { + + private final DefaultOfferteTextTab ui; + + public DefaultOfferteTextTabController() { + this(new DefaultOfferteTextPaneController()); + } + + public DefaultOfferteTextTabController(DefaultOfferteTextPaneController subController) { + this.ui = new DefaultOfferteTextTab(subController.getUI()); + } + + public DefaultOfferteTextTab getUI() { + return this.ui; + } +} diff --git a/Rekeningsysteem/src/main/java/org/rekeningsysteem/logic/offerte/DefaultOfferteTextHandler.java b/Rekeningsysteem/src/main/java/org/rekeningsysteem/logic/offerte/DefaultOfferteTextHandler.java index 44a0d30..8729d7b 100644 --- a/Rekeningsysteem/src/main/java/org/rekeningsysteem/logic/offerte/DefaultOfferteTextHandler.java +++ b/Rekeningsysteem/src/main/java/org/rekeningsysteem/logic/offerte/DefaultOfferteTextHandler.java @@ -37,10 +37,16 @@ public String getDefaultText() { .orElse(""); } - public void setDefaultText(String s) throws IOException, NoSuchFileException { + /** + * Stores the text in the file that was supplied by the constructor. + * @param text the text to be stored + * @throws IOException in case an IO exception occurs while writing to the file + * @throws NoSuchFileException if there was no file supplied by the constructor + */ + public void setDefaultText(String text) throws IOException, NoSuchFileException { if (this.file.isPresent()) { File f = this.file.get(); - FileUtils.writeStringToFile(f, s, false); + FileUtils.writeStringToFile(f, text, false); } else { throw new NoSuchFileException("Er bestaat geen file waarin deze tekst kan " From c786833900dbfcf34a04d4f50af44ee37ded2b9f Mon Sep 17 00:00:00 2001 From: Richard van Heest Date: Sun, 26 Jul 2015 19:53:11 +0200 Subject: [PATCH 8/8] Error handling on the default offerte text --- .../DefaultOfferteTextPaneController.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/offerte/DefaultOfferteTextPaneController.java b/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/offerte/DefaultOfferteTextPaneController.java index 006d330..b01b783 100644 --- a/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/offerte/DefaultOfferteTextPaneController.java +++ b/Rekeningsysteem/src/main/java/org/rekeningsysteem/application/settings/offerte/DefaultOfferteTextPaneController.java @@ -3,8 +3,14 @@ import java.io.IOException; import javafx.event.ActionEvent; +import javafx.scene.control.Alert; +import javafx.scene.control.ButtonType; +import javafx.scene.control.Alert.AlertType; +import javafx.scene.control.ButtonBar.ButtonData; +import org.apache.log4j.Logger; import org.rekeningsysteem.exception.NoSuchFileException; +import org.rekeningsysteem.logging.ApplicationLogger; import org.rekeningsysteem.logic.offerte.DefaultOfferteTextHandler; import rx.Observable; @@ -13,6 +19,8 @@ public class DefaultOfferteTextPaneController { private final DefaultOfferteTextPane ui; private final DefaultOfferteTextHandler handler = new DefaultOfferteTextHandler(); + + private final Logger logger = ApplicationLogger.getInstance(); public DefaultOfferteTextPaneController() { this.ui = new DefaultOfferteTextPane(); @@ -29,10 +37,16 @@ public DefaultOfferteTextPaneController() { this.handler.setDefaultText(s); } catch (IOException e) { - e.printStackTrace(); + this.logger.error("Error while writing default offerte text to file.", e); } catch (NoSuchFileException e) { - e.printStackTrace(); + String alertText = "De tekst kon niet worden opgeslagen. Raadpleeg " + + "de programmeur om dit probleem op te lossen."; + ButtonType close = new ButtonType("Sluit", ButtonData.CANCEL_CLOSE); + Alert alert = new Alert(AlertType.NONE, alertText, close); + alert.setHeaderText("Fout bij opslaan"); + alert.show(); + this.logger.error(e.getMessage() + "\n" + "De tekst was: \"" + s + "\"\n", e); } }); cancel.subscribe(e -> {