From fde59dfae9ccf9767193c7a8ce67ae27371f9638 Mon Sep 17 00:00:00 2001 From: Stefan Suhren Date: Mon, 30 Nov 2015 20:36:13 +0100 Subject: Put gradeList into grades --- src/de/fhswf/in/inf/se/notepadMinusMinus/Main.java | 15 ++++-------- .../in/inf/se/notepadMinusMinus/model/Grades.java | 27 ++++++++++++++-------- 2 files changed, 22 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/de/fhswf/in/inf/se/notepadMinusMinus/Main.java b/src/de/fhswf/in/inf/se/notepadMinusMinus/Main.java index 3a72d6b..eb22eb5 100644 --- a/src/de/fhswf/in/inf/se/notepadMinusMinus/Main.java +++ b/src/de/fhswf/in/inf/se/notepadMinusMinus/Main.java @@ -11,7 +11,6 @@ import de.fhswf.in.inf.se.notepadMinusMinus.model.Grade; import de.fhswf.in.inf.se.notepadMinusMinus.model.Grades; import de.fhswf.in.inf.se.notepadMinusMinus.view.MainViewController; import javafx.application.Application; -import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; @@ -28,8 +27,7 @@ import javafx.stage.Stage; */ public class Main extends Application { - private ObservableList gradeList = FXCollections - .observableArrayList(Grade.extractor()); + private Grades grades = new Grades(); private Stage primaryStage; @@ -83,7 +81,7 @@ public class Main extends Application */ public ObservableList getGradeList() { - return gradeList; + return grades.gradesProperty(); } /** @@ -174,8 +172,7 @@ public class Main extends Application // Reading XML from the file and unmarshalling. Grades wrapper = (Grades) um.unmarshal(file); - gradeList.clear(); - gradeList.addAll(wrapper.getGrades()); + grades.setGrades(wrapper.getGrades()); // Save the file path to the registry. setGradesFilePath(file); @@ -210,12 +207,8 @@ public class Main extends Application Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); - // Wrapping our grades data. - Grades wrapper = new Grades(); - wrapper.setGrades(gradeList); - // Marshalling and saving XML to the file. - m.marshal(wrapper, file); + m.marshal(grades, file); // Save the file path to the registry. setGradesFilePath(file); diff --git a/src/de/fhswf/in/inf/se/notepadMinusMinus/model/Grades.java b/src/de/fhswf/in/inf/se/notepadMinusMinus/model/Grades.java index 631097e..aafc1e6 100644 --- a/src/de/fhswf/in/inf/se/notepadMinusMinus/model/Grades.java +++ b/src/de/fhswf/in/inf/se/notepadMinusMinus/model/Grades.java @@ -1,7 +1,6 @@ package de.fhswf.in.inf.se.notepadMinusMinus.model; import java.math.BigDecimal; -import java.util.ArrayList; import java.util.List; import javax.xml.bind.annotation.XmlAttribute; @@ -10,6 +9,8 @@ import javax.xml.bind.annotation.XmlRootElement; import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleObjectProperty; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; /** * TODO Add comment here @@ -20,7 +21,8 @@ import javafx.beans.property.SimpleObjectProperty; @XmlRootElement(name = "grades") public class Grades { - protected List grades; + ObservableList grades = FXCollections + .observableArrayList(Grade.extractor()); private ObjectProperty thesis = new SimpleObjectProperty<>( new BigDecimal("0.0")); @@ -36,21 +38,28 @@ public class Grades @XmlElement(name = "grade", required = true) public List getGrades() { - if (grades == null) - { - grades = new ArrayList<>(); - } return this.grades; } /** * TODO Add method comment here * - * @param consumption + * @param grades */ - public void setGrades(List consumption) + public void setGrades(List grades) { - this.grades = consumption; + this.grades.clear(); + this.grades.setAll(grades); + } + + /** + * TODO Add method comment here + * + * @return + */ + public ObservableList gradesProperty() + { + return grades; } /** -- cgit v1.2.3-70-g09d2