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.PIXELS;
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.TextField;
53  import com.vaadin.ui.UI;
54  import com.vaadin.ui.VerticalLayout;
55  
56  @Theme("poctheme")
57  @Title("Magnolia 6 Resurface")
58  @Widgetset("info.magnolia.poc.Widgetset")
59  public class SimpleDialogUI extends UI {
60  
61      @WebServlet(value = "/simpleDialog/*", asyncSupported = true)
62      @VaadinServletConfiguration(productionMode = false, ui = SimpleDialogUI.class)
63      public static class Servlet extends VaadinServlet {
64      }
65  
66      @Override
67      protected void init(VaadinRequest request) {
68          VerticalLayout layout = new VerticalLayout();
69          layout.setMargin(false);
70          layout.setSpacing(false);
71          layout.setWidth(926, PIXELS);
72  
73          layout.addComponent(getHeader());
74          layout.addComponent(getBody());
75          layout.addComponent(getFooter());
76          layout.setStyleName("dialog");
77  
78          setContent(layout);
79      }
80  
81      private CssLayout getHeader() {
82          CssLayout header = new CssLayout();
83          header.setStyleName("header");
84  
85          Label title = new Label("Section Header");
86  
87          Label close = new Label("X");
88          close.addStyleName("primary-actions");
89  
90          header.addComponent(title);
91          header.addComponent(close);
92  
93          return header;
94      }
95  
96      private FormLayout getBody() {
97          FormLayout formLayout = new FormLayout();
98          formLayout.setStyleName("body");
99          formLayout.setMargin(true);
100         formLayout.setHeight(245, PIXELS);
101 
102         TextField title = new TextField("Title (en)");
103         title.setValue("Nullam quis risus eget urna mollis ornare vel eu leo");
104         title.setWidth(100, Unit.PERCENTAGE);
105 
106         TextField description = new TextField("Description (en)");
107         description.setValue("Nullam quis risus eget urna mollis ornare vel eu leo");
108         description.setWidth(100, Unit.PERCENTAGE);
109 
110         CheckBoxGroup<String> checkBoxGroup = new CheckBoxGroup<>("Page in Navigation");
111         checkBoxGroup.setItems("Hide in Navigation");
112 
113         formLayout.addComponent(title);
114         formLayout.addComponent(description);
115         formLayout.addComponent(checkBoxGroup);
116 
117         return formLayout;
118     }
119 
120     private CssLayout getFooter() {
121         CssLayout footer = new CssLayout();
122         footer.setStyleName("footer");
123         footer.setWidth(100, Unit.PERCENTAGE);
124 
125         Button saveButton = new Button("Save changes");
126         saveButton.addStyleName("commit primary-button primary-actions");
127 
128         Button cancelButton = new Button("Cancel");
129         cancelButton.addStyleName("cancel secondary-button primary-actions");
130 
131         footer.addComponent(getSelectField());
132         footer.addComponent(saveButton);
133         footer.addComponent(cancelButton);
134 
135         return footer;
136     }
137 
138     private ComboBox<String> getSelectField() {
139         ComboBox<String> selectField = new ComboBox<>();
140         selectField.setEmptySelectionAllowed(false);
141         selectField.setItems("English", "French", "German");
142         selectField.setValue("English");
143         return selectField;
144     }
145 }