Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
teletha committed Nov 29, 2023
1 parent 345c7d4 commit a9795d1
Showing 1 changed file with 48 additions and 7 deletions.
55 changes: 48 additions & 7 deletions src/main/java/viewtify/ui/view/PreferenceViewBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
*/
package viewtify.ui.view;

import java.util.HashSet;
import java.util.Set;

import javafx.collections.ObservableList;
import javafx.scene.Node;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.Labeled;
import kiss.Extensible;
import kiss.Variable;
Expand All @@ -35,15 +38,28 @@ void searchPreferenceBy(String text) {
boolean precondition = text == null || text.isBlank() || category().exact().contains(text);

int shown = 0;
Set<Node> nodes = ui().lookupAll(FormStyles.Row.selector());
for (Node row : nodes) {
if (precondition || searchLabel(row, text, ".label", ".button", ".check-box", ".hyperlink", " .toggle-button") || searchCombo(row, text)) {
Set<Node> shownDescriptions = new HashSet();

for (Node row : ui().lookupAll(FormStyles.Row.selector())) {
Variable<Node> description = findDescription(row);
if (precondition || searchLabel(row, text, ".label", ".button", ".check-box", ".hyperlink", " .toggle-button") || searchCombo(row, text) || searchDescription(description, text)) {
shown++;
row.setManaged(true);
row.setVisible(true);
shown++;
description.to(x -> {
x.setManaged(true);
x.setVisible(true);
shownDescriptions.add(x);
});
} else {
row.setManaged(false);
row.setVisible(false);
description.to(x -> {
if (!shownDescriptions.contains(x)) {
x.setManaged(false);
x.setVisible(false);
}
});
}
}

Expand All @@ -55,15 +71,15 @@ void searchPreferenceBy(String text) {
private boolean searchLabel(Node row, String text, String... classes) {
for (String clazz : classes) {
for (Node node : row.lookupAll(clazz)) {
if (node instanceof Labeled labeled) {
return labeled.getText().toLowerCase().contains(text);
if (node instanceof Labeled labeled && labeled.getText().toLowerCase().contains(text)) {
return true;
}
}
}
return false;
}

private boolean searchCombo(Node row, String text, String... classes) {
private boolean searchCombo(Node row, String text) {
for (Node node : row.lookupAll(".combo-box")) {
if (node instanceof ComboBox combo) {
for (Object object : combo.getItems()) {
Expand All @@ -75,4 +91,29 @@ private boolean searchCombo(Node row, String text, String... classes) {
}
return false;
}

private boolean searchDescription(Variable<Node> description, String text) {
if (description.isAbsent()) {
return false;
}

for (Node node : description.v.lookupAll(".label")) {
if (node instanceof Label label && label.getText().toLowerCase().contains(text)) {
return true;
}
}
return false;
}

private Variable<Node> findDescription(Node row) {
ObservableList<Node> children = row.getParent().getChildrenUnmodifiable();
for (int i = children.indexOf(row) - 1; 0 <= i; i--) {
Node child = children.get(i);
ObservableList<String> classes = child.getStyleClass();
if (classes.contains(FormStyles.Description.className()[0])) {
return Variable.of(child);
}
}
return Variable.empty();
}
}

0 comments on commit a9795d1

Please sign in to comment.