Skip to content

Commit f2ef784

Browse files
committed
feat: add setters for features configured in constructor
Close #79
1 parent 3e6b8d3 commit f2ef784

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/main/java/com/flowingcode/addons/applayout/AppLayout.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
@CssImport(value = "./styles/applayout-styles.css", themeFor = "fc-applayout")
4545
public class AppLayout extends Div implements PageConfigurator {
4646

47+
private static final String PROFILE_SLOT_NAME = "profile";
48+
private static final String APP_LAYOUT_TITLE_SLOT_NAME = "title";
49+
private static final String TITLE_ATTRIBUTE_NAME = "title";
4750
private final List<Component> menuItems = new ArrayList<>();
4851
private final List<Component> toolbarComponents = new ArrayList<>();
4952

@@ -61,17 +64,29 @@ public AppLayout(Image logo, Component menuHeader, String title) {
6164

6265
private AppLayout(Component menuHeader, String aTitle, Image aLogo) {
6366
if (aLogo != null) {
64-
aLogo.getElement().setAttribute("slot", "title");
65-
add(aLogo);
67+
addToTitleSection(aLogo);
6668
}
6769
if (menuHeader != null) {
68-
menuHeader.getElement().setAttribute("slot", "profile");
69-
add(menuHeader);
70+
setMenuHeader(menuHeader);
7071
}
7172
Div title = new Div();
7273
title.setText(aTitle);
73-
title.getElement().setAttribute("slot", "title");
74-
add(title);
74+
addToTitleSection(title);
75+
}
76+
77+
public void addToTitleSection(Component component) {
78+
component.getElement().setAttribute("slot", APP_LAYOUT_TITLE_SLOT_NAME);
79+
add(component);
80+
}
81+
82+
/**
83+
* Sets the component to be shown before the menu in the drawer.
84+
* @param menuHeader
85+
*/
86+
public void setMenuHeader(Component menuHeader) {
87+
getChildren().filter(item->PROFILE_SLOT_NAME.equals(item.getElement().getAttribute("slot"))).forEach(this::remove);
88+
menuHeader.getElement().setAttribute("slot", PROFILE_SLOT_NAME);
89+
add(menuHeader);
7590
}
7691

7792
public void setMenuItems(Component... someMenuitems) {
@@ -122,7 +137,7 @@ public boolean isMenuVisible() {
122137

123138
/** Set the toolbar title */
124139
public void setCaption(String caption) {
125-
this.getElement().setAttribute("title", caption);
140+
this.getElement().setAttribute(TITLE_ATTRIBUTE_NAME, caption);
126141
}
127142

128143
@Override

0 commit comments

Comments
 (0)