use of org.csstudio.javafx.ClearingTextField in project org.csstudio.display.builder by kasemir.
the class Palette method create.
/**
* Create UI elements
* @return Top-level Node of the UI
*/
@SuppressWarnings("unchecked")
public Node create() {
final VBox palette = new VBox();
final Map<WidgetCategory, Pane> palette_groups = createWidgetCategoryPanes(palette);
groups = palette_groups.values();
createWidgetEntries(palette_groups);
final ScrollPane palette_scroll = new ScrollPane(palette);
palette_scroll.setHbarPolicy(ScrollBarPolicy.NEVER);
palette_scroll.setFitToWidth(true);
// TODO Determine the correct size for the main node
// Using 2*PREFERRED_WIDTH was determined by trial and error
palette_scroll.setMinWidth(PREFERRED_WIDTH + 12);
palette_scroll.setPrefWidth(PREFERRED_WIDTH);
// Copy the widgets, i.e. the children of each palette_group,
// to the userData.
// Actual children are now updated based on search by widget name
palette_groups.values().forEach(group -> group.setUserData(new ArrayList<Node>(group.getChildren())));
final TextField searchField = new ClearingTextField();
searchField.setPromptText(Messages.SearchTextField);
searchField.setTooltip(new Tooltip(Messages.WidgetFilterTT));
searchField.setPrefColumnCount(9);
searchField.textProperty().addListener((observable, oldValue, search_text) -> {
final String search = search_text.toLowerCase().trim();
palette_groups.values().stream().forEach(group -> {
group.getChildren().clear();
final List<Node> all_widgets = (List<Node>) group.getUserData();
if (search.isEmpty())
group.getChildren().setAll(all_widgets);
else
group.getChildren().setAll(all_widgets.stream().filter(node -> {
final String text = ((ToggleButton) node).getText().toLowerCase();
return text.contains(search);
}).collect(Collectors.toList()));
});
});
HBox.setHgrow(searchField, Priority.NEVER);
final HBox toolsPane = new HBox(6);
toolsPane.setAlignment(Pos.CENTER_RIGHT);
toolsPane.setPadding(new Insets(6));
toolsPane.getChildren().add(searchField);
BorderPane paletteContainer = new BorderPane();
paletteContainer.setTop(toolsPane);
paletteContainer.setCenter(palette_scroll);
return paletteContainer;
}
Aggregations