Search in sources :

Example 1 with WidgetCategory

use of org.csstudio.display.builder.model.WidgetCategory in project org.csstudio.display.builder by kasemir.

the class Palette method createWidgetCategoryPanes.

/**
 * Create a TilePane for each WidgetCategory
 *  @param parent Parent Pane
 *  @return Map of panes for each category
 */
private Map<WidgetCategory, Pane> createWidgetCategoryPanes(final Pane parent) {
    final Map<WidgetCategory, Pane> palette_groups = new HashMap<>();
    for (final WidgetCategory category : WidgetCategory.values()) {
        final TilePane palette_group = new TilePane();
        palette_group.getStyleClass().add("palette_group");
        palette_group.setPrefColumns(1);
        palette_group.setMaxWidth(Double.MAX_VALUE);
        palette_groups.put(category, palette_group);
        palette_group.setHgap(2);
        palette_group.setVgap(2);
        final TitledPane pane = new TitledPane(category.getDescription(), palette_group);
        pane.getStyleClass().add("palette_category");
        parent.getChildren().add(pane);
    }
    return palette_groups;
}
Also used : TitledPane(javafx.scene.control.TitledPane) HashMap(java.util.HashMap) TilePane(javafx.scene.layout.TilePane) WidgetCategory(org.csstudio.display.builder.model.WidgetCategory) 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)

Example 2 with WidgetCategory

use of org.csstudio.display.builder.model.WidgetCategory in project org.csstudio.display.builder by kasemir.

the class Palette method createWidgetEntries.

/**
 * Create entry for each widget type
 * @param palette_groups Map with parent panes for each widget category
 */
private void createWidgetEntries(final Map<WidgetCategory, Pane> palette_groups) {
    final Set<String> deprecated = Preferences.getHiddenWidgets();
    // Sort alphabetically-case-insensitive widgets inside their group
    // based on the widget's name, instead of the original set order or class name.
    WidgetFactory.getInstance().getWidgetDescriptions().stream().filter(desc -> !deprecated.contains(desc.getType())).sorted((d1, d2) -> String.CASE_INSENSITIVE_ORDER.compare(d1.getName(), d2.getName())).forEach(desc -> {
        final ToggleButton button = new ToggleButton(desc.getName());
        final Image icon = WidgetIcons.getIcon(desc.getType());
        if (icon != null)
            button.setGraphic(new ImageView(icon));
        button.setPrefWidth(PREFERRED_WIDTH);
        button.setAlignment(Pos.BASELINE_LEFT);
        button.setTooltip(new Tooltip(desc.getDescription()));
        button.setOnAction(event -> {
            // Remember the widget-to-create via rubberband
            active_widget_type = desc;
            // De-select all _other_ buttons
            deselectButtons(button);
        });
        palette_groups.get(desc.getCategory()).getChildren().add(button);
        WidgetTransfer.addDragSupport(button, editor, this, desc, icon);
    });
}
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) Tooltip(javafx.scene.control.Tooltip) ImageView(javafx.scene.image.ImageView) Image(javafx.scene.image.Image)

Example 3 with WidgetCategory

use of org.csstudio.display.builder.model.WidgetCategory 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)

Example 4 with WidgetCategory

use of org.csstudio.display.builder.model.WidgetCategory in project org.csstudio.display.builder by kasemir.

the class MorphWidgetMenuSupport method createMenuManager.

private MenuManager createMenuManager() {
    final MenuManager mm = new MenuManager(Messages.ReplaceWith);
    mm.setRemoveAllWhenShown(true);
    mm.addMenuListener((manager) -> {
        if (editor.getWidgetSelectionHandler().getSelection().isEmpty())
            manager.add(new Action(Messages.ReplaceWith_NoWidgets) {
            });
        else {
            // Create menu that lists all widget types
            WidgetCategory category = null;
            for (WidgetDescriptor descr : WidgetFactory.getInstance().getWidgetDescriptions()) {
                if (Preferences.getHiddenWidgets().contains(descr.getType()))
                    continue;
                // Header for start of each category
                if (descr.getCategory() != category) {
                    category = descr.getCategory();
                    // Use disabled, empty action to show category name
                    final Action info = new Action(category.getDescription()) {
                    };
                    info.setEnabled(false);
                    manager.add(new Separator());
                    manager.add(info);
                }
                manager.add(new MorphAction(descr));
            }
        }
    });
    mm.setImageDescriptor(Plugin.getIcon("replace.png"));
    return mm;
}
Also used : AddWidgetAction(org.csstudio.display.builder.editor.undo.AddWidgetAction) CompoundUndoableAction(org.csstudio.display.builder.util.undo.CompoundUndoableAction) RemoveWidgetsAction(org.csstudio.display.builder.editor.undo.RemoveWidgetsAction) Action(org.eclipse.jface.action.Action) MenuManager(org.eclipse.jface.action.MenuManager) WidgetDescriptor(org.csstudio.display.builder.model.WidgetDescriptor) WidgetCategory(org.csstudio.display.builder.model.WidgetCategory) Separator(org.eclipse.jface.action.Separator)

Aggregations

WidgetCategory (org.csstudio.display.builder.model.WidgetCategory)4 HashMap (java.util.HashMap)3 ScrollPane (javafx.scene.control.ScrollPane)3 TitledPane (javafx.scene.control.TitledPane)3 BorderPane (javafx.scene.layout.BorderPane)3 Pane (javafx.scene.layout.Pane)3 TilePane (javafx.scene.layout.TilePane)3 WidgetDescriptor (org.csstudio.display.builder.model.WidgetDescriptor)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Insets (javafx.geometry.Insets)2 Pos (javafx.geometry.Pos)2 Node (javafx.scene.Node)2 ScrollBarPolicy (javafx.scene.control.ScrollPane.ScrollBarPolicy)2 TextField (javafx.scene.control.TextField)2 ToggleButton (javafx.scene.control.ToggleButton)2