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) {