View Javadoc
1   /**
2    * This file Copyright (c) 2013-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.actionbar;
35  
36  import info.magnolia.i18nsystem.SimpleTranslator;
37  import info.magnolia.ui.vaadin.actionbar.Actionbar;
38  import info.magnolia.ui.vaadin.actionbar.Actionbar.ActionTriggerEvent;
39  import info.magnolia.ui.vaadin.actionbar.Actionbar.ActionTriggerListener;
40  import info.magnolia.ui.vaadin.gwt.client.actionbar.shared.ActionbarItem;
41  
42  import javax.inject.Inject;
43  
44  import com.vaadin.server.Resource;
45  
46  /**
47   * Default Vaadin implementation of the action bar view.
48   *
49   * @deprecated since 6.0. Use new framework and {@link info.magnolia.ui.contentapp.browser.actionbar.ActionbarView}.
50   */
51  @Deprecated
52  public class ActionbarViewImpl implements ActionbarView {
53  
54      private static final String PREVIEW_SECTION_NAME = "preview";
55  
56      private Actionbar actionBar = new Actionbar();
57  
58      private ActionbarView.Listener listener;
59  
60      private SimpleTranslator i18n;
61  
62      @Inject
63      public ActionbarViewImpl(SimpleTranslator i18n) {
64          this.i18n = i18n;
65          actionBar.addActionTriggerListener(new ActionTriggerListener() {
66  
67              @Override
68              public void actionTrigger(ActionTriggerEvent event) {
69                  if (listener != null) {
70                      listener.onActionbarItemClicked(event.getActionName());
71                  }
72              }
73          });
74      }
75  
76      @Override
77      public void setListener(Listener listener) {
78          this.listener = listener;
79      }
80  
81      @Override
82      public void addSection(String sectionName, String label) {
83          actionBar.addSection(sectionName, label);
84      }
85  
86      @Override
87      public void removeSection(String sectionName) {
88          actionBar.removeSection(sectionName);
89      }
90  
91      @Override
92      public void setPreview(Resource previewResource) {
93          if (previewResource != null) {
94              if (!actionBar.getSections().containsKey(PREVIEW_SECTION_NAME)) {
95                  actionBar.addSection(PREVIEW_SECTION_NAME, i18n.translate("actionbar.preview"));
96  
97              }
98              actionBar.setSectionPreview(previewResource, PREVIEW_SECTION_NAME);
99          } else {
100             if (actionBar.getSections().containsKey(PREVIEW_SECTION_NAME)) {
101                 actionBar.removeSection(PREVIEW_SECTION_NAME);
102             }
103         }
104     }
105 
106     @Override
107     public void addAction(ActionbarItem action, String sectionName) {
108         actionBar.addAction(action, sectionName);
109     }
110 
111     @Override
112     public void removeAction(String actionName) {
113         actionBar.removeAction(actionName);
114     }
115 
116     @Override
117     public void setActionEnabled(String actionName, boolean isEnabled) {
118         actionBar.setActionEnabled(actionName, isEnabled);
119     }
120 
121     @Override
122     public void setActionEnabled(String actionName, String sectionName, boolean isEnabled) {
123         actionBar.setActionEnabled(sectionName, actionName, isEnabled);
124     }
125 
126     @Override
127     public void setGroupEnabled(String groupName, boolean isEnabled) {
128         actionBar.setGroupEnabled(groupName, isEnabled);
129     }
130 
131     @Override
132     public void setGroupEnabled(String groupName, String sectionName, boolean isEnabled) {
133         actionBar.setGroupEnabled(groupName, sectionName, isEnabled);
134     }
135 
136     @Override
137     public void setSectionVisible(String sectionName, boolean isVisible) {
138         actionBar.setSectionVisible(sectionName, isVisible);
139     }
140 
141     @Override
142     public boolean isSectionVisible(String sectionName) {
143         return actionBar.isSectionVisible(sectionName);
144     }
145 
146     @Override
147     public void setOpen(boolean isOpen) {
148         actionBar.setOpen(isOpen);
149     }
150 
151     @Override
152     public Actionbar asVaadinComponent() {
153         return actionBar;
154     }
155 
156 }