View Javadoc
1   /**
2    * This file Copyright (c) 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.task.app.view.detail;
35  
36  import static com.vaadin.server.Sizeable.Unit.*;
37  
38  import info.magnolia.ui.UIComponent;
39  
40  import com.vaadin.server.Resource;
41  import com.vaadin.shared.ui.ContentMode;
42  import com.vaadin.ui.Component;
43  import com.vaadin.ui.CssLayout;
44  import com.vaadin.ui.HasComponents;
45  import com.vaadin.ui.HorizontalLayout;
46  import com.vaadin.ui.Label;
47  import com.vaadin.ui.VerticalLayout;
48  
49  /**
50   * Task Form view surrounded by a dialog environment.
51   */
52  public class TaskFormView extends VerticalLayout implements HasComponents, UIComponent {
53  
54      private Component content;
55      private Component actionbar;
56      private final Label title = new Label();
57  
58      @Override
59      public Component asVaadinComponent() {
60  
61          HorizontalLayout root = new HorizontalLayout();
62          root.setSpacing(false);
63          root.setMargin(false);
64          root.setSizeFull();
65  
66          title.setContentMode(ContentMode.HTML);
67          title.setValue("<div class='heading-1'>" + getCaption() + "</div>");
68  
69          HorizontalLayout header = new HorizontalLayout();
70          header.addStyleName("content-header");
71          header.setMargin(false);
72          header.setSpacing(false);
73          header.setWidth(100, PERCENTAGE);
74          header.addComponents(title);
75          header.setExpandRatio(title, 1f);
76  
77          CssLayout contentWraper = new CssLayout();
78          contentWraper.addStyleName("detailview");
79          contentWraper.setSizeFull();
80  
81          VerticalLayout contentArea = new VerticalLayout(header, content);
82          contentArea.setMargin(false);
83          contentArea.setSizeFull();
84          contentArea.setExpandRatio(header, 0f);
85          contentArea.setExpandRatio(content, 1f);
86          content.addStyleName("content");
87  
88          contentWraper.addComponent(contentArea);
89          root.addComponentsAndExpand(contentWraper);
90          root.addComponents(actionbar);
91  
92          addComponentsAndExpand(root);
93  
94          VerticalLayout footer = new VerticalLayout();
95          footer.setMargin(false);
96          footer.setSpacing(false);
97          footer.addStyleName("content-footer");
98          addComponent(footer);
99  
100         return this;
101     }
102 
103     public void setContent(Component content) {
104         this.content = content;
105     }
106 
107     public void setActionBar(Component actionBar) {
108         this.actionbar = actionBar;
109     }
110 
111     @Override
112     public void setCaption(String caption) {
113         super.setCaption(caption);
114         title.setValue("<div class='heading-1'>" + caption + "</div>");
115     }
116 
117     @Override
118     public void setIcon(Resource icon) {
119         super.setIcon(icon);
120         title.setIcon(icon);
121     }
122 }