I created a table with 3 columns. In middle column i have 3 checkboxes. When my window is initialize checkboxes are ticked if info from database is suitable. It works. User can unticked checkbox what changing informations in database. My problem is when I verify did checkbox are selected one time returns true, one time returns false but the checkboxes is in the same state (selected or not).
public CheckBox podglad2, edycja2, dodawanie2, usuwanie2, importowanie2, eksportowanie2, nadawanie2;
private static void setAccessLabelStyle2(CheckBox label, AccessLevel level, Integer value) {
if (check(level, value)) {
label.setSelected(true);
} else {
label.setSelected(false);
}
}
private static boolean check(AccessLevel accessLevel, Integer value) {
return (accessLevel.getBit() & value) > 0;
}
public TableCell getFunctionCell2(TableCell cell, Integer accessLevel) {
HBox graphics = new HBox();
graphics.setAlignment(Pos.CENTER_LEFT);
graphics.setSpacing(7.0);
podglad2 = new CheckBox("P");
setAccessLabelStyle2(podglad2, AccessLevel.VIEW, accessLevel);
dodawanie2 = new CheckBox("D");
setAccessLabelStyle2(dodawanie2, AccessLevel.CREATE, accessLevel);
edycja2 = new CheckBox("E");
setAccessLabelStyle2(edycja2, AccessLevel.UPDATE, accessLevel);
}
accessLevelCol.setCellFactory(param -> {
return new TableCell<FunctionTableModel, Integer>() {
@Override
protected void updateItem(Integer item, boolean empty) {
super.updateItem(item, empty);
if (item == null || empty) {
setText(null);
setStyle("");
} else {
getFunctionCell2(this, item);
podglad2.setOnAction(e -> {
FunctionTableModel row = getTableView().getItems().get(getIndex());
if (check(AccessLevel.VIEW, row.getAccessLevel())) {
if (podglad2.isSelected() == false) {
row.setAccessLevel(row.getAccessLevel() - AccessLevel.VIEW.getBit());
}
} else {
if (podglad2.isSelected() == true) {
row.setAccessLevel(row.getAccessLevel() + AccessLevel.VIEW.getBit());
}
}
});
dodawanie2.setOnAction(e -> {
FunctionTableModel row = getTableView().getItems().get(getIndex());
if (check(AccessLevel.CREATE, row.getAccessLevel())) {
if (dodawanie2.isSelected() == false) {
row.setAccessLevel(row.getAccessLevel() - AccessLevel.CREATE.getBit());
}
} else {
if (dodawanie2.isSelected() == true) {
row.setAccessLevel(row.getAccessLevel() + AccessLevel.CREATE.getBit());
}
}
});
edycja2.setOnAction(e -> {
FunctionTableModel row = getTableView().getItems().get(getIndex());
if (check(AccessLevel.UPDATE, row.getAccessLevel())) {
if (edycja2.isSelected() == false) {
row.setAccessLevel(row.getAccessLevel() - AccessLevel.UPDATE.getBit());
}
} else {
if (edycja2.isSelected() == true) {
row.setAccessLevel(row.getAccessLevel() + AccessLevel.UPDATE.getBit());
}
}
});
}
How can I solved this?
Aucun commentaire:
Enregistrer un commentaire