Revision 9c553d89
Added by Andreas Kohlbecker about 7 years ago
src/main/java/eu/etaxonomy/cdm/mock/RegistrationService.java | ||
---|---|---|
36 | 36 |
* |
37 | 37 |
*/ |
38 | 38 |
@Service("registrationServiceMock") |
39 |
@Transactional |
|
39 |
@Transactional(readOnly=true)
|
|
40 | 40 |
public class RegistrationService { |
41 | 41 |
|
42 |
/** |
|
43 |
* |
|
44 |
*/ |
|
45 | 42 |
private static final int SIZE = 50; // FIXME test performance with 50 !!!!! |
46 | 43 |
|
47 | 44 |
@Autowired |
... | ... | |
68 | 65 |
int pageIndex = 0; |
69 | 66 |
while(registrationsByUUID.size() < SIZE){ |
70 | 67 |
List<TaxonNameBase> names = repo.getNameService().list(TaxonNameBase.class, 100, pageIndex++, null, null); |
68 |
if(names.isEmpty()){ |
|
69 |
break; |
|
70 |
} |
|
71 | 71 |
for(TaxonNameBase name : names){ |
72 | 72 |
if(name != null && name.getRank() != null && name.getRank().isLower(Rank.SUBFAMILY())){ |
73 | 73 |
if(name.getTypeDesignations().size() > minTypeDesignationCount - 1) { |
src/main/java/eu/etaxonomy/cdm/vaadin/AppWidgetSet.gwt.xml | ||
---|---|---|
39 | 39 |
|
40 | 40 |
|
41 | 41 |
|
42 |
<inherits name="org.vaadin.addons.tuningdatefield.widgetset.TuningDateFieldWidgetset" /> |
|
42 |
|
|
43 | 43 |
</module> |
src/main/java/eu/etaxonomy/cdm/vaadin/component/PartialDateField.java | ||
---|---|---|
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.Property; |
|
12 |
import com.vaadin.ui.TextField; |
|
13 |
|
|
14 |
import eu.etaxonomy.cdm.vaadin.util.converter.JodaTimePartialConverter; |
|
15 |
|
|
16 |
/** |
|
17 |
* The PartialDateField is just a simple TextField by now but will evolve to |
|
18 |
* a more user friendly widget with either selectors for year, month, day |
|
19 |
* or it will use calendar widget like the DateField which allows selecting only |
|
20 |
* the year or year + month. |
|
21 |
* |
|
22 |
* @author a.kohlbecker |
|
23 |
* @since Apr 7, 2017 |
|
24 |
* |
|
25 |
*/ |
|
26 |
public class PartialDateField extends TextField { |
|
27 |
|
|
28 |
/** |
|
29 |
* |
|
30 |
*/ |
|
31 |
public PartialDateField() { |
|
32 |
super(); |
|
33 |
setConverter(new JodaTimePartialConverter()); |
|
34 |
} |
|
35 |
|
|
36 |
/** |
|
37 |
* @param dataSource |
|
38 |
*/ |
|
39 |
public PartialDateField(Property dataSource) { |
|
40 |
super(dataSource); |
|
41 |
setConverter(new JodaTimePartialConverter()); |
|
42 |
} |
|
43 |
|
|
44 |
/** |
|
45 |
* @param caption |
|
46 |
* @param dataSource |
|
47 |
*/ |
|
48 |
public PartialDateField(String caption, Property dataSource) { |
|
49 |
super(caption, dataSource); |
|
50 |
setConverter(new JodaTimePartialConverter()); |
|
51 |
} |
|
52 |
|
|
53 |
/** |
|
54 |
* @param caption |
|
55 |
* @param value |
|
56 |
*/ |
|
57 |
public PartialDateField(String caption, String value) { |
|
58 |
super(caption, value); |
|
59 |
setConverter(new JodaTimePartialConverter()); |
|
60 |
} |
|
61 |
|
|
62 |
/** |
|
63 |
* @param caption |
|
64 |
*/ |
|
65 |
public PartialDateField(String caption) { |
|
66 |
super(caption); |
|
67 |
setConverter(new JodaTimePartialConverter()); |
|
68 |
} |
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
} |
src/main/java/eu/etaxonomy/cdm/vaadin/component/SelectFieldFactory.java | ||
---|---|---|
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 java.util.ArrayList; |
|
12 |
import java.util.Arrays; |
|
13 |
import java.util.List; |
|
14 |
|
|
15 |
import org.springframework.beans.factory.annotation.Autowired; |
|
16 |
import org.springframework.beans.factory.annotation.Qualifier; |
|
17 |
|
|
18 |
import com.vaadin.data.util.BeanItemContainer; |
|
19 |
import com.vaadin.spring.annotation.SpringComponent; |
|
20 |
import com.vaadin.ui.ListSelect; |
|
21 |
|
|
22 |
import eu.etaxonomy.cdm.api.application.CdmRepository; |
|
23 |
import eu.etaxonomy.cdm.model.common.DefinedTermBase; |
|
24 |
import eu.etaxonomy.cdm.model.common.TermType; |
|
25 |
import eu.etaxonomy.cdm.persistence.query.OrderHint; |
|
26 |
|
|
27 |
/** |
|
28 |
* @author a.kohlbecker |
|
29 |
* @since Apr 6, 2017 |
|
30 |
* |
|
31 |
*/ |
|
32 |
@SpringComponent |
|
33 |
public class SelectFieldFactory { |
|
34 |
|
|
35 |
@Autowired |
|
36 |
@Qualifier("cdmRepository") |
|
37 |
private CdmRepository repo; |
|
38 |
|
|
39 |
private final static List<String> INIT_STRATEGY = Arrays.asList(new String[]{"$", "representations"}); |
|
40 |
|
|
41 |
private static List<OrderHint> orderHints = new ArrayList<>(); |
|
42 |
|
|
43 |
static { |
|
44 |
orderHints.add(OrderHint.BY_ORDER_INDEX); |
|
45 |
orderHints.add(OrderHint.ORDER_BY_TITLE_CACHE); |
|
46 |
} |
|
47 |
|
|
48 |
public ListSelect createListSelect(String caption, TermType termType){ |
|
49 |
BeanItemContainer<DefinedTermBase> termItemContainer = buildBeanItemContainer(termType); |
|
50 |
ListSelect select = new ListSelect(caption, termItemContainer); |
|
51 |
return select; |
|
52 |
} |
|
53 |
|
|
54 |
/** |
|
55 |
* @param termType |
|
56 |
*/ |
|
57 |
private BeanItemContainer<DefinedTermBase> buildBeanItemContainer(TermType termType) { |
|
58 |
// TODO use TermCacher? |
|
59 |
List<DefinedTermBase> terms = repo.getTermService().listByTermType(termType, null, null, orderHints, INIT_STRATEGY); |
|
60 |
BeanItemContainer<DefinedTermBase> termItemContainer = new BeanItemContainer<>(DefinedTermBase.class); |
|
61 |
termItemContainer.addAll(terms); |
|
62 |
return termItemContainer; |
|
63 |
} |
|
64 |
|
|
65 |
} |
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 |
src/main/java/eu/etaxonomy/cdm/vaadin/component/registration/RegistrationStyles.java | ||
---|---|---|
21 | 21 |
|
22 | 22 |
public static final String BUTTON_BADGE = "button-badge"; |
23 | 23 |
|
24 |
public static final String HELPER_FIELD = "helper-field"; |
|
25 |
|
|
24 | 26 |
|
25 | 27 |
} |
src/main/java/eu/etaxonomy/cdm/vaadin/util/converter/JodaTimePartialConverter.java | ||
---|---|---|
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.util.converter; |
|
10 |
|
|
11 |
import java.util.Locale; |
|
12 |
import java.util.regex.Matcher; |
|
13 |
import java.util.regex.Pattern; |
|
14 |
|
|
15 |
import org.apache.commons.lang.StringUtils; |
|
16 |
import org.joda.time.DateTimeFieldType; |
|
17 |
import org.joda.time.Partial; |
|
18 |
|
|
19 |
import com.vaadin.data.util.converter.Converter; |
|
20 |
|
|
21 |
|
|
22 |
/** |
|
23 |
* @author a.kohlbecker |
|
24 |
* @since Apr 7, 2017 |
|
25 |
* |
|
26 |
*/ |
|
27 |
public class JodaTimePartialConverter implements Converter<String, Partial> { |
|
28 |
|
|
29 |
private static final long serialVersionUID = 976413549472527584L; |
|
30 |
|
|
31 |
static final String GLUE = "-"; |
|
32 |
|
|
33 |
Pattern partialPattern = Pattern.compile("^(?<year>(?:[1,2][7,8,9,0,1])?[0-9]{2})(?:-(?<month>[0-1]?[0-9])(?:-(?<day>[0-3]?[0-9]))?)?$"); |
|
34 |
|
|
35 |
/** |
|
36 |
* |
|
37 |
*/ |
|
38 |
public JodaTimePartialConverter() { |
|
39 |
super(); |
|
40 |
} |
|
41 |
|
|
42 |
/** |
|
43 |
* {@inheritDoc} |
|
44 |
*/ |
|
45 |
@Override |
|
46 |
public Partial convertToModel(String value, Class<? extends Partial> targetType, Locale locale) |
|
47 |
throws com.vaadin.data.util.converter.Converter.ConversionException { |
|
48 |
Partial partial = null; |
|
49 |
if(value != null){ |
|
50 |
partial = new Partial(); |
|
51 |
Matcher m = partialPattern.matcher(value); |
|
52 |
if(m.matches()){ |
|
53 |
try { |
|
54 |
try { |
|
55 |
partial.with(DateTimeFieldType.year(), Integer.parseInt(m.group("year"))); |
|
56 |
} catch (IllegalArgumentException e) { |
|
57 |
// a valid year should be present here |
|
58 |
throw new ConversionException(e); |
|
59 |
} |
|
60 |
try { |
|
61 |
partial.with(DateTimeFieldType.monthOfYear(), Integer.parseInt(m.group("month"))); |
|
62 |
try { |
|
63 |
partial.with(DateTimeFieldType.dayOfMonth(), Integer.parseInt(m.group("day"))); |
|
64 |
} catch (IllegalArgumentException e) { |
|
65 |
/* IGNORE days are not required */ |
|
66 |
} |
|
67 |
} catch (IllegalArgumentException e) { |
|
68 |
/* IGNORE months are not required */ |
|
69 |
} |
|
70 |
} catch (NumberFormatException ne) { |
|
71 |
// all numbers should be parsable, this is guaranteed by the partialPattern |
|
72 |
throw new ConversionException(ne); |
|
73 |
} |
|
74 |
} |
|
75 |
} |
|
76 |
return partial; |
|
77 |
} |
|
78 |
|
|
79 |
/** |
|
80 |
* {@inheritDoc} |
|
81 |
*/ |
|
82 |
@Override |
|
83 |
public String convertToPresentation(Partial value, Class<? extends String> targetType, Locale locale) |
|
84 |
throws com.vaadin.data.util.converter.Converter.ConversionException { |
|
85 |
StringBuffer sb = new StringBuffer(); |
|
86 |
if(value != null){ |
|
87 |
try { |
|
88 |
sb.append(value.get(DateTimeFieldType.year())); |
|
89 |
try { |
|
90 |
sb.append(GLUE).append(StringUtils.leftPad(Integer.toString((value.get(DateTimeFieldType.monthOfYear()))), 2, "0")); |
|
91 |
try { |
|
92 |
sb.append(GLUE).append(StringUtils.leftPad(Integer.toString((value.get(DateTimeFieldType.dayOfMonth()))), 2, "0")); |
|
93 |
} catch (IllegalArgumentException e){ |
|
94 |
/* IGNORE */ |
|
95 |
} |
|
96 |
} catch (IllegalArgumentException e){ |
|
97 |
/* IGNORE */ |
|
98 |
} |
|
99 |
} catch (IllegalArgumentException e){ |
|
100 |
/* IGNORE */ |
|
101 |
} |
|
102 |
} |
|
103 |
return sb.toString(); |
|
104 |
} |
|
105 |
|
|
106 |
/** |
|
107 |
* {@inheritDoc} |
|
108 |
*/ |
|
109 |
@Override |
|
110 |
public Class<Partial> getModelType() { |
|
111 |
return Partial.class; |
|
112 |
} |
|
113 |
|
|
114 |
/** |
|
115 |
* {@inheritDoc} |
|
116 |
*/ |
|
117 |
@Override |
|
118 |
public Class<String> getPresentationType() { |
|
119 |
return String.class; |
|
120 |
} |
|
121 |
|
|
122 |
} |
src/main/java/eu/etaxonomy/vaadin/ui/DevDayWidgetset.gwt.xml | ||
---|---|---|
13 | 13 |
|
14 | 14 |
|
15 | 15 |
|
16 |
<inherits name="org.vaadin.addons.tuningdatefield.widgetset.TuningDateFieldWidgetset" /> |
|
16 |
|
|
17 | 17 |
</module> |
src/main/webapp/VAADIN/themes/edit-valo/custom-fields.scss | ||
---|---|---|
1 | 1 |
// styles for custom fields |
2 | 2 |
|
3 |
// TimePeriodField |
|
4 |
.v-time-period-field { |
|
5 |
.margin-wrapper { |
|
6 |
border: valo-border($border: $v-border, $color: $v-background-color, $strength: 0.7); |
|
7 |
border-radius: $v-border-radius; |
|
8 |
background-color: $v-app-background-color; |
|
9 |
padding: round($v-unit-size / 4); |
|
10 |
} |
|
11 |
} |
|
3 |
body .edit-valo { // increasing specifity to allow overriding the valo default field themes |
|
4 |
|
|
5 |
// TimePeriodField |
|
6 |
.v-time-period-field { |
|
7 |
.margin-wrapper { |
|
8 |
border: valo-border($border: $v-border, $color: $v-background-color, $strength: 0.7); |
|
9 |
border-radius: $v-border-radius; |
|
10 |
background-color: $v-app-background-color; |
|
11 |
padding: round($v-unit-size / 4); |
|
12 |
} |
|
13 |
} |
|
14 |
|
|
15 |
.v-textfield-helper-field { |
|
16 |
@if is-dark-color($v-background-color) { |
|
17 |
$helper-color: lighten($v-background-color, 20%); |
|
18 |
} @else { |
|
19 |
$helper-color: lighten($v-background-color, -20%); |
|
20 |
} |
|
21 |
color: $helper-color; |
|
22 |
background-color: valo-font-color($helper-color); |
|
23 |
border-radius: $v-border-radius; |
|
24 |
} |
|
25 |
} |
src/main/webapp/VAADIN/themes/edit-valo/edit-valo.scss | ||
---|---|---|
135 | 135 |
.v-icon { |
136 | 136 |
display : inline; |
137 | 137 |
} |
138 |
} |
|
138 |
}
|
|
139 | 139 |
|
140 | 140 |
.friendly-foreground { |
141 | 141 |
color: $v-friendly-color; |
Also available in: Unified diff
ref #6169 impoved TimePeriod custom field