Skip to content

Commit

Permalink
Merge pull request #32 from rvanheest/Bugfixes
Browse files Browse the repository at this point in the history
Bugfixes and small improvements
  • Loading branch information
Richard van Heest authored and Richard van Heest committed Jul 26, 2015
2 parents af601cd + c786833 commit bbcd7fe
Show file tree
Hide file tree
Showing 14 changed files with 321 additions and 33 deletions.
2 changes: 2 additions & 0 deletions Rekeningsysteem/config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ 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
factuurnummerfile=resources\\factuurnummer.txt
pdfreparatiestemplate=resources\\LaTeX\\ReparatiesFactuur.tex
offertedefaulttextlocation=resources\\default offerte tekst.txt
2 changes: 2 additions & 0 deletions Rekeningsysteem/resources/default offerte tekst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This is a testing text!
Here you can put your name, adres, etc.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class DebiteurSettingsTabController {

private DebiteurSettingsTab ui;
private final DebiteurSettingsTab ui;

public DebiteurSettingsTabController(Database database) {
this(new DebiteurTablePaneController(database));
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> text = Observables.fromProperty(this.textTA.textProperty());
private final Observable<ActionEvent> save = Observables.fromNodeEvents(this.saveButton, ActionEvent.ACTION);
private final Observable<ActionEvent> 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<String> getText() {
return this.text;
}

public void setText(String text) {
this.textTA.setText(text);
}

public Observable<ActionEvent> getSaveButtonEvent() {
return this.save;
}

public Observable<ActionEvent> getCancelButtonEvent() {
return this.cancel;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.rekeningsysteem.application.settings.offerte;

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;

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();

Observable<String> text = this.ui.getText();
Observable<ActionEvent> save = this.ui.getSaveButtonEvent();
Observable<ActionEvent> cancel = this.ui.getCancelButtonEvent();

this.ui.setText(this.handler.getDefaultText());

text.sample(save)
.subscribe(s -> {
try {
this.handler.setDefaultText(s);
}
catch (IOException e) {
this.logger.error("Error while writing default offerte text to file.", e);
}
catch (NoSuchFileException e) {
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 -> {
String s = this.handler.getDefaultText();
this.ui.setText(s);
});
}

public DefaultOfferteTextPane getUI() {
return this.ui;
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -179,10 +203,19 @@ 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<File> 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);
Expand All @@ -192,22 +225,38 @@ private Observable<File> showOpenFileChooser(Stage stage) {
.filter(Objects::nonNull);
}

private Optional<File> showSaveFileChooser(Stage stage) {
File initDir = new File(this.properties.getProperty(PropertyModelEnum.LAST_SAVE_LOCATION)
private Optional<File> showSaveFileChooser(PropertyKey key, Stage stage) {
File initDir = new File(this.properties.getProperty(key)
.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);
chooser.getExtensionFilters().addAll(new ExtensionFilter("XML", "*.xml"));

return Optional.ofNullable(chooser.showSaveDialog(stage));
}

private Optional<File> showSaveFileChooser(Stage stage) {
return this.showSaveFileChooser(PropertyModelEnum.LAST_SAVE_LOCATION, stage);
}

private Optional<File> showSaveFileChooserOfferte(Stage stage) {
return this.showSaveFileChooser(PropertyModelEnum.LAST_SAVE_LOCATION_OFFERTE, stage);
}

private Optional<File> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,19 @@ else if (file.getName().endsWith(".xml")) {
Observable<? extends AbstractRekening> factuur = ioWorker.load(file);

Observable<AangenomenController> aangenomen = factuur
.filter(a -> a instanceof AangenomenFactuur)
.cast(AangenomenFactuur.class)
.ofType(AangenomenFactuur.class)
.map(fact -> new AangenomenController(fact, database));
Observable<MutatiesController> mutaties = factuur
.filter(m -> m instanceof MutatiesFactuur)
.cast(MutatiesFactuur.class)
.ofType(MutatiesFactuur.class)
.map(fact -> new MutatiesController(fact, database));
Observable<OfferteController> offerte = factuur
.filter(o -> o instanceof Offerte)
.cast(Offerte.class)
.ofType(Offerte.class)
.map(fact -> new OfferteController(fact, database));
Observable<ParticulierController> particulier = factuur
.filter(p -> p instanceof ParticulierFactuur)
.cast(ParticulierFactuur.class)
.ofType(ParticulierFactuur.class)
.map(fact -> new ParticulierController(fact, database));
Observable<ReparatiesController> 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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Loading

0 comments on commit bbcd7fe

Please sign in to comment.