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.component;
|
10
|
|
11
|
import com.vaadin.data.fieldgroup.BeanFieldGroup;
|
12
|
import com.vaadin.ui.Alignment;
|
13
|
import com.vaadin.ui.Component;
|
14
|
import com.vaadin.ui.CssLayout;
|
15
|
import com.vaadin.ui.CustomField;
|
16
|
import com.vaadin.ui.GridLayout;
|
17
|
import com.vaadin.ui.Label;
|
18
|
import com.vaadin.ui.TextField;
|
19
|
|
20
|
import eu.etaxonomy.cdm.model.common.TimePeriod;
|
21
|
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationStyles;
|
22
|
|
23
|
/**
|
24
|
* @author a.kohlbecker
|
25
|
* @since Apr 6, 2017
|
26
|
*
|
27
|
*/
|
28
|
public class TimePeriodField extends CustomField<TimePeriod> {
|
29
|
|
30
|
private static final long serialVersionUID = -7377778547595966252L;
|
31
|
|
32
|
private static final String PRIMARY_STYLE = "v-time-period-field";
|
33
|
|
34
|
private BeanFieldGroup<TimePeriod> fieldGroup = new BeanFieldGroup<>(TimePeriod.class);
|
35
|
|
36
|
TextField parseField = null;
|
37
|
|
38
|
GridLayout grid = new GridLayout(3, 3);
|
39
|
|
40
|
/**
|
41
|
*
|
42
|
*/
|
43
|
public TimePeriodField() {
|
44
|
super();
|
45
|
}
|
46
|
|
47
|
/**
|
48
|
* @param string
|
49
|
*/
|
50
|
public TimePeriodField(String string) {
|
51
|
this();
|
52
|
setCaption(string);
|
53
|
}
|
54
|
|
55
|
/**
|
56
|
* {@inheritDoc}
|
57
|
*/
|
58
|
@Override
|
59
|
protected Component initContent() {
|
60
|
|
61
|
super.setPrimaryStyleName(PRIMARY_STYLE);
|
62
|
|
63
|
parseField = new TextField();
|
64
|
parseField.setWidth(100, Unit.PERCENTAGE);
|
65
|
parseField.setInputPrompt("This field will parse the entered time period");
|
66
|
|
67
|
PartialDateField startDate = new PartialDateField("Start");
|
68
|
PartialDateField endDate = new PartialDateField("End");
|
69
|
TextField freeText = new TextField("FreeText");
|
70
|
freeText.setWidth(100, Unit.PERCENTAGE);
|
71
|
|
72
|
fieldGroup.bind(startDate, "start");
|
73
|
fieldGroup.bind(endDate, "end");
|
74
|
fieldGroup.bind(freeText, "freeText");
|
75
|
|
76
|
Label dashLabel = new Label("-");
|
77
|
|
78
|
int row = 0;
|
79
|
grid.addComponent(parseField, 0, row, 2, row);
|
80
|
row++;
|
81
|
grid.addComponent(startDate, 0, row);
|
82
|
grid.addComponent(dashLabel, 1, row);
|
83
|
grid.setComponentAlignment(dashLabel, Alignment.BOTTOM_CENTER);
|
84
|
grid.addComponent(endDate, 2, row);
|
85
|
row++;
|
86
|
grid.addComponent(freeText, 0, row, 2, row);
|
87
|
|
88
|
grid.iterator().forEachRemaining(c -> c.setStyleName(getStyleName()));
|
89
|
|
90
|
CssLayout marginwrapper = new CssLayout();
|
91
|
marginwrapper.setStyleName("margin-wrapper");
|
92
|
marginwrapper.addComponent(grid);
|
93
|
|
94
|
applyDefaultStyles();
|
95
|
|
96
|
return marginwrapper;
|
97
|
}
|
98
|
|
99
|
|
100
|
|
101
|
/**
|
102
|
*
|
103
|
*/
|
104
|
private void applyDefaultStyles() {
|
105
|
if(parseField != null) {
|
106
|
parseField.addStyleName(RegistrationStyles.HELPER_FIELD);
|
107
|
}
|
108
|
|
109
|
}
|
110
|
|
111
|
@Override
|
112
|
protected void setInternalValue(TimePeriod newValue) {
|
113
|
super.setInternalValue(newValue);
|
114
|
fieldGroup.setItemDataSource(newValue);
|
115
|
}
|
116
|
|
117
|
@Override
|
118
|
public void setStyleName(String style) {
|
119
|
super.setStyleName(style);
|
120
|
grid.iterator().forEachRemaining(c -> c.setStyleName(style));
|
121
|
applyDefaultStyles();
|
122
|
}
|
123
|
|
124
|
@Override
|
125
|
public void addStyleName(String style) {
|
126
|
super.addStyleName(style);
|
127
|
grid.iterator().forEachRemaining(c -> c.addStyleName(style));
|
128
|
}
|
129
|
|
130
|
/**
|
131
|
* {@inheritDoc}
|
132
|
*/
|
133
|
@Override
|
134
|
public Class<? extends TimePeriod> getType() {
|
135
|
return TimePeriod.class;
|
136
|
}
|
137
|
|
138
|
}
|