1
|
/**
|
2
|
* Copyright (C) 2017 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.vaadin.view;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.List;
|
13
|
|
14
|
import com.vaadin.shared.ui.label.ContentMode;
|
15
|
import com.vaadin.ui.AbstractLayout;
|
16
|
import com.vaadin.ui.Component;
|
17
|
import com.vaadin.ui.Label;
|
18
|
import com.vaadin.ui.VerticalLayout;
|
19
|
import com.vaadin.ui.themes.ValoTheme;
|
20
|
|
21
|
import eu.etaxonomy.vaadin.mvp.AbstractPresenter;
|
22
|
import eu.etaxonomy.vaadin.mvp.AbstractView;
|
23
|
|
24
|
/**
|
25
|
* A Page based on a <code>CssLayout</code> expanded to full size having a header and sub-header.
|
26
|
*
|
27
|
* The whole header section is build using a single <code>Label</code> for better performance.
|
28
|
*
|
29
|
* @author a.kohlbecker
|
30
|
* @since Mar 20, 2017
|
31
|
*
|
32
|
*/
|
33
|
public abstract class AbstractPageView<P extends AbstractPresenter> extends AbstractView<P> {
|
34
|
|
35
|
private VerticalLayout layout;
|
36
|
|
37
|
private List<Component> contentComponents = new ArrayList<>();
|
38
|
|
39
|
private Label header;
|
40
|
|
41
|
|
42
|
/**
|
43
|
*
|
44
|
*/
|
45
|
public AbstractPageView() {
|
46
|
layout = new VerticalLayout();
|
47
|
layout.setSizeFull();
|
48
|
|
49
|
header = new Label();
|
50
|
header.setStyleName(ValoTheme.LABEL_HUGE);
|
51
|
header.setWidth(100, Unit.PERCENTAGE);
|
52
|
header.setContentMode(ContentMode.HTML);
|
53
|
updateHeader();
|
54
|
layout.addComponent(header);
|
55
|
|
56
|
setCompositionRoot(layout);
|
57
|
this.setSizeFull();
|
58
|
}
|
59
|
|
60
|
/**
|
61
|
*
|
62
|
*/
|
63
|
public void updateHeader() {
|
64
|
header.setValue("<div id=\"header\">" + getHeaderText() + "</div><div id=\"subheader\">" + getSubHeaderText() + "</div>");
|
65
|
}
|
66
|
|
67
|
protected AbstractLayout getLayout() {
|
68
|
return layout;
|
69
|
}
|
70
|
|
71
|
protected void removeContentComponents(){
|
72
|
for(Component c : contentComponents){
|
73
|
layout.removeComponent(c);
|
74
|
}
|
75
|
|
76
|
}
|
77
|
|
78
|
protected void addContentComponent(Component component, Float expandRatio){
|
79
|
contentComponents.add(component);
|
80
|
layout.addComponent(component);
|
81
|
if(expandRatio != null){
|
82
|
layout.setExpandRatio(component, expandRatio);
|
83
|
}
|
84
|
}
|
85
|
|
86
|
|
87
|
|
88
|
/**
|
89
|
* Provides the sub header text
|
90
|
*
|
91
|
* @return
|
92
|
*/
|
93
|
protected abstract String getHeaderText();
|
94
|
|
95
|
/**
|
96
|
* Provides the header text
|
97
|
*
|
98
|
* @return
|
99
|
*/
|
100
|
protected abstract String getSubHeaderText();
|
101
|
|
102
|
|
103
|
|
104
|
}
|