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.ui.incub;
35  
36  import com.vaadin.server.ThemeResource;
37  import com.vaadin.ui.Button;
38  import com.vaadin.ui.Component;
39  import com.vaadin.ui.CssLayout;
40  import com.vaadin.ui.CustomComponent;
41  import com.vaadin.ui.FormLayout;
42  import com.vaadin.ui.Image;
43  import com.vaadin.ui.Label;
44  import com.vaadin.ui.VerticalLayout;
45  
46  /**
47   * TODO compare with actual V8 impl in new UI framework and/or drop.
48   */
49  public class LinkFieldPreviewComponent extends CustomComponent implements Component {
50  
51      private Component contentDetail;
52      private Component contentPreview;
53      private VerticalLayout rootLayout;
54  
55  
56      public LinkFieldPreviewComponent() {
57          this.rootLayout = new VerticalLayout();
58          this.rootLayout.setMargin(false);
59          setCompositionRoot(rootLayout);
60      }
61  
62      public void onValueChange() {
63          clearRootLayout();
64          contentDetail = refreshContentDetail();
65          contentPreview = refreshContentPreview();
66          refreshRootLayout();
67  
68      }
69  
70      protected void clearRootLayout() {
71          this.rootLayout.setVisible(false);
72          this.rootLayout.removeAllComponents();
73          removeStyleName("done");
74      }
75  
76      protected void refreshRootLayout() {
77          this.rootLayout.setVisible(true);
78          addStyleName("done");
79          rootLayout.addComponent(contentPreview);
80          rootLayout.addComponent(contentDetail);
81      }
82  
83      public Component refreshContentDetail() {
84          FormLayout fileInfo = new FormLayout();
85          fileInfo.setSizeUndefined();
86          fileInfo.addStyleName("file-details");
87          fileInfo.addComponent(getFileDetailFileName());
88          fileInfo.addComponent(getFileDetailSize());
89          fileInfo.addComponent(getFileDetailFileFormat());
90          return fileInfo;
91      }
92  
93      public Component refreshContentPreview() {
94          CssLayout previewLayout = new CssLayout();
95          previewLayout.addStyleName("file-preview-area");
96          // Create the preview Component (Icon / Image thumbnail/...)
97          Component image = new Image("", new ThemeResource("img/logo-magnolia.svg"));
98          if (image != null) {
99              image.addStyleName("preview-image");
100             previewLayout.addComponent(image);
101         }
102 
103         // Add buttons to the preview layout (Add LightBox) IF CONFIGURED
104         Button lightboxButton = new Button();
105         lightboxButton.addStyleName("lightbox-button");
106         lightboxButton.setCaptionAsHtml(true);
107         lightboxButton.setCaption("<span class=\"icon-search\"></span>");
108         lightboxButton.setDescription("Detail");
109         previewLayout.addComponent(lightboxButton);
110 
111         return previewLayout;
112     }
113 
114     /**
115      * Add File Name.<br>
116      */
117     protected Component getFileDetailFileName() {
118         Label label = new Label();
119         label.setCaption("Title");
120         label.setValue("Asia markt");
121         return label;
122     }
123 
124     /**
125      * Add File Info.
126      */
127     protected Component getFileDetailSize() {
128         Label label = new Label();
129         label.setCaption("Size");
130         label.setValue("2048 x 1194, 1 MB");
131         return label;
132     }
133 
134     /**
135      * Add File Format.<br>
136      */
137     protected Component getFileDetailFileFormat() {
138         Label label = new Label();
139         label.setCaption("Format");
140         label.setValue("JPG");
141         return label;
142     }
143 }