4242@ CssImport (value = "./styles/applayout-styles.css" , themeFor = "fc-applayout" )
4343public class AppLayout extends Div {
4444
45+ private static final String PROFILE_SLOT_NAME = "profile" ;
46+ private static final String APP_LAYOUT_TITLE_SLOT_NAME = "title" ;
47+ private static final String TITLE_ATTRIBUTE_NAME = "title" ;
4548 private final List <Component > menuItems = new ArrayList <>();
4649 private final List <Component > toolbarComponents = new ArrayList <>();
4750
@@ -59,17 +62,29 @@ public AppLayout(Image logo, Component menuHeader, String title) {
5962
6063 private AppLayout (Component menuHeader , String aTitle , Image aLogo ) {
6164 if (aLogo != null ) {
62- aLogo .getElement ().setAttribute ("slot" , "title" );
63- add (aLogo );
65+ addToTitleSection (aLogo );
6466 }
6567 if (menuHeader != null ) {
66- menuHeader .getElement ().setAttribute ("slot" , "profile" );
67- add (menuHeader );
68+ setMenuHeader (menuHeader );
6869 }
6970 Div title = new Div ();
7071 title .setText (aTitle );
71- title .getElement ().setAttribute ("slot" , "title" );
72- add (title );
72+ addToTitleSection (title );
73+ }
74+
75+ public void addToTitleSection (Component component ) {
76+ component .getElement ().setAttribute ("slot" , APP_LAYOUT_TITLE_SLOT_NAME );
77+ add (component );
78+ }
79+
80+ /**
81+ * Sets the component to be shown before the menu in the drawer.
82+ * @param menuHeader
83+ */
84+ public void setMenuHeader (Component menuHeader ) {
85+ getChildren ().filter (item ->PROFILE_SLOT_NAME .equals (item .getElement ().getAttribute ("slot" ))).forEach (this ::remove );
86+ menuHeader .getElement ().setAttribute ("slot" , PROFILE_SLOT_NAME );
87+ add (menuHeader );
7388 }
7489
7590 public void setMenuItems (Component ... someMenuitems ) {
@@ -120,7 +135,7 @@ public boolean isMenuVisible() {
120135
121136 /** Set the toolbar title */
122137 public void setCaption (String caption ) {
123- this .getElement ().setAttribute ("title" , caption );
138+ this .getElement ().setAttribute (TITLE_ATTRIBUTE_NAME , caption );
124139 }
125140
126141 /** Mantains the header fixed at the top so it never moves away. */
0 commit comments