View Javadoc
1   /**
2    * This file Copyright (c) 2018 Magnolia International
3    * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10   * This file is distributed in the hope that it will be
11   * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12   * implied warranty of MERCHANTABILITY or FITNESS FOR A
13   * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14   * Redistribution, except as permitted by whichever of the GPL
15   * or MNA you select, is prohibited.
16   *
17   * 1. For the GPL license (GPL), you can redistribute and/or
18   * modify this file under the terms of the GNU General
19   * Public License, Version 3, as published by the Free Software
20   * Foundation.  You should have received a copy of the GNU
21   * General Public License, Version 3 along with this program;
22   * if not, write to the Free Software Foundation, Inc., 51
23   * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24   *
25   * 2. For the Magnolia Network Agreement (MNA), this file
26   * and the accompanying materials are made available under the
27   * terms of the MNA which accompanies this distribution, and
28   * is available at http://www.magnolia-cms.com/mna.html
29   *
30   * Any modifications to this file must keep this entire header
31   * intact.
32   *
33   */
34  package info.magnolia.admincentral;
35  
36  import static com.vaadin.server.Sizeable.Unit.*;
37  import static com.vaadin.ui.Alignment.TOP_LEFT;
38  
39  import info.magnolia.admincentral.badge.NotificationBadge;
40  import info.magnolia.admincentral.badge.TaskBadge;
41  import info.magnolia.admincentral.banner.BannerContainer;
42  import info.magnolia.admincentral.components.InstanceInfo;
43  import info.magnolia.admincentral.findbar.FindBar;
44  import info.magnolia.admincentral.usermenu.UserMenu;
45  import info.magnolia.objectfactory.ComponentProvider;
46  import info.magnolia.ui.api.ioc.AdmincentralScoped;
47  
48  import javax.inject.Inject;
49  
50  import org.vaadin.jonatan.contexthelp.ContextHelp;
51  
52  import com.vaadin.server.Responsive;
53  import com.vaadin.server.ThemeResource;
54  import com.vaadin.ui.Component;
55  import com.vaadin.ui.HorizontalLayout;
56  import com.vaadin.ui.Image;
57  import com.vaadin.ui.UI;
58  import com.vaadin.ui.VerticalLayout;
59  
60  /**
61   * Resurface UI layout.
62   */
63  @AdmincentralScoped 
64  public class ResurfaceUILayout extends VerticalLayout {
65  
66      @Inject
67      public ResurfaceUILayout(ComponentProvider componentProvider, NotificationBadge notificationBadge, TaskBadge taskBadge,
68                               BannerContainer bannerContainer, InstanceInfo instanceInfo, UserMenu userMenu,
69                               ViewportLayout viewportLayout) {
70          setSizeFull();
71          setMargin(true);
72          setSpacing(true);
73          addStyleName("shell");
74  
75          // Logo
76          Image logo = new Image(null, new ThemeResource("img/logo-magnolia.svg"));
77          logo.setAlternateText("Magnolia logo");
78          logo.addStyleName("logo");
79  
80          // Find-bar
81          FindBar findBar = componentProvider.newInstance(FindBar.class, viewportLayout);
82  
83          // Header components
84          Component findBarTextBox = findBar.asVaadinComponent();
85  
86          HorizontalLayout header = new HorizontalLayout();
87          header.setWidth(100, PERCENTAGE);
88          header.setHeight(70, PIXELS);
89          header.setSpacing(true);
90          header.addStyleName("header");
91          header.addComponents(logo, findBarTextBox, taskBadge, notificationBadge, instanceInfo, userMenu);
92          header.setComponentAlignment(logo, TOP_LEFT);
93          header.setExpandRatio(findBarTextBox, 1f);
94  
95          addComponents(header);
96          setExpandRatio(header, 0f);
97  
98          VerticalLayout contentContainer = new VerticalLayout();
99          contentContainer.setSpacing(false);
100         contentContainer.setMargin(false);
101         contentContainer.setSizeFull();
102         contentContainer.addComponent(bannerContainer);
103         contentContainer.setExpandRatio(bannerContainer, 0f);
104         contentContainer.addComponent(viewportLayout);
105         contentContainer.setExpandRatio(viewportLayout, 1f);
106 
107         addComponent(contentContainer);
108         setExpandRatio(contentContainer, 1f);
109 
110         //extensions
111         Responsive.makeResponsive(this);
112         new ContextHelp().extend(UI.getCurrent()); //this is used by info.magnolia.ui.vaadin.form.field.FieldLayout
113     }
114 }