View Javadoc
1   /**
2    * This file Copyright (c) 2010-2017 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.vaadin.gwt.client.magnoliashell.viewport.connector;
35  
36  import info.magnolia.ui.vaadin.gwt.client.magnoliashell.event.AppRequestedEvent;
37  import info.magnolia.ui.vaadin.gwt.client.magnoliashell.event.HideShellAppsEvent;
38  import info.magnolia.ui.vaadin.gwt.client.magnoliashell.event.HideShellAppsRequestedEvent;
39  import info.magnolia.ui.vaadin.gwt.client.magnoliashell.event.ShellAppRequestedEvent;
40  import info.magnolia.ui.vaadin.gwt.client.magnoliashell.event.ShellAppStartedEvent;
41  import info.magnolia.ui.vaadin.gwt.client.magnoliashell.event.ShellAppStartingEvent;
42  import info.magnolia.ui.vaadin.gwt.client.magnoliashell.event.ShellAppsHiddenEvent;
43  import info.magnolia.ui.vaadin.gwt.client.magnoliashell.viewport.ShellAppsTransitionDelegate;
44  import info.magnolia.ui.vaadin.gwt.client.magnoliashell.viewport.widget.ShellAppsViewportWidget;
45  import info.magnolia.ui.vaadin.gwt.client.shared.magnoliashell.ShellAppType;
46  import info.magnolia.ui.vaadin.magnoliashell.viewport.ShellAppsViewport;
47  
48  import com.google.gwt.user.client.ui.Widget;
49  import com.google.web.bindery.event.shared.EventBus;
50  import com.vaadin.client.ComponentConnector;
51  import com.vaadin.client.Util;
52  import com.vaadin.shared.ui.Connect;
53  
54  /**
55   * ShellAppsViewportConnector.
56   */
57  @Connect(ShellAppsViewport.class)
58  public class ShellAppsViewportConnector extends ViewportConnector implements ShellAppsViewportWidget.Listener {
59  
60      @Override
61      protected void init() {
62          super.init();
63          getWidget().setTransitionDelegate(new ShellAppsTransitionDelegate(getWidget()));
64      }
65  
66      public void showShellApp(ShellAppType type) {
67          ComponentConnector shellAppConnector = (ComponentConnector) getState().shellApps.get(type);
68          Widget w = shellAppConnector.getWidget();
69          getWidget().showChild(w);
70          if (!getWidget().isActive()) {
71              w.getElement().getStyle().clearOpacity();
72              getWidget().setActive(true);
73          }
74          getLayoutManager().setNeedsMeasure(shellAppConnector);
75          eventBus.fireEvent(new ShellAppStartingEvent(type));
76      }
77  
78      @Override
79      public void setEventBus(EventBus eventBus) {
80          super.setEventBus(eventBus);
81          eventBus.addHandler(ShellAppRequestedEvent.TYPE, new ShellAppRequestedEvent.Handler() {
82              @Override
83              public void onShellAppRequested(ShellAppRequestedEvent event) {
84                  if (!getWidget().isActive() || !getConnection().getMessageSender().hasActiveRequest()) {
85                      showShellApp(event.getType());
86                  }
87              }
88          });
89  
90          eventBus.addHandler(HideShellAppsEvent.TYPE, new HideShellAppsEvent.Handler() {
91              @Override
92              public void onHideShellApps(HideShellAppsEvent event) {
93                  getWidget().setActive(false);
94              }
95          });
96  
97          eventBus.addHandler(AppRequestedEvent.TYPE, new AppRequestedEvent.Handler() {
98              @Override
99              public void onAppRequested(AppRequestedEvent event) {
100                 getWidget().setActiveNoTransition(false);
101             }
102         });
103     }
104 
105     @Override
106     public ShellAppsViewportWidget getWidget() {
107         return (ShellAppsViewportWidget)super.getWidget();
108     }
109 
110     @Override
111     protected ShellAppsViewportWidget createWidget() {
112         return new ShellAppsViewportWidget(this);
113     }
114 
115     @Override
116     public ShellAppViewportState getState() {
117         return (ShellAppViewportState) super.getState();
118     }
119 
120     @Override
121     public void onShellAppLoaded(Widget shellAppWidget) {
122         ComponentConnector shellAppConnector = Util.findConnectorFor(shellAppWidget);
123         eventBus.fireEvent(new ShellAppStartedEvent(getState().getShellAppType(shellAppConnector)));
124     }
125 
126     @Override
127     public void outerContentClicked() {
128         eventBus.fireEvent(new HideShellAppsRequestedEvent());
129     }
130 
131     @Override
132     public void onShellAppsHidden() {
133         eventBus.fireEvent(new ShellAppsHiddenEvent());
134     }
135 
136 }