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.contentapp.browser;
35  
36  import info.magnolia.ui.actionbar.ActionbarView;
37  import info.magnolia.ui.api.view.View;
38  import info.magnolia.ui.vaadin.actionbar.ActionPopup;
39  import info.magnolia.ui.workbench.WorkbenchView;
40  
41  import com.vaadin.ui.MenuBar.MenuItem;
42  import com.vaadin.server.Resource;
43  import com.vaadin.ui.Component;
44  import com.vaadin.ui.CssLayout;
45  import com.vaadin.ui.HorizontalLayout;
46  import com.vaadin.ui.VerticalLayout;
47  
48  /**
49   * Implementation of {@link BrowserView}.
50   *
51   * @deprecated since 6.2 - without direct replacement. The closest 'relative' now is the {@link Browser}.
52   *
53   * @see <a href="https://documentation.magnolia-cms.com/display/DOCS62/Upgrading+to+Magnolia+6.2.x">Upgrading to Magnolia 6.2.x</a>
54   */
55  @Deprecated
56  public class BrowserViewImpl extends VerticalLayout implements BrowserView {
57  
58      private ActionbarView actionBar;
59  
60      private ActionPopup actionPopup;
61  
62      private final CssLayout actionBarWrapper = new CssLayout();
63  
64      private final HorizontalLayout workbenchWapper = new HorizontalLayout();
65  
66      private WorkbenchView workbench;
67  
68      private BrowserView.Listener listener;
69  
70      public BrowserViewImpl() {
71          setSizeFull();
72          setMargin(false);
73          setSpacing(false);
74          addStyleName("browser");
75  
76          workbenchWapper.setSizeFull();
77          workbenchWapper.setMargin(false);
78          workbenchWapper.setSpacing(true);
79  
80          actionBarWrapper.setHeight(100, Unit.PERCENTAGE);
81          actionBarWrapper.addStyleName("actionbar");
82          workbenchWapper.addComponent(actionBarWrapper);
83          workbenchWapper.setExpandRatio(actionBarWrapper, 0);
84  
85          addComponent(workbenchWapper);
86          setExpandRatio(workbenchWapper, 1);
87          createActionPopup();
88  
89      }
90  
91      @Override
92      public void setActionbarView(final ActionbarView actionBar) {
93          Component c = actionBar.asVaadinComponent();
94          Component old = actionBarWrapper.getComponentCount() != 0 ? actionBarWrapper.getComponent(0) : null;
95          if (old == null) {
96              actionBarWrapper.addComponent(c);
97          } else {
98              actionBarWrapper.replaceComponent(old, c);
99          }
100         this.actionBar = actionBar;
101     }
102 
103     @Override
104     public Component asVaadinComponent() {
105         return this;
106     }
107 
108     @Override
109     public void setListener(BrowserView.Listener listener) {
110         this.listener = listener;
111     }
112 
113     @Override
114     public void setWorkbenchView(WorkbenchView workbench) {
115         if (this.workbench == null) {
116             workbenchWapper.addComponent(workbench.asVaadinComponent(), 0); // add as first
117         } else {
118             workbenchWapper.replaceComponent(this.workbench.asVaadinComponent(), workbench.asVaadinComponent());
119         }
120         workbenchWapper.setExpandRatio(workbench.asVaadinComponent(), 1);
121 
122         View statusBarView = workbench.getStatusBarView();
123         if (statusBarView != null) {
124             addComponent(statusBarView.asVaadinComponent());
125             setExpandRatio(statusBarView.asVaadinComponent(), 0);
126         }
127         this.workbench = workbench;
128     }
129 
130     /**
131      * Create an ActionPopup which will be triggered by right-clicks on items in Content views.
132      */
133     protected void createActionPopup() {
134         actionPopup = new ActionPopup(this, false);
135         actionPopup.setAsContextMenuOf(this);
136     }
137 
138     @Override
139     public ActionPopup getActionPopup() {
140         return actionPopup;
141     }
142 
143     @Override
144     public MenuItem addPopupItem(String label, Resource iconFontResource) {
145         return actionPopup.addItem(label, iconFontResource, item -> {});
146     }
147 }