Skip to content

Commit

Permalink
added fxml controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
LeiLiYang committed Nov 22, 2023
1 parent 2f21ce7 commit a2d040e
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 47 deletions.
4 changes: 2 additions & 2 deletions .settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
arguments=--init-script /home/timmyhoa/.config/Code/User/globalStorage/redhat.java/1.23.0/config_linux/org.eclipse.osgi/55/0/.cp/gradle/init/init.gradle --init-script /home/timmyhoa/.config/Code/User/globalStorage/redhat.java/1.23.0/config_linux/org.eclipse.osgi/55/0/.cp/gradle/protobuf/init.gradle
arguments=--init-script C\:\\Users\\liyan\\AppData\\Roaming\\Code\\User\\globalStorage\\redhat.java\\1.24.0\\config_win\\org.eclipse.osgi\\57\\0\\.cp\\gradle\\init\\init.gradle --init-script C\:\\Users\\liyan\\AppData\\Roaming\\Code\\User\\globalStorage\\redhat.java\\1.24.0\\config_win\\org.eclipse.osgi\\57\\0\\.cp\\gradle\\protobuf\\init.gradle
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=/usr/lib/jvm/java-19-openjdk-amd64
java.home=C\:/Program Files/Java/jdk-19
jvm.arguments=
offline.mode=false
override.workspace.settings=true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package ca.mcgill.ecse.assetplus.javafx.controllers;

import ca.mcgill.ecse.assetplus.controller.AssetPlusFeatureSet1Controller;
import static ca.mcgill.ecse.assetplus.javafx.controllers.ViewUtils.successful;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;

