Revision 9c553d89
Added by Andreas Kohlbecker about 7 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/component/TimePeriodField.java | ||
---|---|---|
15 | 15 |
import com.vaadin.ui.CustomField; |
16 | 16 |
import com.vaadin.ui.GridLayout; |
17 | 17 |
import com.vaadin.ui.Label; |
18 |
import com.vaadin.ui.PopupDateField; |
|
19 | 18 |
import com.vaadin.ui.TextField; |
20 | 19 |
|
21 | 20 |
import eu.etaxonomy.cdm.model.common.TimePeriod; |
22 |
import eu.etaxonomy.cdm.vaadin.util.converter.JodaDateTimeConverter;
|
|
21 |
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationStyles;
|
|
23 | 22 |
|
24 | 23 |
/** |
25 | 24 |
* @author a.kohlbecker |
... | ... | |
34 | 33 |
|
35 | 34 |
private BeanFieldGroup<TimePeriod> fieldGroup = new BeanFieldGroup<>(TimePeriod.class); |
36 | 35 |
|
37 |
GridLayout grid = new GridLayout(4, 2); |
|
36 |
TextField parseField = null; |
|
37 |
|
|
38 |
GridLayout grid = new GridLayout(3, 3); |
|
38 | 39 |
|
39 | 40 |
/** |
40 | 41 |
* |
... | ... | |
59 | 60 |
|
60 | 61 |
super.setPrimaryStyleName(PRIMARY_STYLE); |
61 | 62 |
|
62 |
// better use https://vaadin.com/directory#!addon/tuning-datefield ???
|
|
63 |
TuningDateField startDateField = new TuningDateField();
|
|
64 |
PopupDateField startDate = new PopupDateField("Start");
|
|
65 |
startDate.setConverter(new JodaDateTimeConverter()); |
|
66 |
PopupDateField endDate = new PopupDateField("End");
|
|
67 |
endDate.setConverter(new JodaDateTimeConverter());
|
|
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");
|
|
68 | 69 |
TextField freeText = new TextField("FreeText"); |
69 | 70 |
freeText.setWidth(100, Unit.PERCENTAGE); |
70 | 71 |
|
... | ... | |
74 | 75 |
|
75 | 76 |
Label dashLabel = new Label("-"); |
76 | 77 |
|
77 |
grid.addComponent(startDate, 0, 0); |
|
78 |
grid.addComponent(dashLabel); |
|
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); |
|
79 | 83 |
grid.setComponentAlignment(dashLabel, Alignment.BOTTOM_CENTER); |
80 |
grid.addComponent(endDate, 2, 0); |
|
81 |
grid.addComponent(freeText, 0, 1, 2, 1); |
|
84 |
grid.addComponent(endDate, 2, row); |
|
85 |
row++; |
|
86 |
grid.addComponent(freeText, 0, row, 2, row); |
|
82 | 87 |
|
83 | 88 |
grid.iterator().forEachRemaining(c -> c.setStyleName(getStyleName())); |
84 | 89 |
|
... | ... | |
86 | 91 |
marginwrapper.setStyleName("margin-wrapper"); |
87 | 92 |
marginwrapper.addComponent(grid); |
88 | 93 |
|
94 |
applyDefaultStyles(); |
|
95 |
|
|
89 | 96 |
return marginwrapper; |
90 | 97 |
} |
91 | 98 |
|
92 | 99 |
|
93 | 100 |
|
101 |
/** |
|
102 |
* |
|
103 |
*/ |
|
104 |
private void applyDefaultStyles() { |
|
105 |
if(parseField != null) { |
|
106 |
parseField.addStyleName(RegistrationStyles.HELPER_FIELD); |
|
107 |
} |
|
108 |
|
|
109 |
} |
|
110 |
|
|
94 | 111 |
@Override |
95 | 112 |
protected void setInternalValue(TimePeriod newValue) { |
96 | 113 |
super.setInternalValue(newValue); |
... | ... | |
101 | 118 |
public void setStyleName(String style) { |
102 | 119 |
super.setStyleName(style); |
103 | 120 |
grid.iterator().forEachRemaining(c -> c.setStyleName(style)); |
121 |
applyDefaultStyles(); |
|
104 | 122 |
} |
105 | 123 |
|
106 | 124 |
@Override |
Also available in: Unified diff
ref #6169 impoved TimePeriod custom field