main
Alexis Drai 3 years ago
parent 0ce049eed0
commit ede570dd8a

@ -5,7 +5,6 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="39201d7d-d87b-4c10-b0b0-e462b4f0b033" name="Changes" comment=""> <list default="true" id="39201d7d-d87b-4c10-b0b0-e462b4f0b033" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/data/Loader.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/data/Loader.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/data/Loader.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/data/Loader.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/data/Saver.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/data/Saver.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/data/Saver.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/data/Saver.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/model/Product.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/model/Product.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/model/Product.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/model/Product.java" afterDir="false" />
@ -93,7 +92,7 @@
<workItem from="1665590389139" duration="2198000" /> <workItem from="1665590389139" duration="2198000" />
<workItem from="1665651119385" duration="53000" /> <workItem from="1665651119385" duration="53000" />
<workItem from="1665652739206" duration="91000" /> <workItem from="1665652739206" duration="91000" />
<workItem from="1665679173344" duration="5011000" /> <workItem from="1665679173344" duration="5345000" />
</task> </task>
<task id="LOCAL-00001" summary=":truck: Set up main window"> <task id="LOCAL-00001" summary=":truck: Set up main window">
<created>1665143728540</created> <created>1665143728540</created>
@ -158,7 +157,14 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1665592583787</updated> <updated>1665592583787</updated>
</task> </task>
<option name="localTasksCounter" value="10" /> <task id="LOCAL-00010" summary=":bug:">
<created>1665687943184</created>
<option name="number" value="00010" />
<option name="presentableId" value="LOCAL-00010" />
<option name="project" value="LOCAL" />
<updated>1665687943184</updated>
</task>
<option name="localTasksCounter" value="11" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
@ -182,7 +188,8 @@
<MESSAGE value=":construction: WIP" /> <MESSAGE value=":construction: WIP" />
<MESSAGE value=" Update gitignore" /> <MESSAGE value=" Update gitignore" />
<MESSAGE value=":poop: Produce bad code that doesn't work&#10;&#10;I think we're looking at a restart in the near future" /> <MESSAGE value=":poop: Produce bad code that doesn't work&#10;&#10;I think we're looking at a restart in the near future" />
<option name="LAST_COMMIT_MESSAGE" value=":poop: Produce bad code that doesn't work&#10;&#10;I think we're looking at a restart in the near future" /> <MESSAGE value=":bug:" />
<option name="LAST_COMMIT_MESSAGE" value=":bug:" />
</component> </component>
<component name="XDebuggerManager"> <component name="XDebuggerManager">
<breakpoint-manager> <breakpoint-manager>

@ -11,7 +11,6 @@ public class Loader implements Loadable {
@Override @Override
public Shop load() throws IOException, ClassNotFoundException { public Shop load() throws IOException, ClassNotFoundException {
try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream("save.bin"))) { try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream("save.bin"))) {
System.out.println("...loading!...");
return (Shop) ois.readObject(); return (Shop) ois.readObject();
} }
} }

@ -11,7 +11,6 @@ public class Saver implements Savable {
@Override @Override
public void save(Shop model) throws IOException { public void save(Shop model) throws IOException {
try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("save.bin"))) { try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("save.bin"))) {
System.out.println("...saving!...");
oos.writeObject(model); oos.writeObject(model);
} }
} }

@ -16,6 +16,7 @@ public class Product implements Serializable {
} }
public Product() { public Product() {
this(null, 0.0);
} }
public String getName() { public String getName() {
@ -30,7 +31,6 @@ public class Product implements Serializable {
oldV, oldV,
getName() getName()
); );
System.out.println("set my name to " + name);
} }
public double getPrice() { public double getPrice() {
@ -45,7 +45,6 @@ public class Product implements Serializable {
oldV, oldV,
getPrice() getPrice()
); );
System.out.println("set my price to " + price);
} }
private PropertyChangeSupport support; private PropertyChangeSupport support;
@ -64,16 +63,4 @@ public class Product implements Serializable {
getSupport().addPropertyChangeListener(listener); getSupport().addPropertyChangeListener(listener);
} }
@Override
public int hashCode() {
return getName().hashCode();
}
@Override
public boolean equals(Object obj) {
return obj instanceof Product
&& ((Product) obj).getName() != null
&& ((Product) obj).getName().equals(getName());
}
} }

