Skip to content

Commit

Permalink
Set default text for offerte via settings pane
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard van Heest authored and Richard van Heest committed Jul 26, 2015
1 parent adec6e8 commit 1a59662
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 4 deletions.
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,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<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) {
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;
}
}
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 @@ -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 "
Expand Down

0 comments on commit 1a59662

Please sign in to comment.