mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-12-16 08:14:15 -05:00
fix tables by auto adjusting first and last column classes
This commit is contained in:
parent
2f3c7098de
commit
f0162c05bc
1 changed files with 50 additions and 11 deletions
|
|
@ -69,6 +69,7 @@ import javafx.beans.binding.Bindings;
|
||||||
import javafx.beans.value.ChangeListener;
|
import javafx.beans.value.ChangeListener;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.collections.ListChangeListener;
|
import javafx.collections.ListChangeListener;
|
||||||
|
import javafx.collections.ObservableList;
|
||||||
import javafx.geometry.HPos;
|
import javafx.geometry.HPos;
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
import javafx.geometry.Orientation;
|
import javafx.geometry.Orientation;
|
||||||
|
|
@ -1134,13 +1135,15 @@ public class GUIUtil {
|
||||||
|
|
||||||
private static <T> void applyEdgeColumnStyleClasses(TableView<T> tableView) {
|
private static <T> void applyEdgeColumnStyleClasses(TableView<T> tableView) {
|
||||||
ListChangeListener<TableColumn<T, ?>> columnListener = change -> {
|
ListChangeListener<TableColumn<T, ?>> columnListener = change -> {
|
||||||
updateEdgeColumnStyleClasses(tableView);
|
UserThread.execute(() -> {
|
||||||
|
updateEdgeColumnStyleClasses(tableView);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
tableView.getColumns().addListener(columnListener);
|
tableView.getColumns().addListener(columnListener);
|
||||||
tableView.skinProperty().addListener((obs, oldSkin, newSkin) -> {
|
tableView.skinProperty().addListener((obs, oldSkin, newSkin) -> {
|
||||||
if (newSkin != null) {
|
if (newSkin != null) {
|
||||||
Platform.runLater(() -> {
|
UserThread.execute(() -> {
|
||||||
updateEdgeColumnStyleClasses(tableView);
|
updateEdgeColumnStyleClasses(tableView);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -1155,21 +1158,57 @@ public class GUIUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T> void updateEdgeColumnStyleClasses(TableView<T> tableView) {
|
private static <T> void updateEdgeColumnStyleClasses(TableView<T> tableView) {
|
||||||
var columns = tableView.getColumns();
|
ObservableList<TableColumn<T, ?>> columns = tableView.getColumns();
|
||||||
|
|
||||||
|
// find columns with "first-column" and "last-column" classes
|
||||||
|
TableColumn<T, ?> firstCol = null;
|
||||||
|
TableColumn<T, ?> lastCol = null;
|
||||||
for (TableColumn<T, ?> col : columns) {
|
for (TableColumn<T, ?> col : columns) {
|
||||||
col.getStyleClass().removeAll("first-column", "last-column");
|
if (col.getStyleClass().contains("first-column")) {
|
||||||
|
firstCol = col;
|
||||||
|
} else if (col.getStyleClass().contains("last-column")) {
|
||||||
|
lastCol = col;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!columns.isEmpty()) {
|
// handle if columns do not exist
|
||||||
TableColumn<T, ?> first = columns.get(0);
|
if (firstCol == null || lastCol == null) {
|
||||||
TableColumn<T, ?> last = columns.get(columns.size() - 1);
|
if (firstCol != null) throw new IllegalStateException("Missing column with 'last-column'");
|
||||||
|
if (lastCol != null) throw new IllegalStateException("Missing column with 'first-column'");
|
||||||
|
|
||||||
if (!first.getStyleClass().contains("first-column")) {
|
// remove all classes
|
||||||
first.getStyleClass().add("first-column");
|
for (TableColumn<T, ?> col : columns) {
|
||||||
|
col.getStyleClass().removeAll("first-column", "last-column");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!last.getStyleClass().contains("last-column")) {
|
// apply first and last classes
|
||||||
last.getStyleClass().add("last-column");
|
if (!columns.isEmpty()) {
|
||||||
|
TableColumn<T, ?> first = columns.get(0);
|
||||||
|
TableColumn<T, ?> last = columns.get(columns.size() - 1);
|
||||||
|
|
||||||
|
if (!first.getStyleClass().contains("first-column")) {
|
||||||
|
first.getStyleClass().add("first-column");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!last.getStyleClass().contains("last-column")) {
|
||||||
|
last.getStyleClass().add("last-column");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// done if correct order
|
||||||
|
if (columns.get(0) == firstCol && columns.get(columns.size() - 1) == lastCol) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set first and last columns
|
||||||
|
if (columns.get(0) != firstCol) {
|
||||||
|
columns.remove(firstCol);
|
||||||
|
columns.add(0, firstCol);
|
||||||
|
}
|
||||||
|
if (columns.get(columns.size() - 1) != lastCol) {
|
||||||
|
columns.remove(lastCol);
|
||||||
|
columns.add(firstCol == lastCol ? columns.size() - 1 : columns.size(), lastCol);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue