From b8d31f82ce2fed218acd760e41c35c202ec6e57e Mon Sep 17 00:00:00 2001 From: Frank Delporte Date: Tue, 7 May 2024 09:15:43 +0200 Subject: [PATCH] #5 add direct links to each board in the listbox --- .../boardinfoservice/views/BaseLayout.java | 10 +++++-- .../boardinfoservice/views/BoardInfoView.java | 29 ++++++++++++++----- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/pi4j/boardinfoservice/views/BaseLayout.java b/src/main/java/com/pi4j/boardinfoservice/views/BaseLayout.java index eda9d9d..e534171 100644 --- a/src/main/java/com/pi4j/boardinfoservice/views/BaseLayout.java +++ b/src/main/java/com/pi4j/boardinfoservice/views/BaseLayout.java @@ -105,13 +105,19 @@ public MenuItemComponent(String menuTitle, Component icon, Class { private static final Logger logger = LogManager.getLogger(BoardInfoView.class); private final VerticalLayout holder = new VerticalLayout(); private final ListBox listBox = new ListBox<>(); + private BoardModel selectedBoard; public BoardInfoView() { setSpacing(false); @@ -41,11 +41,11 @@ public BoardInfoView() { setJustifyContentMode(JustifyContentMode.START); listBox.addValueChangeListener(e -> showBoard(e.getValue())); - listBox.setMinWidth(250, Unit.PIXELS); + listBox.setMinWidth(300, Unit.PIXELS); listBox.setHeightFull(); listBox.setRenderer(new ComponentRenderer<>(board -> { - var lbl = new Span(board.getLabel()); - lbl.setWidthFull(); + var lbl = new Anchor("/board-information/" + board.getName(), board.getLabel()); + lbl.addClassNames(LumoUtility.Gap.XSMALL, LumoUtility.TextColor.BODY); return lbl; })); @@ -60,13 +60,26 @@ public BoardInfoView() { add(split); } + @Override + public void setParameter(BeforeEvent event, @OptionalParameter String parameter) { + selectedBoard = Arrays.stream(BoardModel.values()) + .filter(bm -> bm.name().equalsIgnoreCase(parameter == null ? "" : parameter)) + .findFirst() + .orElse(BoardModel.UNKNOWN); + } + @Override public void onAttach(AttachEvent event) { var listWithoutUnknown = Arrays.stream(BoardModel.values()) .filter(bm -> bm != BoardModel.UNKNOWN) .sorted(Comparator.comparing(BoardModel::getLabel)) .toList(); - UI.getCurrent().access(() -> listBox.setItems(listWithoutUnknown)); + UI.getCurrent().access(() -> { + listBox.setItems(listWithoutUnknown); + if (selectedBoard != BoardModel.UNKNOWN) { + listBox.setValue(selectedBoard); + } + }); } private void showBoard(BoardModel boardModel) {