View Javadoc

1   /**
2    * This file Copyright (c) 2012-2014 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.applauncher.widget;
35  
36  import info.magnolia.ui.vaadin.gwt.client.applauncher.event.AppActivationEvent;
37  import info.magnolia.ui.vaadin.gwt.client.applauncher.shared.AppGroup;
38  import info.magnolia.ui.vaadin.gwt.client.applauncher.shared.AppTile;
39  
40  import java.util.HashMap;
41  import java.util.Map;
42  import java.util.Map.Entry;
43  
44  import com.google.gwt.user.client.ui.FlowPanel;
45  import com.google.web.bindery.event.shared.EventBus;
46  
47  /**
48   * Implementation of AppLauncher view.
49   */
50  public class AppLauncherViewImpl extends FlowPanel implements AppLauncherView, AppActivationEvent.Handler {
51  
52      private final Map<String, VAppTileGroup> groups = new HashMap<String, VAppTileGroup>();
53  
54      private final VTemporaryAppGroupBar temporarySectionsBar = new VTemporaryAppGroupBar();
55  
56      private final EventBus eventBus;
57  
58      private Presenter presenter;
59  
60      public AppLauncherViewImpl(final EventBus eventBus) {
61          super();
62          this.eventBus = eventBus;
63          add(temporarySectionsBar);
64          this.eventBus.addHandler(AppActivationEvent.TYPE, this);
65      }
66  
67      @Override
68      public void addAppGroup(AppGroup group) {
69          if (group.isPermanent()) {
70              addPermanentAppGroup(group);
71          } else {
72              addTemporaryAppGroup(group);
73          }
74      }
75  
76      public void addTemporaryAppGroup(AppGroup groupParams) {
77          final VAppTileGroup group = new VTemporaryAppTileGroup(groupParams.getBackgroundColor());
78          group.setClientGroup(groupParams.isClientGroup());
79          groups.put(groupParams.getName(), group);
80          temporarySectionsBar.addGroup(groupParams.getCaption(), group);
81          add(group);
82      }
83  
84      public void addPermanentAppGroup(AppGroup groupParams) {
85          final VPermanentAppTileGroup group = new VPermanentAppTileGroup(groupParams.getCaption(), groupParams.getBackgroundColor());
86          group.setClientGroup(groupParams.isClientGroup());
87          groups.put(groupParams.getName(), group);
88          add(group);
89      }
90  
91      @Override
92      public void onAppActivated(AppActivationEvent event) {
93          presenter.activateApp(event.getAppName());
94      }
95  
96      @Override
97      public void setPresenter(Presenter presenter) {
98          this.presenter = presenter;
99      }
100 
101     @Override
102     public void setAppActive(String appName, boolean isActive) {
103         for (Entry<String, VAppTileGroup> entry : groups.entrySet()) {
104             if (entry.getValue().hasApp(appName)) {
105                 AppTileWidget tile = entry.getValue().getAppTile(appName);
106                 tile.setActiveState(isActive);
107             }
108         }
109     }
110 
111     @Override
112     public void addAppTile(AppTile tileData, AppGroup groupData) {
113         AppTileWidget tile = new AppTileWidget(eventBus, tileData);
114         VAppTileGroup group = groups.get(groupData.getName());
115         if (group != null) {
116             group.addAppTile(tile);
117         }
118     }
119 
120     @Override
121     public void clear() {
122         temporarySectionsBar.clear();
123         for (final VAppTileGroup group : groups.values()) {
124             remove(group);
125         }
126         groups.clear();
127     }
128 
129 }