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.pages.app.editor;
35  
36  import info.magnolia.ui.api.view.View;
37  import info.magnolia.ui.vaadin.actionbar.ActionbarView;
38  import info.magnolia.ui.vaadin.editor.PageEditorView;
39  import info.magnolia.ui.vaadin.editor.pagebar.PageBarView;
40  
41  import javax.inject.Inject;
42  
43  import com.vaadin.event.ShortcutAction;
44  import com.vaadin.event.ShortcutListener;
45  import com.vaadin.server.Sizeable.Unit;
46  import com.vaadin.ui.Component;
47  import com.vaadin.ui.CssLayout;
48  import com.vaadin.ui.HorizontalLayout;
49  import com.vaadin.ui.VerticalLayout;
50  
51  /**
52   * PageEditorViewImpl.
53   */
54  public class PagesEditorSubAppViewImpl implements PagesEditorSubAppView {
55  
56      private final HorizontalLayout root = new HorizontalLayout();
57  
58      private final VerticalLayout container = new VerticalLayout();
59  
60      private Listener listener;
61  
62      private PageEditorView pageEditor;
63  
64      private ActionbarView actionBar;
65  
66      private final CssLayout actionBarWrapper = new CssLayout();
67  
68      private PageBarView pageBarView;
69  
70      @Inject
71      public PagesEditorSubAppViewImpl(PageBarView pageBarView) {
72          this.pageBarView = pageBarView;
73  
74          root.setSizeFull();
75          root.setStyleName("pageeditor");
76          root.addComponent(container);
77          root.setExpandRatio(container, 1);
78          root.setSpacing(true);
79          root.setMargin(false);
80          root.addShortcutListener(new ShortcutListener("", ShortcutAction.KeyCode.ESCAPE, null) {
81              @Override
82              public void handleAction(Object sender, Object target) {
83                  listener.onEscape();
84              }
85          });
86  
87          container.setSizeFull();
88          container.addStyleName("editor");
89  
90          actionBarWrapper.setHeight(100, Unit.PERCENTAGE);
91          actionBarWrapper.addStyleName("actionbar");
92          root.addComponent(actionBarWrapper);
93          root.setExpandRatio(actionBarWrapper, 0);
94  
95      }
96  
97      @Override
98      public void setListener(Listener listener) {
99          this.listener = listener;
100         this.pageBarView.setListener(listener);
101     }
102 
103     @Override
104     public void setPageBarView(PageBarView pageBarView) {
105         this.pageBarView = pageBarView;
106         container.addComponentAsFirst(pageBarView.asVaadinComponent());
107     }
108 
109     @Override
110     public void setPageEditorView(PageEditorView pageEditor) {
111         this.pageEditor = pageEditor;
112         container.addComponent(pageEditor.asVaadinComponent(), 1);
113         container.setExpandRatio(pageEditor.asVaadinComponent(), 1f);
114     }
115 
116     @Override
117     public void setActionbarView(final ActionbarView actionBar) {
118         Component c = actionBar.asVaadinComponent();
119         Component old = actionBarWrapper.getComponentCount() != 0 ? actionBarWrapper.getComponent(0) : null;
120         if (old == null) {
121             actionBarWrapper.addComponent(c);
122         } else {
123             actionBarWrapper.replaceComponent(old, c);
124         }
125         this.actionBar = actionBar;
126     }
127 
128     @Override
129     public Component asVaadinComponent() {
130         return root;
131     }
132 
133     @Override
134     public void hideActionbar(boolean hide) {
135         if (actionBar != null) {
136             actionBar.asVaadinComponent().setVisible(!hide);
137         }
138     }
139 
140     @Override
141     public void setContentView(View view) {
142 
143     }
144 }