-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProductList.java
72 lines (56 loc) · 2.41 KB
/
ProductList.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package com.e_commerce.ecommerce;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.VBox;
public class ProductList {
TableView<Product> productTable;
TableView<Product> cartTable;
public VBox createTable(ObservableList<Product> data){
// Columns
TableColumn id = new TableColumn("ID");
id.setCellValueFactory(new PropertyValueFactory<>("id"));
TableColumn name = new TableColumn("Name");
name.setCellValueFactory(new PropertyValueFactory<>("name"));
TableColumn price = new TableColumn("Price");
price.setCellValueFactory(new PropertyValueFactory<>("price"));
productTable = new TableView<>();
productTable.getColumns().addAll(id, name,price);
productTable.setItems(data);
productTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
VBox vbox = new VBox();
vbox.getChildren().addAll(productTable);
vbox.setPadding(new Insets(10));
return vbox;
}
public VBox createCartTable(ObservableList<Product> data){
TableColumn id = new TableColumn("ID");
id.setCellValueFactory(new PropertyValueFactory<>("id"));
TableColumn name = new TableColumn("Name");
name.setCellValueFactory(new PropertyValueFactory<>("name"));
TableColumn price = new TableColumn("Price");
price.setCellValueFactory(new PropertyValueFactory<>("price"));
cartTable = new TableView<>();
cartTable.getColumns().addAll(id, name,price);
cartTable.setItems(data);
cartTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
VBox vbox = new VBox();
vbox.getChildren().addAll(cartTable);
vbox.setPadding(new Insets(10));
return vbox;
}
public VBox getAllProducts(){
ObservableList<Product> data = Product.getAllProduct();
VBox vBox = createTable(data);
return vBox;
}
public Product getSelectedProduct(){
return productTable.getSelectionModel().getSelectedItem();
}
public VBox getProductsInCart(ObservableList<Product> data){
return createCartTable(data);
}
}