Search in sources :

Example 1 with ClearingTextField

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;
}
Also used : Pos(javafx.geometry.Pos) HashMap(java.util.HashMap) VBox(javafx.scene.layout.VBox) ArrayList(java.util.ArrayList) Insets(javafx.geometry.Insets) ScrollPane(javafx.scene.control.ScrollPane) DisplayEditor(org.csstudio.display.builder.editor.DisplayEditor) Map(java.util.Map) ClearingTextField(org.csstudio.javafx.ClearingTextField) Tooltip(javafx.scene.control.Tooltip) WidgetDescriptor(org.csstudio.display.builder.model.WidgetDescriptor) Pane(javafx.scene.layout.Pane) HBox(javafx.scene.layout.HBox) TextField(javafx.scene.control.TextField) TitledPane(javafx.scene.control.TitledPane) Collection(java.util.Collection) Node(javafx.scene.Node) Set(java.util.Set) Messages(org.csstudio.display.builder.editor.Messages) Collectors(java.util.stream.Collectors) Priority(javafx.scene.layout.Priority) List(java.util.List) ToggleButton(javafx.scene.control.ToggleButton) WidgetFactory(org.csstudio.display.builder.model.WidgetFactory) ScrollBarPolicy(javafx.scene.control.ScrollPane.ScrollBarPolicy) TilePane(javafx.scene.layout.TilePane) ImageView(javafx.scene.image.ImageView) WidgetCategory(org.csstudio.display.builder.model.WidgetCategory) BorderPane(javafx.scene.layout.BorderPane) WidgetTransfer(org.csstudio.display.builder.editor.util.WidgetTransfer) Preferences(org.csstudio.display.builder.editor.Preferences) WidgetIcons(org.csstudio.display.builder.editor.util.WidgetIcons) Image(javafx.scene.image.Image) ToggleButton(javafx.scene.control.ToggleButton) HBox(javafx.scene.layout.HBox) BorderPane(javafx.scene.layout.BorderPane) Insets(javafx.geometry.Insets) Tooltip(javafx.scene.control.Tooltip) Node(javafx.scene.Node) ArrayList(java.util.ArrayList) ClearingTextField(org.csstudio.javafx.ClearingTextField) ScrollPane(javafx.scene.control.ScrollPane) Pane(javafx.scene.layout.Pane) TitledPane(javafx.scene.control.TitledPane) TilePane(javafx.scene.layout.TilePane) BorderPane(javafx.scene.layout.BorderPane) ScrollPane(javafx.scene.control.ScrollPane) ClearingTextField(org.csstudio.javafx.ClearingTextField) TextField(javafx.scene.control.TextField) ArrayList(java.util.ArrayList) List(java.util.List) WidgetCategory(org.csstudio.display.builder.model.WidgetCategory) VBox(javafx.scene.layout.VBox)

Aggregations

ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Insets (javafx.geometry.Insets)1 Pos (javafx.geometry.Pos)1 Node (javafx.scene.Node)1 ScrollPane (javafx.scene.control.ScrollPane)1 ScrollBarPolicy (javafx.scene.control.ScrollPane.ScrollBarPolicy)1 TextField (javafx.scene.control.TextField)1 TitledPane (javafx.scene.control.TitledPane)1 ToggleButton (javafx.scene.control.ToggleButton)1 Tooltip (javafx.scene.control.Tooltip)1 Image (javafx.scene.image.Image)1 ImageView (javafx.scene.image.ImageView)1 BorderPane (javafx.scene.layout.BorderPane)1 HBox (javafx.scene.layout.HBox)1