package lan.zold; import java.io.IOException; import java.net.URL; import java.util.ResourceBundle; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.control.Alert; import javafx.scene.control.CheckBox; import javafx.scene.control.PasswordField; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.control.TextField; import javafx.scene.control.cell.PropertyValueFactory; public class UserController implements Initializable { @FXML private TextField username; @FXML private PasswordField password; @FXML private CheckBox admin; @FXML private CheckBox enabled; @FXML private TableView usertable; @FXML private TableColumn idcol; @FXML private TableColumn usernamecol; @FXML private TableColumn passwordcol; @FXML private TableColumn admincol; @FXML private TableColumn enabledcol; @Override public void initialize( URL url, ResourceBundle rb ) { this.idcol.setCellValueFactory(new PropertyValueFactory<>("id")); this.usernamecol.setCellValueFactory(new PropertyValueFactory<>("username")); this.passwordcol.setCellValueFactory(new PropertyValueFactory<>("password")); this.admincol.setCellValueFactory(new PropertyValueFactory<>("admin")); this.enabledcol.setCellValueFactory(new PropertyValueFactory<>("enabled")); } @FXML private void addUser() { if(this.username.getText().isEmpty() || this.password.getText().isEmpty()) { Alert alert = new Alert(Alert.AlertType.ERROR); alert.setTitle("Hiba!"); alert.setHeaderText("Hiba!"); alert.setContentText("A felhasználónév vagy a jelszó üres!"); alert.showAndWait(); return; } System.out.println("Add user"); String username = this.username.getText(); String password = this.password.getText(); boolean admin = this.admin.isSelected(); boolean enabled = this.enabled.isSelected(); System.out.println("User added: " + username + " " + password + " " + admin + " " + enabled); Employee employee = new Employee(); employee.id = 0; employee.username = username; employee.password = password; employee.admin = admin; employee.enabled = enabled; usertable.getItems().add(employee); this.username.clear(); this.password.clear(); this.admin.setSelected(false); this.enabled.setSelected(false); } @FXML private void deleteUser() { if(usertable.getSelectionModel().getSelectedItem() == null) { Alert alert = new Alert(Alert.AlertType.ERROR); alert.setTitle("Hiba!"); alert.setHeaderText("Hiba!"); alert.setContentText("Nincs kijelölt elem!"); alert.showAndWait(); return; } System.out.println("Delete user"); usertable.getItems().remove(usertable.getSelectionModel().getSelectedItem()); } @FXML private void updateUser() { if(usertable.getSelectionModel().getSelectedItem() == null) { Alert alert = new Alert(Alert.AlertType.ERROR); alert.setTitle("Hiba!"); alert.setHeaderText("Felhasználó módosítása"); alert.setContentText("Nincs kijelölt elem!"); alert.showAndWait(); return; } System.out.println("Update user"); Employee employee = usertable.getSelectionModel().getSelectedItem(); employee.username = this.username.getText(); employee.password = this.password.getText(); employee.admin = this.admin.isSelected(); employee.enabled = this.enabled.isSelected(); usertable.refresh(); } @FXML private void closeUserStage() throws IOException { App.setRoot("main"); } }