From 1b368119ac1c696e20b952a46b4bdd25b57e783b Mon Sep 17 00:00:00 2001 From: Amirhossein Arabzadeh Date: Fri, 26 Jun 2020 23:57:35 +0430 Subject: [PATCH] last fix --- src/main/java/Model/Category.java | 7 +++--- src/main/java/Model/Product.java | 2 +- src/main/java/org/example/ProductPage.java | 2 ++ src/main/java/org/example/ProductsPage.java | 22 +++++++++++++------ .../resources/org/example/ProductsPage.fxml | 2 +- .../org/example/manager-products.fxml | 1 - .../resources/org/example/users-managing.fxml | 2 +- 7 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/main/java/Model/Category.java b/src/main/java/Model/Category.java index 843eac9..6ad8fb1 100644 --- a/src/main/java/Model/Category.java +++ b/src/main/java/Model/Category.java @@ -8,7 +8,7 @@ public class Category extends SaveAble { private static ArrayList allCategories = new ArrayList<>(); private String name; private ArrayList tags; - private ArrayList subCategories; + private ArrayList subCategories = new ArrayList<>(); private ArrayList products; public Category(String name, ArrayList tags, ArrayList products, ArrayList subCategories) { @@ -20,6 +20,7 @@ public Category(String name, ArrayList tags, ArrayList products, this.subCategories = subCategories; this.products = products; for (String product: products) { + System.out.println(Product.getProductWithBarcode(product)); Product.getProductWithBarcode(product).setCategoryTags(tags); } allCategories.add(this); @@ -49,8 +50,8 @@ public String getName() { return name; } - public ArrayList getTags() { - return tags; + public String getTags() { + return tags.toString(); } public String getSubCategories() { diff --git a/src/main/java/Model/Product.java b/src/main/java/Model/Product.java index f68af6d..9ab0e70 100644 --- a/src/main/java/Model/Product.java +++ b/src/main/java/Model/Product.java @@ -314,7 +314,7 @@ public static String givenUsingPlainJava_whenGeneratingRandomStringUnbounded_the } public void setCategoryTags(ArrayList categoryTags) { - this.categoryTags.addAll(categoryTags); + this.tags.addAll(categoryTags); } diff --git a/src/main/java/org/example/ProductPage.java b/src/main/java/org/example/ProductPage.java index 85d072d..e38e93c 100644 --- a/src/main/java/org/example/ProductPage.java +++ b/src/main/java/org/example/ProductPage.java @@ -47,6 +47,7 @@ public static void setProduct(Product product) { } public void addToCart() { + Controller.getOurController().requestAddProductToCart(product.getProductBarcode()); } @@ -81,6 +82,7 @@ public void initialize() { } for (MenuItem menuItem : menuItems) { sellers.getItems().add(menuItem); + menuItem.setOnAction(event -> Controller.getOurController().setNameOfSellerOfProductAddedToCart(menuItem.getText())); } diff --git a/src/main/java/org/example/ProductsPage.java b/src/main/java/org/example/ProductsPage.java index c07a34d..e3ae751 100644 --- a/src/main/java/org/example/ProductsPage.java +++ b/src/main/java/org/example/ProductsPage.java @@ -55,6 +55,7 @@ public void initialize() { max = product.getCost(); } slider.setMax(max + 20); + slider.setValue(max + 20); slider.valueProperty().addListener( new ChangeListener() { public void changed(ObservableValue observable, Number oldValue, Number newValue) @@ -154,18 +155,21 @@ private void activeAvailable( CheckBox checkBox) { private void categoryCheckBoxInitialize(int i, int y, HashSet tags) { for (Product product : Product.getAllProducts()) { + if (product.getCategory() == null) { + continue; + } if (tags.contains(product.getCategory())) { continue; } Category category; CheckBox checkBox; - if((category = Category.getCategoryByName(product.getCategory())) == null){ + if((category = Category.getCategoryByName(product.getCategory())) != null && product.getCategory() !=null){ checkBox = new CheckBox("catgory :" + product.getCategory() + "subcat" + category.getSubCategories() + "tags" + category.getTags()); - }else { + }else{ checkBox = new CheckBox("catgory :" + product.getCategory()); } checkBox.setLayoutX(i); - i += 50; + i += 500; checkBox.setLayoutY(y); mainAnchorPane.getChildren().add(checkBox); tags.add(product.getCategory()); @@ -184,12 +188,16 @@ private void categoryActive(String catName, CheckBox checkBox) { return; } if(checkBox.isSelected()){ - for (String categoryTag : category.getTags()) { - filters.add(categoryTag); + for (String categoryTag : category.getTags().substring(category.getTags().indexOf("[") +1, category.getTags().lastIndexOf("]")).split(",")) { +// System.out.println(categoryTag); +// categoryTag = categoryTag.substring(categoryTag.indexOf("\""), categoryTag.lastIndexOf("\"")); +// System.out.println(categoryTag); + filters.add(categoryTag.trim()); } }else{ - for (String categoryTag : category.getTags()) { - filters.remove(categoryTag); + for (String categoryTag : category.getTags().substring(category.getTags().indexOf("[") +1, category.getTags().lastIndexOf("]")).split(",")) { +// categoryTag = categoryTag.substring(categoryTag.indexOf("\""), categoryTag.lastIndexOf("\"")); + filters.remove(categoryTag.trim()); } } fullFilter(); diff --git a/src/main/resources/org/example/ProductsPage.fxml b/src/main/resources/org/example/ProductsPage.fxml index 4949523..5418272 100644 --- a/src/main/resources/org/example/ProductsPage.fxml +++ b/src/main/resources/org/example/ProductsPage.fxml @@ -23,6 +23,6 @@