View Javadoc

1   /**
2    * This file Copyright (c) 2012-2013 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.detail;
35  
36  import com.vaadin.ui.Component;
37  import com.vaadin.ui.CssLayout;
38  import com.vaadin.ui.HorizontalLayout;
39  import info.magnolia.ui.api.view.View;
40  import info.magnolia.ui.vaadin.actionbar.ActionbarView;
41  
42  import java.util.EnumMap;
43  import java.util.Map;
44  
45  /**
46   * Implementation of {@link DetailEditorView}.
47   * Holds the {@link ActionbarView} and {@link DetailView} Currently lacking some functionality planned. See MGNLUI-154.
48   */
49  public class DetailEditorViewImpl extends HorizontalLayout implements DetailEditorView {
50  
51      private final CssLayout itemViewContainer = new CssLayout();
52      private final Map<DetailView.ViewType, DetailView> itemViews = new EnumMap<DetailView.ViewType, DetailView>(DetailView.ViewType.class);
53  
54      private ActionbarView actionBar;
55  
56      private final CssLayout actionBarWrapper = new CssLayout();
57  
58      private DetailView.ViewType currentViewType = DetailView.ViewType.VIEW;
59  
60      private DetailEditorView.Listener contentWorkbenchViewListener;
61  
62      public DetailEditorViewImpl() {
63          setSizeFull();
64          setMargin(false);
65          setSpacing(true);
66          addStyleName("detail");
67  
68          itemViewContainer.setSizeFull();
69          itemViewContainer.setStyleName("detailview");
70          addComponent(itemViewContainer);
71          setExpandRatio(itemViewContainer, 1);
72  
73          actionBarWrapper.setHeight(100, Unit.PERCENTAGE);
74          actionBarWrapper.addStyleName("actionbar");
75          addComponent(actionBarWrapper);
76          setExpandRatio(actionBarWrapper, 0);
77      }
78  
79      @Override
80      public Component asVaadinComponent() {
81          return this;
82      }
83  
84      @Override
85      public void setListener(DetailEditorView.Listener listener) {
86          this.contentWorkbenchViewListener = listener;
87      }
88  
89      @Override
90      public void setViewType(final DetailView.ViewType type) {
91  
92          itemViewContainer.removeComponent(itemViews.get(currentViewType).asVaadinComponent());
93          final Component c = itemViews.get(type).asVaadinComponent();
94  
95          c.setSizeFull();
96          itemViewContainer.addComponent(c);
97  
98          this.currentViewType = type;
99          refresh();
100         this.contentWorkbenchViewListener.onViewTypeChanged(currentViewType);
101     }
102 
103     @Override
104     public void refresh() {
105 
106     }
107 
108     @Override
109     public void addItemView(DetailView.ViewType type, DetailView view) {
110 
111     }
112 
113     @Override
114     public void setItemView(final View itemView) {
115         itemViewContainer.removeAllComponents();
116         itemView.asVaadinComponent().setHeight("100%");
117         itemViewContainer.addComponent(itemView.asVaadinComponent());
118     }
119 
120     @Override
121     public void setActionbarView(final ActionbarView actionBar) {
122         Component c = actionBar.asVaadinComponent();
123         c.addStyleName("stub");
124         actionBar.setOpen(false);
125 
126         Component old = actionBarWrapper.getComponentCount() != 0 ? actionBarWrapper.getComponent(0) : null;
127         if (old == null) {
128             actionBarWrapper.addComponent(c);
129         } else {
130             actionBarWrapper.replaceComponent(old, c);
131         }
132         this.actionBar = actionBar;
133     }
134 
135 }