Skip to content

Commit

Permalink
Better links on board info
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Delporte committed May 7, 2024
1 parent 388fbf8 commit 9e5f54f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
34 changes: 16 additions & 18 deletions src/main/java/com/pi4j/boardinfoservice/views/BoardInfoView.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.Unit;
import com.vaadin.flow.component.html.*;
import com.vaadin.flow.component.listbox.ListBox;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.sidenav.SideNav;
import com.vaadin.flow.component.sidenav.SideNavItem;
import com.vaadin.flow.component.splitlayout.SplitLayout;
import com.vaadin.flow.data.renderer.ComponentRenderer;
import com.vaadin.flow.router.*;
import com.vaadin.flow.theme.lumo.LumoUtility;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand All @@ -31,7 +30,7 @@ public class BoardInfoView extends VerticalLayout implements HasUrlParameter<Str
private static final Logger logger = LogManager.getLogger(BoardInfoView.class);

private final VerticalLayout holder = new VerticalLayout();
private final ListBox<BoardModel> listBox = new ListBox<>();
private final SideNav items = new SideNav();
private BoardModel selectedBoard;

public BoardInfoView() {
Expand All @@ -45,20 +44,13 @@ public BoardInfoView() {
new Anchor("https://pi4j.com/documentation/board-info", "board info", AnchorTarget.BLANK),
new Span(" provided by the Pi4J library.")));

listBox.addValueChangeListener(e -> showBoard(e.getValue()));
listBox.setMinWidth(300, Unit.PIXELS);
listBox.setHeightFull();
listBox.setRenderer(new ComponentRenderer<>(board -> {
var lbl = new Anchor("/board-information/" + board.getName(), board.getLabel());
lbl.addClassNames(LumoUtility.Gap.XSMALL, LumoUtility.TextColor.BODY);
return lbl;
}));

holder.setPadding(true);
holder.setMargin(false);
holder.setSpacing(true);

var split = new SplitLayout(listBox, holder);
items.setMinWidth(250, Unit.PIXELS);

var split = new SplitLayout(items, holder);
split.setHeightFull();
split.setWidthFull();

Expand All @@ -71,6 +63,9 @@ public void setParameter(BeforeEvent event, @OptionalParameter String parameter)
.filter(bm -> bm.name().equalsIgnoreCase(parameter == null ? "" : parameter))
.findFirst()
.orElse(BoardModel.UNKNOWN);
UI.getCurrent().access(() -> {
showBoard(selectedBoard);
});
}

@Override
Expand All @@ -80,17 +75,20 @@ public void onAttach(AttachEvent event) {
.sorted(Comparator.comparing(BoardModel::getLabel))
.toList();
UI.getCurrent().access(() -> {
listBox.setItems(listWithoutUnknown);
if (selectedBoard != BoardModel.UNKNOWN) {
listBox.setValue(selectedBoard);
for (BoardModel boardModel : listWithoutUnknown) {
var item = new SideNavItem(boardModel.getLabel(), "/board-information/" + boardModel.getName());
items.addItem(item);
if (boardModel == selectedBoard) {
showBoard(boardModel);
}
}
});
}

private void showBoard(BoardModel boardModel) {
holder.removeAll();

if (boardModel == null) {
if (boardModel == null || boardModel == BoardModel.UNKNOWN) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ public SystemInfoView(@Autowired SystemInfoService systemInfoService) {
add(grid);

setSizeFull();
//setJustifyContentMode(JustifyContentMode.LEF);
//setDefaultHorizontalComponentAlignment(Alignment.CENTER);
getStyle().set("text-align", "center");
}

Expand Down

0 comments on commit 9e5f54f

Please sign in to comment.