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;
}
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);
});
}
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;
}
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;
}
Aggregations