1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
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
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
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
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
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
136
137 protected Component getFileDetailFileFormat() {
138 Label label = new Label();
139 label.setCaption("Format");
140 label.setValue("JPG");
141 return label;
142 }
143 }