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.poc;
35  
36  import static com.vaadin.server.Sizeable.Unit.*;
37  
38  import javax.servlet.annotation.WebServlet;
39  
40  import com.vaadin.annotations.Theme;
41  import com.vaadin.annotations.Title;
42  import com.vaadin.annotations.VaadinServletConfiguration;
43  import com.vaadin.annotations.Widgetset;
44  import com.vaadin.server.VaadinRequest;
45  import com.vaadin.server.VaadinServlet;
46  import com.vaadin.ui.Button;
47  import com.vaadin.ui.CheckBoxGroup;
48  import com.vaadin.ui.ComboBox;
49  import com.vaadin.ui.CssLayout;
50  import com.vaadin.ui.FormLayout;
51  import com.vaadin.ui.Label;
52  import com.vaadin.ui.TabSheet;
53  import com.vaadin.ui.TextField;
54  import com.vaadin.ui.UI;
55  import com.vaadin.ui.VerticalLayout;
56  import com.vaadin.ui.themes.ValoTheme;
57  
58  @Theme("poctheme")
59  @Title("Magnolia 6 Resurface")
60  @Widgetset("info.magnolia.poc.Widgetset")
61  public class ComplexDialogUI extends UI {
62  
63      @WebServlet(value = "/complexDialog/*", asyncSupported = true)
64      @VaadinServletConfiguration(productionMode = false, ui = ComplexDialogUI.class)
65      public static class Servlet extends VaadinServlet {
66      }
67  
68      @Override
69      protected void init(VaadinRequest request) {
70          // TODO: this is for the sake of the demo
71          setHeight(600, PIXELS);
72  
73          VerticalLayout layout = new VerticalLayout();
74          layout.setMargin(false);
75          layout.setSpacing(false);
76          layout.setWidth(926, PIXELS);
77          layout.setHeightUndefined();
78  
79          layout.addComponent(getHeader());
80          layout.addComponent(getTabSheet());
81          layout.addComponent(getFooter());
82          layout.setStyleName("dialog");
83  
84          setContent(layout);
85      }
86  
87      private CssLayout getHeader() {
88          CssLayout header = new CssLayout();
89          header.setStyleName("header");
90          header.setHeight(75, Unit.PIXELS);
91  
92          Label title = new Label("Section Header");
93  
94          Label close = new Label("X");
95          close.addStyleName("primary-actions");
96  
97          header.addComponent(title);
98          header.addComponent(close);
99  
100         return header;
101     }
102 
103 
104     private TabSheet getTabSheet() {
105         TabSheet tabSheetComponent = new TabSheet();
106         tabSheetComponent.setWidth(100, PERCENTAGE);
107         tabSheetComponent.addStyleName(ValoTheme.TABSHEET_FRAMED);
108 
109         tabSheetComponent.addTab(getBody(), "Meta Data");
110         tabSheetComponent.addTab(getBody(), "Article Info");
111         tabSheetComponent.addTab(getBody(), "Output channels");
112 
113         return tabSheetComponent;
114     }
115 
116     private FormLayout getBody() {
117         FormLayout formLayout = new FormLayout();
118         formLayout.setStyleName("body");
119         formLayout.setMargin(true);
120 
121         TextField title = new TextField("Title (en)");
122         title.setValue("Nullam quis risus eget urna mollis ornare vel eu leo");
123         title.setWidth(100, PERCENTAGE);
124 
125         TextField description = new TextField("Description (en)");
126         description.setValue("Nullam quis risus eget urna mollis ornare vel eu leo");
127         description.setWidth(100, PERCENTAGE);
128 
129         CheckBoxGroup<String> checkBoxGroup = new CheckBoxGroup<>("Page in Navigation");
130         checkBoxGroup.setItems("Hide in Navigation");
131 
132         formLayout.setSizeFull();
133 
134         formLayout.addComponent(title);
135         formLayout.addComponent(description);
136         formLayout.addComponent(checkBoxGroup);
137 
138         return formLayout;
139     }
140 
141     private CssLayout getFooter() {
142         CssLayout footer = new CssLayout();
143         footer.setStyleName("footer");
144         footer.setWidth(100, PERCENTAGE);
145         footer.setHeight(75, Unit.PIXELS);
146 
147         Button saveButton = new Button("Save changes");
148         saveButton.addStyleName("commit primary-button primary-actions");
149 
150         Button cancelButton = new Button("Cancel");
151         cancelButton.addStyleName("cancel secondary-button primary-actions");
152 
153         footer.addComponent(getSelectField());
154         footer.addComponent(saveButton);
155         footer.addComponent(cancelButton);
156 
157         return footer;
158     }
159 
160     private ComboBox<String> getSelectField() {
161         ComboBox<String> selectField = new ComboBox<>();
162         selectField.setEmptySelectionAllowed(false);
163         selectField.setItems("English", "French", "German");
164         selectField.setValue("English");
165         return selectField;
166     }
167 }