Skip to content

Commit

Permalink
feat: add setters for features configured in constructor
Browse files Browse the repository at this point in the history
Close #79
  • Loading branch information
mlopezFC committed Aug 18, 2021
1 parent 3e6b8d3 commit f2ef784
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/main/java/com/flowingcode/addons/applayout/AppLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
@CssImport(value = "./styles/applayout-styles.css", themeFor = "fc-applayout")
public class AppLayout extends Div implements PageConfigurator {

private static final String PROFILE_SLOT_NAME = "profile";
private static final String APP_LAYOUT_TITLE_SLOT_NAME = "title";
private static final String TITLE_ATTRIBUTE_NAME = "title";
private final List<Component> menuItems = new ArrayList<>();
private final List<Component> toolbarComponents = new ArrayList<>();

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

private AppLayout(Component menuHeader, String aTitle, Image aLogo) {
if (aLogo != null) {
aLogo.getElement().setAttribute("slot", "title");
add(aLogo);
addToTitleSection(aLogo);
}
if (menuHeader != null) {
menuHeader.getElement().setAttribute("slot", "profile");
add(menuHeader);
setMenuHeader(menuHeader);
}
Div title = new Div();
title.setText(aTitle);
title.getElement().setAttribute("slot", "title");
add(title);
addToTitleSection(title);
}

public void addToTitleSection(Component component) {
component.getElement().setAttribute("slot", APP_LAYOUT_TITLE_SLOT_NAME);
add(component);
}

/**
* Sets the component to be shown before the menu in the drawer.
* @param menuHeader
*/
public void setMenuHeader(Component menuHeader) {
getChildren().filter(item->PROFILE_SLOT_NAME.equals(item.getElement().getAttribute("slot"))).forEach(this::remove);
menuHeader.getElement().setAttribute("slot", PROFILE_SLOT_NAME);
add(menuHeader);
}

public void setMenuItems(Component... someMenuitems) {
Expand Down Expand Up @@ -122,7 +137,7 @@ public boolean isMenuVisible() {

/** Set the toolbar title */
public void setCaption(String caption) {
this.getElement().setAttribute("title", caption);
this.getElement().setAttribute(TITLE_ATTRIBUTE_NAME, caption);
}

@Override
Expand Down

0 comments on commit f2ef784

Please sign in to comment.