View Javadoc
1   /**
2    * This file Copyright (c) 2012-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.ui.admincentral;
35  
36  import info.magnolia.context.Context;
37  import info.magnolia.event.EventBus;
38  import info.magnolia.objectfactory.Components;
39  import info.magnolia.ui.admincentral.shellapp.ShellAppController;
40  import info.magnolia.ui.admincentral.shellapp.applauncher.AppLauncherShellApp;
41  import info.magnolia.ui.admincentral.shellapp.favorites.FavoritesShellApp;
42  import info.magnolia.ui.admincentral.shellapp.pulse.PulseShellApp;
43  import info.magnolia.ui.admincentral.sticker.StickerView;
44  import info.magnolia.ui.admincentral.usermenu.UserMenuPresenter;
45  import info.magnolia.ui.api.app.AppController;
46  import info.magnolia.ui.api.app.launcherlayout.AppLauncherLayoutManager;
47  import info.magnolia.ui.api.event.AdmincentralEventBus;
48  import info.magnolia.ui.api.location.DefaultLocation;
49  import info.magnolia.ui.api.location.Location;
50  import info.magnolia.ui.api.location.LocationController;
51  import info.magnolia.ui.api.location.LocationHistoryHandler;
52  import info.magnolia.ui.api.shell.Shell;
53  import info.magnolia.ui.api.view.View;
54  import info.magnolia.ui.framework.app.DefaultLocationHistoryMapper;
55  import info.magnolia.ui.framework.message.MessagesManager;
56  import info.magnolia.ui.framework.shell.ShellImpl;
57  
58  import javax.inject.Inject;
59  import javax.inject.Named;
60  
61  import com.vaadin.ui.UI;
62  
63  /**
64   * Presenter which starts up the components that make up Admincentral.
65   */
66  public class AdmincentralPresenter {
67  
68      private final ShellImpl shell;
69  
70      @Inject
71      public AdmincentralPresenter(final Shell shell, @Named(AdmincentralEventBus.NAME) final EventBus eventBus, final AppLauncherLayoutManager appLauncherLayoutManager, final LocationController locationController, final AppController appController, final ShellAppController shellAppController, MessagesManager messagesManager, UserMenuPresenter userMenu, StickerView stickerView, Context context) {
72          this.shell = (ShellImpl) shell;
73  
74          shell.setUserMenu(userMenu.start());
75          shell.setStickerView(stickerView);
76  
77          shellAppController.setViewport(this.shell.getShellAppViewport());
78          shellAppController.addShellApp("applauncher", AppLauncherShellApp.class);
79          shellAppController.addShellApp("pulse", PulseShellApp.class);
80          shellAppController.addShellApp("favorite", FavoritesShellApp.class);
81  
82          appController.setViewport(this.shell.getAppViewport());
83  
84          DefaultLocationHistoryMapper locationHistoryMapper = new DefaultLocationHistoryMapper(appLauncherLayoutManager, context);
85          LocationHistoryHandler locationHistoryHandler = new LocationHistoryHandler(locationHistoryMapper, shell);
86          locationHistoryHandler.register(locationController, eventBus, new DefaultLocation(Location.LOCATION_TYPE_SHELL_APP, "applauncher", "", ""));
87  
88          // We handle application errors at UI level in our own way, but we can't handle 'internal errors' at UI level — e.g. those that occur during paint phase and corrupt the UIDL response;
89          // for these, in order to get a trace of the error in the server logs, we rely on VaadinSession's DefaultErrorHandler — should never be null, see com.vaadin.server.ErrorEvent#findErrorHandler(ClientConnector).
90          UI.getCurrent().setErrorHandler(new AdmincentralErrorHandler(messagesManager));
91      }
92  
93      /**
94       * @deprecated since 5.6.2 - use {@link #AdmincentralPresenter(Shell, EventBus, AppLauncherLayoutManager, LocationController, AppController, ShellAppController, MessagesManager, UserMenuPresenter, StickerView, Context)} instead.
95       */
96      @Deprecated
97      public AdmincentralPresenter(final Shell shell, @Named(AdmincentralEventBus.NAME) final EventBus eventBus, final AppLauncherLayoutManager appLauncherLayoutManager, final LocationController locationController, final AppController appController, final ShellAppController shellAppController, MessagesManager messagesManager, UserMenuPresenter userMenu, Context context) {
98          this(shell, eventBus, appLauncherLayoutManager, locationController, appController, shellAppController, messagesManager, userMenu, Components.getComponent(StickerView.class), context);
99      }
100 
101     public View start() {
102         return shell::getMagnoliaShell;
103     }
104 }