public class AddUserController {

@FXML
private TextField AddEmail;

@FXML
private TextField AddName;

@FXML
private TextField AddPassword;

@FXML
private TextField AddPhone;

@FXML
private Button AddUser;

@FXML
private Button cancelAddUser;

@FXML
void addUserClicked(ActionEvent event) {
String name = AddEmail.getText();
String email = AddEmail.getText();
String password = AddPassword.getText();
String phone = AddPhone.getText();
if (successful(AssetPlusFeatureSet1Controller.addEmployeeOrGuest(email, password, name, phone, true))) {
AddEmail.setText("");
AddName.setText("");
AddPassword.setText("");
AddPhone.setText("");
}
// NEED TO RETURN TO USER VIEW PAGE, IF APPLICABLE

}

@FXML
void cancelAddUserClicked(ActionEvent event) {
AddEmail.setText("");
AddName.setText("");
AddPassword.setText("");
AddPhone.setText("");
// NEED TO RETURN TO USER VIEW PAGE
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package ca.mcgill.ecse.assetplus.javafx.controllers;

import ca.mcgill.ecse.assetplus.controller.AssetPlusFeatureSet1Controller;
import static ca.mcgill.ecse.assetplus.javafx.controllers.ViewUtils.successful;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;

public class UpdatePasswordController {

@FXML
private Button cancelUpdatePassword;

@FXML
private TextField newPassword;

@FXML
private TextField newPasswordConfirm;

@FXML
private Button updatePassword;

@FXML
void cancelUpdatePasswordClicked(ActionEvent event) {

}

@FXML
void updatePasswordClicked(ActionEvent event) {
String password = newPassword.getText();
String passowrdConfirm = newPasswordConfirm.getText();
if (!password.equals(passowrdConfirm)) {
ViewUtils.showError("Please ensure that the new password match.");
} else if (successful(AssetPlusFeatureSet1Controller.updateManager(password))) {
newPassword.setText("");
newPasswordConfirm.setText("");
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package ca.mcgill.ecse.assetplus.javafx.controllers;

import java.util.List;
import ca.mcgill.ecse.assetplus.javafx.AssetPlusFxmlView;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.stage.Modality;
import javafx.stage.Stage;

public class ViewUtils {

/** Calls the controller and shows an error, if applicable. */
public static boolean callController(String result) {
if (result.isEmpty()) {
AssetPlusFxmlView.getInstance().refresh();
return true;
}
showError(result);
return false;
}

/** Calls the controller and returns true on success. This method is included for readability. */
public static boolean successful(String controllerResult) {
return callController(controllerResult);
}

/**
* Creates a popup window.
*
* @param title: title of the popup window
* @param message: message to display
*/
public static void makePopupWindow(String title, String message) {
Stage dialog = new Stage();
dialog.initModality(Modality.APPLICATION_MODAL);
VBox dialogPane = new VBox();

// create UI elements
Text text = new Text(message);
Button okButton = new Button("OK");
okButton.setOnAction(a -> dialog.close());

// display the popup window
int innerPadding = 10; // inner padding/spacing
int outerPadding = 100; // outer padding
dialogPane.setSpacing(innerPadding);
dialogPane.setAlignment(Pos.CENTER);
dialogPane.setPadding(new Insets(innerPadding, innerPadding, innerPadding, innerPadding));
dialogPane.getChildren().addAll(text, okButton);
Scene dialogScene = new Scene(dialogPane, outerPadding + 5 * message.length(), outerPadding);
dialog.setScene(dialogScene);
dialog.setTitle(title);
dialog.show();
}

public static void showError(String message) {
makePopupWindow("Error", message);
}
}
38 changes: 12 additions & 26 deletions src/main/java/ca/mcgill/ecse/assetplus/javafx/pages/AddUser.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.PasswordField?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.text.Font?>

<AnchorPane prefHeight="500.0" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1">
<AnchorPane prefHeight="500.0" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ca.mcgill.ecse.assetplus.javafx.controllers.AddUserController">
<children>
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.0" prefWidth="600.0">
<columnConstraints>
Expand All @@ -19,15 +19,13 @@
<rowConstraints>
<RowConstraints maxHeight="128.66668701171875" minHeight="0.0" prefHeight="37.99999874830246" valignment="CENTER" />
<RowConstraints maxHeight="247.33332316080725" minHeight="0.0" prefHeight="54.66667683919272" vgrow="SOMETIMES" />
<RowConstraints maxHeight="220.00003051757812" minHeight="10.0" prefHeight="49.33332316080728" vgrow="SOMETIMES" />
<RowConstraints maxHeight="220.00003051757812" minHeight="10.0" prefHeight="72.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="220.00003051757812" minHeight="10.0" prefHeight="68.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="220.00003051757812" minHeight="10.0" prefHeight="58.666646321614564" vgrow="SOMETIMES" />
<RowConstraints maxHeight="220.00003051757812" minHeight="10.0" prefHeight="63.33335367838538" vgrow="SOMETIMES" />
<RowConstraints maxHeight="220.00003051757812" minHeight="10.0" prefHeight="63.33335367838538" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Password: " GridPane.halignment="RIGHT" GridPane.rowIndex="5">
<Label text="Password: " GridPane.halignment="RIGHT" GridPane.rowIndex="3">
<font>
<Font size="18.0" />
</font>
Expand All @@ -37,47 +35,35 @@
<Font size="24.0" />
</font>
</Label>
<Label text="Last Name: " textAlignment="CENTER" GridPane.halignment="RIGHT" GridPane.rowIndex="1">
<Label text="Name: " textAlignment="CENTER" GridPane.halignment="RIGHT" GridPane.rowIndex="1">
<font>
<Font size="18.0" />
</font>
</Label>
<Label text="First Name: " GridPane.halignment="RIGHT" GridPane.rowIndex="2">
<Label text="Email: " GridPane.halignment="RIGHT" GridPane.rowIndex="2">
<font>
<Font size="18.0" />
</font>
</Label>
<Label text="Employee ID: " GridPane.halignment="RIGHT" GridPane.rowIndex="3">
<Label text="Phone Number: " GridPane.halignment="RIGHT" GridPane.rowIndex="4">
<font>
<Font size="18.0" />
</font>
</Label>
<PasswordField maxWidth="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<PasswordField maxWidth="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<PasswordField maxWidth="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Label text="Email: " GridPane.halignment="RIGHT" GridPane.rowIndex="4">
<font>
<Font size="18.0" />
</font>
</Label>
<Label text="Phone Number: " GridPane.halignment="RIGHT" GridPane.rowIndex="6">
<font>
<Font size="18.0" />
</font>
</Label>
<PasswordField layoutX="310.0" layoutY="175.0" maxWidth="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="4" />
<PasswordField layoutX="310.0" layoutY="245.0" maxWidth="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="5" />
<PasswordField layoutX="310.0" layoutY="309.0" maxWidth="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="6" />
<Button mnemonicParsing="false" text="Cancel" GridPane.rowIndex="7">
<Button fx:id="cancelAddUser" mnemonicParsing="false" onAction="#cancelAddUserClicked" text="Cancel" GridPane.rowIndex="5">
<font>
<Font size="18.0" />
</font>
</Button>
<Button mnemonicParsing="false" text="Add" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="7">
<Button fx:id="AddUser" mnemonicParsing="false" onAction="#addUserClicked" text="Add" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="5">
<font>
<Font size="18.0" />
</font>
</Button>
<TextField fx:id="AddName" maxWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<TextField fx:id="AddEmail" maxWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<TextField fx:id="AddPhone" maxWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="4" />
<TextField fx:id="AddPassword" layoutX="310.0" layoutY="357.0" maxWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="3" />
</children>
</GridPane>
</children>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.PasswordField?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.text.Font?>

<AnchorPane xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1">
<AnchorPane xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ca.mcgill.ecse.assetplus.javafx.controllers.UpdatePasswordController">
<children>
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0">
<columnConstraints>
Expand All @@ -19,7 +19,6 @@
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="128.66668701171875" minHeight="0.0" prefHeight="60.66665518283844" valignment="CENTER" />
<RowConstraints maxHeight="247.33332316080725" minHeight="0.0" prefHeight="94.33332316080728" vgrow="SOMETIMES" />
<RowConstraints maxHeight="220.00003051757812" minHeight="10.0" prefHeight="120.3333435058594" vgrow="SOMETIMES" />
<RowConstraints maxHeight="220.00003051757812" minHeight="10.0" prefHeight="132.33332316080725" vgrow="SOMETIMES" />
<RowConstraints maxHeight="220.00003051757812" minHeight="10.0" prefHeight="132.33332316080725" vgrow="SOMETIMES" />
Expand All @@ -30,37 +29,31 @@
<Font size="24.0" />
</font>
</Label>
<Label text="Current Password: " textAlignment="CENTER" GridPane.halignment="RIGHT" GridPane.rowIndex="1">
<Label text="New Password: " GridPane.halignment="RIGHT" GridPane.rowIndex="1">
<font>
<Font size="18.0" />
</font>
</Label>
<Label text="New Password: " GridPane.halignment="RIGHT" GridPane.rowIndex="2">
<Label text="Confirm New Password: " GridPane.halignment="RIGHT" GridPane.rowIndex="2">
<font>
<Font size="18.0" />
</font>
</Label>
<Label text="Confirm New Password: " GridPane.halignment="RIGHT" GridPane.rowIndex="3">
<font>
<Font size="18.0" />
</font>
</Label>
<PasswordField maxWidth="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<PasswordField maxWidth="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<PasswordField maxWidth="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Button mnemonicParsing="false" text="Cancel" GridPane.rowIndex="4">
<Button fx:id="cancelUpdatePassword" mnemonicParsing="false" onAction="#cancelUpdatePasswordClicked" text="Cancel" GridPane.rowIndex="3">
<font>
<Font size="18.0" />
</font>
</Button>
<Button mnemonicParsing="false" text="Update" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="4">
<Button fx:id="updatePassword" mnemonicParsing="false" onAction="#updatePasswordClicked" text="Update" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="3">
<font>
<Font size="18.0" />
</font>
<GridPane.margin>
<Insets />
</GridPane.margin>
</Button>
<TextField fx:id="newPassword" maxWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<TextField fx:id="newPasswordConfirm" maxWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="2" />
</children>
</GridPane>
</children>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>

<AnchorPane prefHeight="600.0" prefWidth="900.0" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1">
<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ca.mcgill.ecse.assetplus.javafx.controllers.UserViewController">
<children>
<VBox layoutX="0.5" layoutY="12.666666984558105" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
Expand All @@ -25,16 +25,16 @@
<RowConstraints maxHeight="55.333343505859375" minHeight="10.0" prefHeight="43.333343505859375" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Button contentDisplay="CENTER" mnemonicParsing="false" text="Add User" GridPane.columnIndex="2" />
<Button mnemonicParsing="false" text="Update Password" GridPane.columnIndex="1" />
<Button fx:id="addUser" contentDisplay="CENTER" mnemonicParsing="false" onAction="#addUserClicked" text="Add User" GridPane.columnIndex="2" />
<Button fx:id="updatePassword" mnemonicParsing="false" onAction="#updatePasswordClicked" text="Update Password" GridPane.columnIndex="1" />
<Label alignment="CENTER" contentDisplay="CENTER" prefHeight="74.0" prefWidth="250.0" text="User Management" textAlignment="CENTER">
<font>
<Font size="24.0" />
</font>
</Label>
</children>
</GridPane>
<TableView editable="true" prefHeight="355.0" prefWidth="600.0">
<TableView fx:id="userTableView" editable="true" prefHeight="355.0" prefWidth="600.0">
<columns>
<TableColumn prefWidth="76.00006353855133" text="Last Name" />
<TableColumn prefWidth="69.33330535888672" text="First Name" />
Expand Down

0 comments on commit a2d040e

Please sign in to comment.