@ -52,7 +52,7 @@ public class MainWindow {
@FXML @FXML
private void clickAddProduct() { private void clickAddProduct() {
viewmodel.addGarmentVM(new GarmentVM("no_name", 0.0)); viewmodel.addGarmentVM(new GarmentVM());
} }
@ -76,7 +76,7 @@ public class MainWindow {
new Alert(Alert.AlertType.ERROR, new Alert(Alert.AlertType.ERROR,
"could not parse PRICE as a number, please try again", "could not parse PRICE as a number, please try again",
ButtonType.OK) ButtonType.OK)
.setHeaderText(null); .show();
} }
} }
@ -99,10 +99,11 @@ public class MainWindow {
creationWindowStage.setScene(new Scene(loader.load())); creationWindowStage.setScene(new Scene(loader.load()));
creationWindowStage.showAndWait(); creationWindowStage.showAndWait();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace();
new Alert(Alert.AlertType.ERROR, new Alert(Alert.AlertType.ERROR,
"error while opening product creation window", "error while opening product creation window",
ButtonType.OK) ButtonType.OK)
.setHeaderText(null); .show();
} }
return controller; return controller;
} }

@ -8,6 +8,14 @@ public class GarmentVM extends ProductVM {
private Garment model; private Garment model;
public GarmentVM(Object obj) {
super(obj);
}
public GarmentVM() {
super();
}
public GarmentVM(String name, Double price) { public GarmentVM(String name, Double price) {
super(name, price); super(name, price);
} }

@ -1,7 +1,21 @@
package viewmodel; package viewmodel;
import model.Perfume;
public class PerfumeVM extends ProductVM { public class PerfumeVM extends ProductVM {
private Perfume model;
public PerfumeVM(Object obj) {
super(obj);
}
public PerfumeVM() {
super();
}
public PerfumeVM(String name, Double price) { public PerfumeVM(String name, Double price) {
super(name, price); super(name, price);
} }
} }

@ -1,6 +1,9 @@
package viewmodel; package viewmodel;
import javafx.beans.property.*; import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import model.Product; import model.Product;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
@ -19,12 +22,18 @@ public class ProductVM implements PropertyChangeListener {
private final StringProperty name = new SimpleStringProperty(); private final StringProperty name = new SimpleStringProperty();
public ProductVM(String name, Double price) { public ProductVM(Object obj) {
model = new Product(); //loads
if (obj instanceof Product) {
model = (Product) obj;
}
else {
model = new Product();
}
//loads / sets setName(model.getName());
setName(name == null ? model.getName() : name); setPrice(model.getPrice());
setPrice(price == null ? model.getPrice() : price);
//subscribes //subscribes
model.addListener(this); model.addListener(this);
@ -34,9 +43,12 @@ public class ProductVM implements PropertyChangeListener {
priceProperty().addListener((__, ___, newV) -> model.setPrice((Double) newV)); priceProperty().addListener((__, ___, newV) -> model.setPrice((Double) newV));
} }
public ProductVM(Object o) { public ProductVM() {
this(o != null ? ((Product) o).getName() : null, this(null);
o != null ? ((Product) o).getPrice() : null); }
public ProductVM(String name, Double price) {
this(new Product(name, price));
} }
public String getName() { public String getName() {
@ -61,7 +73,6 @@ public class ProductVM implements PropertyChangeListener {
public void setPrice(double price) {this.price.set(price);} public void setPrice(double price) {this.price.set(price);}
@Override @Override
public void propertyChange(PropertyChangeEvent evt) { public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals(PROP_PRODUCT_NAME)) { if (evt.getPropertyName().equals(PROP_PRODUCT_NAME)) {

@ -1,5 +1,6 @@
package viewmodel; package viewmodel;
import data.Loadable;
import data.Loader; import data.Loader;
import data.Saver; import data.Saver;
import data.Stub; import data.Stub;
@ -17,7 +18,7 @@ import java.io.IOException;
public class ShopVM implements PropertyChangeListener { public class ShopVM implements PropertyChangeListener {
private Shop model; private final Shop model;
public Shop getModel() { public Shop getModel() {
return model; return model;
@ -30,44 +31,42 @@ public class ShopVM implements PropertyChangeListener {
public ShopVM() { public ShopVM() {
Shop tmpModel;
Loadable loader;
try { try {
System.out.println("trying real load"); loader = new Loader();
model = new Loader().load(); tmpModel = loader.load();
} catch (IOException | ClassNotFoundException ex1) { } catch (IOException | ClassNotFoundException ex1) {
ex1.printStackTrace();
try { try {
System.out.println("trying stub load"); loader = new Stub();
model = new Stub().load(); tmpModel = loader.load();
} catch (IOException | ClassNotFoundException ex2) { } catch (IOException | ClassNotFoundException ex2) {
System.out.println("giving up load and creating new"); ex2.printStackTrace();
model = new Shop(); tmpModel = new Shop();
} }
} }
model = tmpModel;
//subscribes //subscribes
model.addListener(this); model.addListener(this);
//loads //loads
model.getProducts().forEach(p -> productsVMObs.add(new ProductVM(p.getName(), p.getPrice()))); model.getProducts().forEach(p -> productsVMObs.add(new ProductVM(p)));
//will update with its methods //will update with its methods
} }
public void removeProduct(ProductVM productVM) { public void removeProduct(ProductVM productVM) {
productsVMObs.remove(productVM);
getModel().removeProduct(productVM.getModel()); getModel().removeProduct(productVM.getModel());
printModel();
} }
public void addGarmentVM(GarmentVM garmentVM) { public void addGarmentVM(GarmentVM garmentVM) {
productsVMObs.add(garmentVM);
getModel().addProduct(garmentVM.getModel()); getModel().addProduct(garmentVM.getModel());
printModel();
} }
public void addPerfumeVM(PerfumeVM perfumeVM) { public void addPerfumeVM(PerfumeVM perfumeVM) {
productsVMObs.add(perfumeVM);
getModel().addProduct(perfumeVM.getModel()); getModel().addProduct(perfumeVM.getModel());
printModel();
} }
public void save() throws IOException { public void save() throws IOException {
@ -75,19 +74,13 @@ public class ShopVM implements PropertyChangeListener {
saver.save(getModel()); saver.save(getModel());
} }
private void printModel() {
System.out.println("printing model.................");
getModel().getProducts().forEach(p -> System.out.println(p.getName() + " : " + p.getPrice()));
}
@Override @Override
public void propertyChange(PropertyChangeEvent evt) { public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals(Shop.PROP_SHOP_ADD)) { if (evt.getPropertyName().equals(Shop.PROP_SHOP_ADD)) {
ProductVM pvm = new ProductVM(evt.getNewValue()); productsVMObs.add(((IndexedPropertyChangeEvent) evt).getIndex(), new ProductVM(evt.getNewValue()));
productsVMObs.add(((IndexedPropertyChangeEvent) evt).getIndex(), pvm);
} }
if (evt.getPropertyName().equals(Shop.PROP_SHOP_RMV)) { if (evt.getPropertyName().equals(Shop.PROP_SHOP_RMV)) {
productsVMObs.remove(new ProductVM(evt.getOldValue())); // redefined equals an toHash productsVMObs.remove(((IndexedPropertyChangeEvent) evt).getIndex());
} }
} }
} }

Loading…
Cancel
Save