#8: Implement User Permissions System Base and usage with Tabs
Signed-off-by: Dominik Säume <Dominik.Saeume@hmmh.de>
This commit is contained in:
parent
050747d09a
commit
9663b4c0b5
13 changed files with 228 additions and 260 deletions
Binary file not shown.
|
@ -2,6 +2,8 @@ package de.hitec.nhplus;
|
||||||
|
|
||||||
import de.hitec.nhplus.datastorage.ConnectionBuilder;
|
import de.hitec.nhplus.datastorage.ConnectionBuilder;
|
||||||
import de.hitec.nhplus.login.LoginController;
|
import de.hitec.nhplus.login.LoginController;
|
||||||
|
import de.hitec.nhplus.login.User;
|
||||||
|
import de.hitec.nhplus.main.MainWindowController;
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
|
@ -54,8 +56,8 @@ public class Main extends Application {
|
||||||
|
|
||||||
loginStage.showAndWait();
|
loginStage.showAndWait();
|
||||||
|
|
||||||
if(controller.user == null){
|
if(controller.user != null){
|
||||||
executeMainApplication();
|
executeMainApplication(controller.user);
|
||||||
}
|
}
|
||||||
} catch (IOException exception) {
|
} catch (IOException exception) {
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
|
@ -65,7 +67,7 @@ public class Main extends Application {
|
||||||
/**
|
/**
|
||||||
* Executes the main application.
|
* Executes the main application.
|
||||||
*/
|
*/
|
||||||
private void executeMainApplication() {
|
private void executeMainApplication(User user) {
|
||||||
try {
|
try {
|
||||||
FXMLLoader loader = new FXMLLoader(Main.class.getResource("/de/hitec/nhplus/main/MainWindowView.fxml"));
|
FXMLLoader loader = new FXMLLoader(Main.class.getResource("/de/hitec/nhplus/main/MainWindowView.fxml"));
|
||||||
TabPane pane = loader.load();
|
TabPane pane = loader.load();
|
||||||
|
@ -74,6 +76,10 @@ public class Main extends Application {
|
||||||
this.primaryStage.setTitle("NHPlus");
|
this.primaryStage.setTitle("NHPlus");
|
||||||
this.primaryStage.setScene(scene);
|
this.primaryStage.setScene(scene);
|
||||||
this.primaryStage.setResizable(true);
|
this.primaryStage.setResizable(true);
|
||||||
|
|
||||||
|
MainWindowController controller = loader.getController();
|
||||||
|
controller.initialize(user);
|
||||||
|
|
||||||
this.primaryStage.show();
|
this.primaryStage.show();
|
||||||
|
|
||||||
this.primaryStage.setOnCloseRequest(event -> {
|
this.primaryStage.setOnCloseRequest(event -> {
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class Fixtures {
|
||||||
medicationFixture.setupTable(connection);
|
medicationFixture.setupTable(connection);
|
||||||
medicationFixture.load();
|
medicationFixture.load();
|
||||||
|
|
||||||
UserFixture userFixture = new UserFixture();
|
UserFixture userFixture = new UserFixture(nursesByName);
|
||||||
userFixture.dropTable(connection);
|
userFixture.dropTable(connection);
|
||||||
userFixture.setupTable(connection);
|
userFixture.setupTable(connection);
|
||||||
userFixture.load();
|
userFixture.load();
|
||||||
|
|
|
@ -54,6 +54,12 @@ public class NurseFixture implements Fixture<Nurse> {
|
||||||
true
|
true
|
||||||
));
|
));
|
||||||
|
|
||||||
|
nurses.add(new Nurse(
|
||||||
|
"Maria",
|
||||||
|
"Höller",
|
||||||
|
"666"
|
||||||
|
));
|
||||||
|
|
||||||
NurseDao dao = DaoFactory.getInstance().createNurseDAO();
|
NurseDao dao = DaoFactory.getInstance().createNurseDAO();
|
||||||
for (Nurse nurse : nurses) {
|
for (Nurse nurse : nurses) {
|
||||||
dao.create(nurse);
|
dao.create(nurse);
|
||||||
|
|
|
@ -2,9 +2,10 @@ package de.hitec.nhplus.fixtures;
|
||||||
|
|
||||||
import de.hitec.nhplus.Main;
|
import de.hitec.nhplus.Main;
|
||||||
import de.hitec.nhplus.datastorage.DaoFactory;
|
import de.hitec.nhplus.datastorage.DaoFactory;
|
||||||
|
import de.hitec.nhplus.login.Permissions;
|
||||||
import de.hitec.nhplus.login.User;
|
import de.hitec.nhplus.login.User;
|
||||||
import de.hitec.nhplus.login.database.UserDao;
|
import de.hitec.nhplus.login.database.UserDao;
|
||||||
import de.hitec.nhplus.medication.Medication;
|
import de.hitec.nhplus.nurse.Nurse;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
@ -16,6 +17,13 @@ public class UserFixture implements Fixture<User>{
|
||||||
private static final String SCHEMA = "/de/hitec/nhplus/login/database/User.sql";
|
private static final String SCHEMA = "/de/hitec/nhplus/login/database/User.sql";
|
||||||
private static final String PERMISSION_SCHEMA = "/de/hitec/nhplus/login/database/UserPermission.sql";
|
private static final String PERMISSION_SCHEMA = "/de/hitec/nhplus/login/database/UserPermission.sql";
|
||||||
private static final String TO_NURSE_SCHEMA = "/de/hitec/nhplus/login/database/UserToNurse.sql";
|
private static final String TO_NURSE_SCHEMA = "/de/hitec/nhplus/login/database/UserToNurse.sql";
|
||||||
|
|
||||||
|
private final Map<String, Nurse> nursesByName;
|
||||||
|
|
||||||
|
public UserFixture(Map<String, Nurse> nursesByName) {
|
||||||
|
this.nursesByName = nursesByName;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dropTable(Connection connection) throws SQLException {
|
public void dropTable(Connection connection) throws SQLException {
|
||||||
connection.createStatement().execute("DROP TABLE IF EXISTS user");
|
connection.createStatement().execute("DROP TABLE IF EXISTS user");
|
||||||
|
@ -54,9 +62,7 @@ public class UserFixture implements Fixture<User>{
|
||||||
|
|
||||||
User udo = new User(
|
User udo = new User(
|
||||||
"udo",
|
"udo",
|
||||||
null,
|
Permissions.OWNER,
|
||||||
null,
|
|
||||||
Integer.parseInt("00000001", 2),
|
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
udo.setPassword("uD0_187!");
|
udo.setPassword("uD0_187!");
|
||||||
|
@ -64,14 +70,28 @@ public class UserFixture implements Fixture<User>{
|
||||||
|
|
||||||
User maria = new User(
|
User maria = new User(
|
||||||
"maria",
|
"maria",
|
||||||
null,
|
Permissions.NURSE,
|
||||||
null,
|
nursesByName.get("Maria")
|
||||||
0,
|
|
||||||
null
|
|
||||||
);
|
);
|
||||||
maria.setPassword("H!mm3lf4hrt");
|
maria.setPassword("H!mm3lf4hrt");
|
||||||
users.add(maria);
|
users.add(maria);
|
||||||
|
|
||||||
|
User werner = new User(
|
||||||
|
"werner",
|
||||||
|
Permissions.MANAGEMENT,
|
||||||
|
null
|
||||||
|
);
|
||||||
|
werner.setPassword("TurboSchraube42!");
|
||||||
|
users.add(werner);
|
||||||
|
|
||||||
|
User fullPermissionsTestUser = new User(
|
||||||
|
"test",
|
||||||
|
-1,
|
||||||
|
null
|
||||||
|
);
|
||||||
|
fullPermissionsTestUser.setPassword("");
|
||||||
|
users.add(fullPermissionsTestUser);
|
||||||
|
|
||||||
UserDao dao = DaoFactory.getInstance().createUserDAO();
|
UserDao dao = DaoFactory.getInstance().createUserDAO();
|
||||||
Map<String, User> usersByUsername = new HashMap<>();
|
Map<String, User> usersByUsername = new HashMap<>();
|
||||||
for (User user : users){
|
for (User user : users){
|
||||||
|
|
|
@ -88,6 +88,5 @@ public class LoginController {
|
||||||
} catch (SQLException | NoSuchAlgorithmException exception) {
|
} catch (SQLException | NoSuchAlgorithmException exception) {
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
8
src/main/java/de/hitec/nhplus/login/Permissions.java
Normal file
8
src/main/java/de/hitec/nhplus/login/Permissions.java
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
package de.hitec.nhplus.login;
|
||||||
|
|
||||||
|
public class Permissions {
|
||||||
|
public final static int EVERYBODY = 0b0;
|
||||||
|
public final static int NURSE = 0b1;
|
||||||
|
public final static int MANAGEMENT = 0b10;
|
||||||
|
public final static int OWNER = 0b100;
|
||||||
|
}
|
|
@ -9,6 +9,7 @@ import java.security.SecureRandom;
|
||||||
|
|
||||||
public class User {
|
public class User {
|
||||||
|
|
||||||
|
|
||||||
private int id;
|
private int id;
|
||||||
private String username;
|
private String username;
|
||||||
private byte[] passwordSalt;
|
private byte[] passwordSalt;
|
||||||
|
@ -34,30 +35,13 @@ public class User {
|
||||||
|
|
||||||
public User(
|
public User(
|
||||||
String username,
|
String username,
|
||||||
byte[] passwordSalt,
|
|
||||||
byte[] passwordHash,
|
|
||||||
int permissions,
|
int permissions,
|
||||||
Nurse nurse
|
Nurse nurse
|
||||||
) {
|
) {
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.passwordSalt = passwordSalt;
|
|
||||||
this.passwordHash = passwordHash;
|
|
||||||
this.permissions = permissions;
|
this.permissions = permissions;
|
||||||
this.nurse = nurse;
|
this.nurse = nurse;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] getPasswordSalt() {
|
|
||||||
return passwordSalt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] getPasswordHash() {
|
|
||||||
return passwordHash;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPassword(String password) {
|
public void setPassword(String password) {
|
||||||
try {
|
try {
|
||||||
SecureRandom random = new SecureRandom();
|
SecureRandom random = new SecureRandom();
|
||||||
|
@ -72,6 +56,25 @@ public class User {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasNursePermissions(){
|
||||||
|
return (permissions & Permissions.NURSE) != 0;
|
||||||
|
}
|
||||||
|
public boolean hasAdminPermissions(){
|
||||||
|
return (permissions & Permissions.MANAGEMENT) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getPasswordSalt() {
|
||||||
|
return passwordSalt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getPasswordHash() {
|
||||||
|
return passwordHash;
|
||||||
|
}
|
||||||
|
|
||||||
public String getUsername() {
|
public String getUsername() {
|
||||||
return username;
|
return username;
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,7 +86,7 @@ public class UserDao implements Dao<User> {
|
||||||
statement.setBytes(3, user.getPasswordHash());
|
statement.setBytes(3, user.getPasswordHash());
|
||||||
statement.execute();
|
statement.execute();
|
||||||
|
|
||||||
ResultSet generatedKeys = connection.createStatement().executeQuery("SELECT id FROM user");
|
ResultSet generatedKeys = connection.createStatement().executeQuery("SELECT last_insert_rowid()");
|
||||||
connection.commit(); //Finish SQL Transaction
|
connection.commit(); //Finish SQL Transaction
|
||||||
connection.setAutoCommit(true); //Switch back Mode
|
connection.setAutoCommit(true); //Switch back Mode
|
||||||
|
|
||||||
|
@ -112,13 +112,11 @@ public class UserDao implements Dao<User> {
|
||||||
INSERT INTO user__nurse
|
INSERT INTO user__nurse
|
||||||
(userId, nurseId)
|
(userId, nurseId)
|
||||||
VALUES (?, ?);
|
VALUES (?, ?);
|
||||||
|
|
||||||
|
|
||||||
""";
|
""";
|
||||||
PreparedStatement nurseStatement = this.connection.prepareStatement(nurseSQL);
|
PreparedStatement nurseStatement = this.connection.prepareStatement(nurseSQL);
|
||||||
permissionStatement.setInt(1, newId);
|
nurseStatement.setInt(1, newId);
|
||||||
permissionStatement.setInt(2, user.getNurse().getId());
|
nurseStatement.setInt(2, user.getNurse().getId());
|
||||||
permissionStatement.execute();
|
nurseStatement.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,20 +1,15 @@
|
||||||
package de.hitec.nhplus.main;
|
package de.hitec.nhplus.main;
|
||||||
|
|
||||||
import de.hitec.nhplus.Main;
|
import de.hitec.nhplus.login.Permissions;
|
||||||
import de.hitec.nhplus.nurse.Nurse;
|
import de.hitec.nhplus.login.User;
|
||||||
|
import de.hitec.nhplus.utils.tab.TabManager;
|
||||||
|
import de.hitec.nhplus.utils.tab.TabStruct;
|
||||||
|
import javafx.event.Event;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.FXMLLoader;
|
|
||||||
import javafx.scene.control.SelectionModel;
|
|
||||||
import javafx.scene.control.Tab;
|
import javafx.scene.control.Tab;
|
||||||
import javafx.scene.control.TabPane;
|
import javafx.scene.control.TabPane;
|
||||||
import javafx.scene.layout.AnchorPane;
|
|
||||||
import javafx.scene.layout.BorderPane;
|
|
||||||
import de.hitec.nhplus.treatment.Treatment;
|
|
||||||
import de.hitec.nhplus.medication.Medication;
|
|
||||||
import de.hitec.nhplus.patient.Patient;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller for the main window of the application, which holds all tabs.
|
* Controller for the main window of the application, which holds all tabs.
|
||||||
|
@ -26,199 +21,65 @@ import java.util.Objects;
|
||||||
*/
|
*/
|
||||||
public class MainWindowController {
|
public class MainWindowController {
|
||||||
@FXML
|
@FXML
|
||||||
private TabPane mainTabPane;
|
public TabPane mainTabPane;
|
||||||
@FXML
|
|
||||||
private AnchorPane patientPage;
|
private User user;
|
||||||
@FXML
|
private TabManager tabManager;
|
||||||
private Tab patientTab;
|
|
||||||
@FXML
|
|
||||||
private AnchorPane activeTreatmentPage;
|
|
||||||
@FXML
|
|
||||||
private Tab treatmentTab;
|
|
||||||
@FXML
|
|
||||||
private TabPane treatmentTabPane;
|
|
||||||
@FXML
|
|
||||||
private Tab activeTreatmentTab;
|
|
||||||
@FXML
|
|
||||||
private AnchorPane lockedTreatmentPage;
|
|
||||||
@FXML
|
|
||||||
private Tab lockedTreatmentTab;
|
|
||||||
@FXML
|
|
||||||
private Tab nurseTab;
|
|
||||||
@FXML
|
|
||||||
private TabPane nurseTabPane;
|
|
||||||
@FXML
|
|
||||||
private AnchorPane activeNursePage;
|
|
||||||
@FXML
|
|
||||||
private Tab activeNurseTab;
|
|
||||||
@FXML
|
|
||||||
private AnchorPane lockedNursePage;
|
|
||||||
@FXML
|
|
||||||
private Tab lockedNurseTab;
|
|
||||||
@FXML
|
|
||||||
private AnchorPane medicationPage;
|
|
||||||
@FXML
|
|
||||||
private Tab medicationTab;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialization method that is called after the binding of all the fields.
|
* JavaFX Initialization method that is called after the binding of all the fields.
|
||||||
|
*
|
||||||
|
* @param user The logged in {@link User}.
|
||||||
*/
|
*/
|
||||||
@FXML
|
@FXML
|
||||||
public void initialize() {
|
public void initialize(User user) {
|
||||||
loadPatientPage();
|
this.user = user;
|
||||||
mainTabPane.getSelectionModel().select(patientTab);
|
this.tabManager = new TabManager(user);
|
||||||
|
setupTabs();
|
||||||
patientTab.setOnSelectionChanged(event -> loadPatientPage());
|
|
||||||
medicationTab.setOnSelectionChanged(event -> loadMedicationPage());
|
|
||||||
|
|
||||||
|
|
||||||
nurseTab.setOnSelectionChanged(event -> loadNursePage());
|
|
||||||
nurseTabPane.getSelectionModel().select(activeNurseTab);
|
|
||||||
|
|
||||||
activeNurseTab.setOnSelectionChanged(event -> loadActiveNursePage());
|
|
||||||
lockedNurseTab.setOnSelectionChanged(event -> loadLockedNursePage());
|
|
||||||
|
|
||||||
treatmentTab.setOnSelectionChanged(event -> loadTreatmentPage());
|
|
||||||
treatmentTabPane.getSelectionModel().select(activeTreatmentTab);
|
|
||||||
|
|
||||||
activeTreatmentTab.setOnSelectionChanged(event -> loadActiveTreatmentPage());
|
|
||||||
lockedTreatmentTab.setOnSelectionChanged(event -> loadLockedTreatmentPage());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the {@link Patient} page into its tab.
|
* Sets up all Tabs Accessible, with help of the {@link TabManager}.
|
||||||
*/
|
*/
|
||||||
private void loadPatientPage() {
|
private void setupTabs() {
|
||||||
try {
|
tabManager.setupTab(mainTabPane, new TabStruct(
|
||||||
BorderPane patientsPane = FXMLLoader.load(
|
"Patienten",
|
||||||
Objects.requireNonNull(Main.class.getResource("/de/hitec/nhplus/patient/AllPatientView.fxml"))
|
"/de/hitec/nhplus/patient/AllPatientView.fxml",
|
||||||
);
|
Permissions.NURSE
|
||||||
patientPage.getChildren().setAll(patientsPane);
|
));
|
||||||
AnchorPane.setTopAnchor(patientsPane, 0d);
|
tabManager.setupSubTabPane(mainTabPane, "Behandlungen", Permissions.NURSE, List.of(
|
||||||
AnchorPane.setBottomAnchor(patientsPane, 0d);
|
new TabStruct(
|
||||||
AnchorPane.setLeftAnchor(patientsPane, 0d);
|
"Behandlungen",
|
||||||
AnchorPane.setRightAnchor(patientsPane, 0d);
|
"/de/hitec/nhplus/treatment/AllTreatmentView.fxml",
|
||||||
} catch (IOException exception) {
|
Permissions.NURSE
|
||||||
exception.printStackTrace();
|
),
|
||||||
}
|
new TabStruct(
|
||||||
}
|
"Gesperrte Behandlungen",
|
||||||
|
"/de/hitec/nhplus/treatment/LockedTreatmentView.fxml",
|
||||||
|
Permissions.NURSE
|
||||||
|
)
|
||||||
|
));
|
||||||
|
tabManager.setupSubTabPane(mainTabPane, "Pfleger", Permissions.EVERYBODY, List.of(
|
||||||
|
new TabStruct(
|
||||||
|
"Pfleger",
|
||||||
|
"/de/hitec/nhplus/nurse/AllNurseView.fxml",
|
||||||
|
Permissions.NURSE | Permissions.MANAGEMENT
|
||||||
|
),
|
||||||
|
new TabStruct(
|
||||||
|
"Gesperrte Pfleger",
|
||||||
|
"/de/hitec/nhplus/nurse/LockedNurseView.fxml",
|
||||||
|
Permissions.MANAGEMENT | Permissions.OWNER
|
||||||
|
)
|
||||||
|
));
|
||||||
|
tabManager.setupTab(mainTabPane, new TabStruct(
|
||||||
|
"Medikamente",
|
||||||
|
"/de/hitec/nhplus/medication/AllMedicationView.fxml",
|
||||||
|
Permissions.MANAGEMENT
|
||||||
|
));
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads the {@link Treatment } tab.
|
|
||||||
*/
|
|
||||||
private void loadTreatmentPage() {
|
|
||||||
SelectionModel<Tab> selectionModel = treatmentTabPane.getSelectionModel();
|
|
||||||
Tab selectedTab = selectionModel.getSelectedItem();
|
|
||||||
if (selectedTab == activeTreatmentTab) {
|
|
||||||
loadActiveTreatmentPage();
|
|
||||||
}
|
|
||||||
if (selectedTab == lockedTreatmentTab) {
|
|
||||||
loadLockedTreatmentPage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
Tab defaultTab = mainTabPane.getTabs().get(0);
|
||||||
* Loads the active {@link Treatment} page into its tab.
|
mainTabPane.getSelectionModel().select(defaultTab);
|
||||||
*/
|
defaultTab.getOnSelectionChanged().handle(new Event(Event.ANY));
|
||||||
private void loadActiveTreatmentPage() {
|
|
||||||
try {
|
|
||||||
BorderPane activeTreatmentPane = FXMLLoader.load(
|
|
||||||
Objects.requireNonNull(Main.class.getResource("/de/hitec/nhplus/treatment/AllTreatmentView.fxml"))
|
|
||||||
);
|
|
||||||
activeTreatmentPage.getChildren().setAll(activeTreatmentPane);
|
|
||||||
AnchorPane.setTopAnchor(activeTreatmentPane, 0d);
|
|
||||||
AnchorPane.setBottomAnchor(activeTreatmentPane, 0d);
|
|
||||||
AnchorPane.setLeftAnchor(activeTreatmentPane, 0d);
|
|
||||||
AnchorPane.setRightAnchor(activeTreatmentPane, 0d);
|
|
||||||
} catch (IOException exception) {
|
|
||||||
exception.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads the locked {@link Treatment} page into its tab.
|
|
||||||
*/
|
|
||||||
private void loadLockedTreatmentPage() {
|
|
||||||
try {
|
|
||||||
BorderPane treatmentsPane = FXMLLoader.load(
|
|
||||||
Objects.requireNonNull(Main.class.getResource("/de/hitec/nhplus/treatment/LockedTreatmentView.fxml"))
|
|
||||||
);
|
|
||||||
lockedTreatmentPage.getChildren().setAll(treatmentsPane);
|
|
||||||
AnchorPane.setTopAnchor(treatmentsPane, 0d);
|
|
||||||
AnchorPane.setBottomAnchor(treatmentsPane, 0d);
|
|
||||||
AnchorPane.setLeftAnchor(treatmentsPane, 0d);
|
|
||||||
AnchorPane.setRightAnchor(treatmentsPane, 0d);
|
|
||||||
} catch (IOException exception) {
|
|
||||||
exception.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads the {@link Nurse} page into its tab.
|
|
||||||
*/
|
|
||||||
private void loadNursePage() {
|
|
||||||
SelectionModel<Tab> selectionModel = nurseTabPane.getSelectionModel();
|
|
||||||
Tab selectedTab = selectionModel.getSelectedItem();
|
|
||||||
if (selectedTab == activeNurseTab) {
|
|
||||||
loadActiveNursePage();
|
|
||||||
}
|
|
||||||
if (selectedTab == lockedNurseTab) {
|
|
||||||
loadLockedNursePage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads the active {@link Nurse} page into its tab.
|
|
||||||
*/
|
|
||||||
private void loadActiveNursePage() {
|
|
||||||
try {
|
|
||||||
BorderPane activeNursePane = FXMLLoader.load(
|
|
||||||
Objects.requireNonNull(Main.class.getResource("/de/hitec/nhplus/nurse/AllNurseView.fxml"))
|
|
||||||
);
|
|
||||||
activeNursePage.getChildren().setAll(activeNursePane);
|
|
||||||
AnchorPane.setTopAnchor(activeNursePane, 0d);
|
|
||||||
AnchorPane.setBottomAnchor(activeNursePane, 0d);
|
|
||||||
AnchorPane.setLeftAnchor(activeNursePane, 0d);
|
|
||||||
AnchorPane.setRightAnchor(activeNursePane, 0d);
|
|
||||||
} catch (IOException exception) {
|
|
||||||
exception.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads the locked {@link Nurse} page into its tab.
|
|
||||||
*/
|
|
||||||
private void loadLockedNursePage() {
|
|
||||||
try {
|
|
||||||
BorderPane lockedNursePane = FXMLLoader.load(
|
|
||||||
Objects.requireNonNull(Main.class.getResource("/de/hitec/nhplus/nurse/LockedNurseView.fxml"))
|
|
||||||
);
|
|
||||||
lockedNursePage.getChildren().setAll(lockedNursePane);
|
|
||||||
AnchorPane.setTopAnchor(lockedNursePane, 0d);
|
|
||||||
AnchorPane.setBottomAnchor(lockedNursePane, 0d);
|
|
||||||
AnchorPane.setLeftAnchor(lockedNursePane, 0d);
|
|
||||||
AnchorPane.setRightAnchor(lockedNursePane, 0d);
|
|
||||||
} catch (IOException exception) {
|
|
||||||
exception.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads the {@link Medication} page into its tab.
|
|
||||||
*/
|
|
||||||
private void loadMedicationPage() {
|
|
||||||
try {
|
|
||||||
BorderPane medicationPane = FXMLLoader.load(
|
|
||||||
Objects.requireNonNull(Main.class.getResource("/de/hitec/nhplus/medication/AllMedicationView.fxml"))
|
|
||||||
);
|
|
||||||
medicationPage.getChildren().setAll(medicationPane);
|
|
||||||
AnchorPane.setTopAnchor(medicationPane, 0d);
|
|
||||||
AnchorPane.setBottomAnchor(medicationPane, 0d);
|
|
||||||
AnchorPane.setLeftAnchor(medicationPane, 0d);
|
|
||||||
AnchorPane.setRightAnchor(medicationPane, 0d);
|
|
||||||
} catch (IOException exception) {
|
|
||||||
exception.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
82
src/main/java/de/hitec/nhplus/utils/tab/TabManager.java
Normal file
82
src/main/java/de/hitec/nhplus/utils/tab/TabManager.java
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
package de.hitec.nhplus.utils.tab;
|
||||||
|
|
||||||
|
import de.hitec.nhplus.Main;
|
||||||
|
import de.hitec.nhplus.login.Permissions;
|
||||||
|
import de.hitec.nhplus.login.User;
|
||||||
|
import javafx.event.Event;
|
||||||
|
import javafx.event.EventHandler;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.scene.control.Tab;
|
||||||
|
import javafx.scene.control.TabPane;
|
||||||
|
import javafx.scene.layout.AnchorPane;
|
||||||
|
import javafx.scene.layout.BorderPane;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class TabManager {
|
||||||
|
private final User user;
|
||||||
|
|
||||||
|
public TabManager(User user) {
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasPermissions(int requiredPermissions, int permissions) {
|
||||||
|
return requiredPermissions == Permissions.EVERYBODY
|
||||||
|
|| (permissions & requiredPermissions) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setupTab(TabPane tabPane, TabStruct tabStruct) {
|
||||||
|
if (!hasPermissions(tabStruct.requiredPermissions, user.getPermissions())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Tab tab = new Tab();
|
||||||
|
tab.setText(tabStruct.title);
|
||||||
|
AnchorPane pane = new AnchorPane();
|
||||||
|
tab.setContent(pane);
|
||||||
|
tab.setOnSelectionChanged(loadTabEventHandler(tabStruct, pane));
|
||||||
|
tabPane.getTabs().add(tab);
|
||||||
|
}
|
||||||
|
|
||||||
|
private EventHandler<Event> loadTabEventHandler(TabStruct tabStruct, AnchorPane pane) {
|
||||||
|
return event -> {
|
||||||
|
try {
|
||||||
|
BorderPane patientsPane = FXMLLoader.load(
|
||||||
|
Objects.requireNonNull(Main.class.getResource(tabStruct.view))
|
||||||
|
);
|
||||||
|
pane.getChildren().setAll(patientsPane);
|
||||||
|
AnchorPane.setTopAnchor(patientsPane, 0d);
|
||||||
|
AnchorPane.setBottomAnchor(patientsPane, 0d);
|
||||||
|
AnchorPane.setLeftAnchor(patientsPane, 0d);
|
||||||
|
AnchorPane.setRightAnchor(patientsPane, 0d);
|
||||||
|
} catch (IOException exception) {
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setupSubTabPane(TabPane parentTabPane, String title, int requiredPermissions, List<TabStruct> subTabs) {
|
||||||
|
if (!hasPermissions(requiredPermissions, user.getPermissions())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Tab tab = new Tab();
|
||||||
|
tab.setText(title);
|
||||||
|
TabPane subTabPane = new TabPane();
|
||||||
|
subTabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE);
|
||||||
|
tab.setContent(subTabPane);
|
||||||
|
subTabs.forEach(tabStruct -> setupTab(subTabPane, tabStruct));
|
||||||
|
if (subTabPane.getTabs().isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
tab.setOnSelectionChanged(loadSubTabPaneEventHandler(subTabPane));
|
||||||
|
parentTabPane.getTabs().add(tab);
|
||||||
|
}
|
||||||
|
|
||||||
|
private EventHandler<Event> loadSubTabPaneEventHandler(TabPane tabPane) {
|
||||||
|
return event -> {
|
||||||
|
Tab tab = tabPane.getSelectionModel().getSelectedItem();
|
||||||
|
tab.getOnSelectionChanged().handle(new Event(Event.ANY));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
13
src/main/java/de/hitec/nhplus/utils/tab/TabStruct.java
Normal file
13
src/main/java/de/hitec/nhplus/utils/tab/TabStruct.java
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
package de.hitec.nhplus.utils.tab;
|
||||||
|
|
||||||
|
public class TabStruct {
|
||||||
|
public String title;
|
||||||
|
public String view;
|
||||||
|
public int requiredPermissions;
|
||||||
|
|
||||||
|
public TabStruct(String title, String view, int requiredPermissions) {
|
||||||
|
this.title = title;
|
||||||
|
this.view = view;
|
||||||
|
this.requiredPermissions = requiredPermissions;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,38 +1,10 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<?import javafx.scene.control.*?>
|
<?import javafx.scene.control.*?>
|
||||||
<?import javafx.scene.layout.AnchorPane?>
|
|
||||||
<TabPane
|
<TabPane
|
||||||
fx:id="mainTabPane"
|
fx:id="mainTabPane"
|
||||||
tabClosingPolicy="UNAVAILABLE"
|
tabClosingPolicy="UNAVAILABLE"
|
||||||
xmlns="http://javafx.com/javafx/17.0.2-ea"
|
xmlns="http://javafx.com/javafx/17.0.2-ea"
|
||||||
xmlns:fx="http://javafx.com/fxml/1"
|
xmlns:fx="http://javafx.com/fxml/1"
|
||||||
fx:controller="de.hitec.nhplus.main.MainWindowController"
|
fx:controller="de.hitec.nhplus.main.MainWindowController"
|
||||||
>
|
/>
|
||||||
<Tab fx:id="patientTab" text="Patienten">
|
|
||||||
<AnchorPane fx:id="patientPage"/>
|
|
||||||
</Tab>
|
|
||||||
<Tab fx:id="treatmentTab" text="Behandlungen">
|
|
||||||
<TabPane fx:id="treatmentTabPane" tabClosingPolicy="UNAVAILABLE">
|
|
||||||
<Tab fx:id="activeTreatmentTab" text="Behandlungen">
|
|
||||||
<AnchorPane fx:id="activeTreatmentPage"/>
|
|
||||||
</Tab>
|
|
||||||
<Tab fx:id="lockedTreatmentTab" text="Gesperrte Behandlungen">
|
|
||||||
<AnchorPane fx:id="lockedTreatmentPage" />
|
|
||||||
</Tab>
|
|
||||||
</TabPane>
|
|
||||||
</Tab>
|
|
||||||
<Tab fx:id="nurseTab" text="Pfleger">
|
|
||||||
<TabPane fx:id="nurseTabPane" tabClosingPolicy="UNAVAILABLE">
|
|
||||||
<Tab fx:id="activeNurseTab" text="Pfleger">
|
|
||||||
<AnchorPane fx:id="activeNursePage"/>
|
|
||||||
</Tab>
|
|
||||||
<Tab fx:id="lockedNurseTab" text="Gesperrte Pfleger">
|
|
||||||
<AnchorPane fx:id="lockedNursePage"/>
|
|
||||||
</Tab>
|
|
||||||
</TabPane>
|
|
||||||
</Tab>
|
|
||||||
<Tab fx:id="medicationTab" text="Medikamente">
|
|
||||||
<AnchorPane fx:id="medicationPage"/>
|
|
||||||
</Tab>
|
|
||||||
</TabPane>
|
|
Loading…
Reference in a new issue