Skip to content
Snippets Groups Projects
Commit cf34b524 authored by Syed OMAR's avatar Syed OMAR
Browse files

View All Services page should work now

parent dd1e2458
No related branches found
No related tags found
No related merge requests found
Pipeline #8294 canceled
......@@ -6,11 +6,14 @@ import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;
import java.io.IOException;
public class MainPageController {
@FXML private Button viewButton;
@FXML
private void handleAddService(ActionEvent event) {
try {
......
......@@ -5,6 +5,7 @@ import com.cpsc329pm.Data;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
......@@ -13,33 +14,45 @@ import javafx.scene.control.cell.PropertyValueFactory;
import java.util.List;
public class StoredServicesController {
private int num = 0;
@FXML private TableView<Data> tableView;
@FXML private TableColumn<Data, String> colService;
@FXML private TableColumn<Data, String> colUsername;
@FXML private TableColumn<Data, String> colPassword;
@FXML private TableColumn<Data, String> colNumber;
private final DataStorage dataStorage = new DataStorage("master_login.json"); // Assuming you have this class
@FXML
public void initialize() {
// Set cell value factories for actual data columns
colService.setCellValueFactory(new PropertyValueFactory<>("platform"));
colUsername.setCellValueFactory(new PropertyValueFactory<>("username"));
colPassword.setCellValueFactory(new PropertyValueFactory<>("password"));
// Set a custom cell value factory for row numbers
colNumber.setCellValueFactory(cellData -> {
int index = tableView.getItems().indexOf(cellData.getValue()) + 1;
return new javafx.beans.property.SimpleStringProperty(String.valueOf(index));
});
loadDataIntoTable();
}
@FXML
private void loadDataIntoTable() {
num++;
List<Data> dataList = dataStorage.getAllData();
// DEBUG: Check if data is retrieved
System.out.println("Retrieved Data: " + dataList);
// System.out.println("Retrieved Data: " + dataList);
ObservableList<Data> observableList = FXCollections.observableArrayList(dataList);
// DEBUG: Check if ObservableList is not empty
System.out.println("ObservableList Size: " + observableList.size());
// System.out.println("ObservableList Size: " + observableList.size());
tableView.setItems(observableList);
}
......
......@@ -20,7 +20,7 @@
<Button fx:id="addServiceButton" layoutX="10.0" layoutY="10.0" mnemonicParsing="false" onAction="#handleAddService" prefHeight="51.0" prefWidth="136.0" style="-fx-border-color: black; -fx-border-width: 0px 0px 2px 0px;" styleClass="backgroundColor" stylesheets="@LoginScene-Pane.css" text="Add New Service" />
<Button fx:id="deleteServiceButton" layoutX="10.0" layoutY="61.0" mnemonicParsing="false" onAction="#handleDeleteService" prefHeight="51.0" prefWidth="136.0" style="-fx-border-color: black; -fx-border-width: 0px 0px 2px 0px;" styleClass="backgroundColor" stylesheets="@LoginScene-Pane.css" text="Delete Service" />
<Button layoutX="10.0" layoutY="112.0" mnemonicParsing="false" prefHeight="51.0" prefWidth="136.0" style="-fx-border-color: black; -fx-border-width: 0px 0px 2px 0px;" styleClass="backgroundColor" stylesheets="@LoginScene-Pane.css" text="Delete All Service" />
<Button fx:id="viewServiceButton" layoutX="10.0" layoutY="163.0" mnemonicParsing="false" onAction="#viewAllServices" prefHeight="51.0" prefWidth="136.0" style="-fx-border-color: black; -fx-border-width: 0px 0px 2px 0px;" styleClass="backgroundColor" stylesheets="@LoginScene-Pane.css" text="View All services" />
<Button fx:id="viewButton" layoutX="10.0" layoutY="163.0" mnemonicParsing="false" onAction="#viewAllServices" prefHeight="51.0" prefWidth="136.0" style="-fx-border-color: black; -fx-border-width: 0px 0px 2px 0px;" styleClass="backgroundColor" stylesheets="@LoginScene-Pane.css" text="View All services" />
<Button fx:id="editServiceButton" mnemonicParsing="false" onAction="#handleEditService" prefHeight="51.0" prefWidth="136.0" style="-fx-border-color: black; -fx-border-width: 0px 0px 2px 0px;" styleClass="backgroundColor" stylesheets="@LoginScene-Pane.css" text="Edit Info" />
</children>
</VBox>
......
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Region?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1">
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.cpsc329pm.StoredServicesController">
<top>
<Label prefHeight="36.0" prefWidth="86.0" text="Stored Services" BorderPane.alignment="CENTER" />
<HBox BorderPane.alignment="CENTER">
<children>
<Region prefHeight="36.0" prefWidth="0.0" HBox.hgrow="ALWAYS" />
<Label alignment="CENTER" contentDisplay="CENTER" prefHeight="36.0" prefWidth="506.0" text="Stored Services" HBox.hgrow="ALWAYS" />
<Button fx:id="loadServices" contentDisplay="CENTER" mnemonicParsing="false" onAction="#loadDataIntoTable" prefHeight="37.0" prefWidth="59.0" style="-fx-background-radius: 0; -fx-border-radius: 0;" text="Load" HBox.hgrow="ALWAYS" />
</children>
</HBox>
</top>
<center>
<TableView fx:id="tableView" prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment