View Javadoc

1   /**
2    * This file Copyright (c) 2013-2014 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.about.app;
35  
36  import info.magnolia.i18nsystem.SimpleTranslator;
37  import info.magnolia.ui.vaadin.layout.SmallAppLayout;
38  
39  import java.util.HashMap;
40  import java.util.Map;
41  import java.util.Map.Entry;
42  
43  import javax.inject.Inject;
44  
45  import com.vaadin.data.Item;
46  import com.vaadin.data.Property;
47  import com.vaadin.ui.Component;
48  import com.vaadin.ui.FormLayout;
49  import com.vaadin.ui.Label;
50  
51  /**
52   * Implementation of the {@link AboutView} interface, for the community edition.
53   */
54  public class AboutViewImpl implements AboutView {
55  
56      protected final SmallAppLayout root = new SmallAppLayout();
57  
58      private Item dataSource;
59  
60      private Map<String, Property.Viewer> dataBindings = new HashMap<String, Property.Viewer>();
61  
62      protected final SimpleTranslator i18n;
63  
64      @Inject
65      public AboutViewImpl(SimpleTranslator i18n) {
66          this.i18n = i18n;
67          root.setDescription(i18n.translate("about.app.main.description"));
68          root.addSection(createInstallationSection());
69      }
70  
71      private Component createInstallationSection() {
72  
73          // build and bind fields
74          Component mgnlEdition = buildAndBind(AboutView.MAGNOLIA_EDITION_KEY, i18n.translate("about.app.main.mgnledition"));
75          Component mgnlVersion = buildAndBind(AboutView.MAGNOLIA_VERSION_KEY, i18n.translate("about.app.main.mgnlversion"));
76          Component mgnlInstance = buildAndBind(AboutView.MAGNOLIA_INSTANCE_KEY, i18n.translate("about.app.main.instance"));
77  
78          Component osInfo = buildAndBind(AboutView.OS_INFO_KEY, i18n.translate("about.app.main.os"));
79          Component javaInfo = buildAndBind(AboutView.JAVA_INFO_KEY, i18n.translate("about.app.main.java"));
80          Component serverInfo = buildAndBind(AboutView.SERVER_INFO_KEY, i18n.translate("about.app.main.server"));
81          Component dbInfo = buildAndBind(AboutView.DB_INFO_KEY, i18n.translate("about.app.main.dbinfo"));
82          Component dbDriverInfo = buildAndBind(AboutView.DB_DRIVER_INFO_KEY, i18n.translate("about.app.main.dbdriverinfo"));
83          Component jcrInfo = buildAndBind(AboutView.JCR_INFO_KEY, i18n.translate("about.app.main.repository"));
84  
85          // layout
86          FormLayout layout = new FormLayout();
87  
88          Label sectionTitle = new Label(i18n.translate("about.app.main.installation.title"));
89          sectionTitle.addStyleName("section-title");
90          layout.addComponent(sectionTitle);
91  
92          layout.addComponent(createFieldsetTitle(i18n.translate("about.app.main.magnolia.title")));
93          layout.addComponent(mgnlEdition);
94          layout.addComponent(mgnlVersion);
95          layout.addComponent(mgnlInstance);
96  
97          Component environmentTitle = createFieldsetTitle(i18n.translate("about.app.main.environment.title"));
98          environmentTitle.addStyleName("spacer");
99          layout.addComponent(environmentTitle);
100         layout.addComponent(osInfo);
101         layout.addComponent(javaInfo);
102         layout.addComponent(serverInfo);
103         layout.addComponent(dbInfo);
104         layout.addComponent(dbDriverInfo);
105         layout.addComponent(jcrInfo);
106 
107         return layout;
108     }
109 
110     protected Component createFieldsetTitle(String title) {
111         Label fieldsetTitle = new Label(title);
112         fieldsetTitle.addStyleName("fieldset-title");
113         return fieldsetTitle;
114     }
115 
116     protected Component buildAndBind(String key, String caption) {
117         Label field = new Label();
118         field.setCaption(caption);
119         dataBindings.put(key, field);
120         return field;
121     }
122 
123     @Override
124     public void setDataSource(Item item) {
125         this.dataSource = item;
126         refresh();
127     }
128 
129     private void refresh() {
130         for (Entry<String, Property.Viewer> entry : dataBindings.entrySet()) {
131             Property.Viewer field = entry.getValue();
132             Property<?> property = dataSource.getItemProperty(entry.getKey());
133             field.setPropertyDataSource(property);
134         }
135     }
136 
137     @Override
138     public Component asVaadinComponent() {
139         return root;
140     }
141 
142 }