Revision 6d715f66
Added by Andreas Kohlbecker almost 7 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/util/JodaDateTimeConverter.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; |
|
10 |
|
|
11 |
import java.util.Date; |
|
12 |
import java.util.Locale; |
|
13 |
|
|
14 |
import org.joda.time.DateTime; |
|
15 |
|
|
16 |
import com.vaadin.data.util.converter.Converter; |
|
17 |
|
|
18 |
/** |
|
19 |
* @author a.kohlbecker |
|
20 |
* @since Mar 7, 2017 |
|
21 |
* |
|
22 |
*/ |
|
23 |
public final class JodaDateTimeConverter implements Converter<Date, DateTime> { |
|
24 |
@Override |
|
25 |
public DateTime convertToModel(Date value, Class<? extends DateTime> targetType, Locale locale) |
|
26 |
throws com.vaadin.data.util.converter.Converter.ConversionException { |
|
27 |
DateTime dateTime = null; |
|
28 |
if(value != null) { |
|
29 |
try { |
|
30 |
dateTime = new DateTime(value); |
|
31 |
} catch (IllegalArgumentException e) { |
|
32 |
throw new ConversionException(e); |
|
33 |
} |
|
34 |
} |
|
35 |
return dateTime; |
|
36 |
} |
|
37 |
|
|
38 |
@Override |
|
39 |
public Date convertToPresentation(DateTime value, Class<? extends Date> targetType, Locale locale) |
|
40 |
throws com.vaadin.data.util.converter.Converter.ConversionException { |
|
41 |
Date date = null; |
|
42 |
if(value != null){ |
|
43 |
date = value.toDate(); |
|
44 |
} |
|
45 |
return date; |
|
46 |
} |
|
47 |
|
|
48 |
@Override |
|
49 |
public Class<DateTime> getModelType() { |
|
50 |
return DateTime.class; |
|
51 |
} |
|
52 |
|
|
53 |
@Override |
|
54 |
public Class<Date> getPresentationType() { |
|
55 |
return Date.class; |
|
56 |
} |
|
57 |
} |
src/main/java/eu/etaxonomy/cdm/vaadin/util/UrlStringConverter.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; |
|
10 |
|
|
11 |
import java.util.Locale; |
|
12 |
|
|
13 |
import com.vaadin.data.util.converter.Converter; |
|
14 |
|
|
15 |
/** |
|
16 |
* Creates a link from the values in the column. |
|
17 |
* |
|
18 |
* @author a.kohlbecker |
|
19 |
* @since Mar 7, 2017 |
|
20 |
* |
|
21 |
*/ |
|
22 |
public final class UrlStringConverter implements Converter<String, String> { |
|
23 |
|
|
24 |
private String regex = null; |
|
25 |
private String replacement = ""; |
|
26 |
|
|
27 |
public UrlStringConverter() { |
|
28 |
|
|
29 |
} |
|
30 |
|
|
31 |
/** |
|
32 |
* @param regex Regular expression for creating an alternative label by string replacement on the value. |
|
33 |
* This is optional. No string replacement will be done when this is <code>null</code>. |
|
34 |
*/ |
|
35 |
public UrlStringConverter(String regex) { |
|
36 |
this(regex, null); |
|
37 |
} |
|
38 |
|
|
39 |
/** |
|
40 |
* @param regex Regular expression for creating an alternative label by string replacement on the value. |
|
41 |
* This is optional. No string replacement will be done when this is <code>null</code>. |
|
42 |
* @param replacement The replacement to be used with the <code>regex</code>. |
|
43 |
* Defaults to an empty string when null. |
|
44 |
*/ |
|
45 |
public UrlStringConverter(String regex, String replacement) { |
|
46 |
this.regex = regex; |
|
47 |
if(replacement != null){ |
|
48 |
this.replacement = replacement; |
|
49 |
} |
|
50 |
} |
|
51 |
|
|
52 |
@Override |
|
53 |
public String convertToModel(String value, Class<? extends String> targetType, Locale locale) |
|
54 |
throws com.vaadin.data.util.converter.Converter.ConversionException { |
|
55 |
return null; |
|
56 |
} |
|
57 |
|
|
58 |
@Override |
|
59 |
public String convertToPresentation(String value, Class<? extends String> targetType, Locale locale) |
|
60 |
throws com.vaadin.data.util.converter.Converter.ConversionException { |
|
61 |
String label = value; |
|
62 |
if(regex != null){ |
|
63 |
label = label.replace(regex, replacement); |
|
64 |
} |
|
65 |
return "<a href=\"" + value + "\" target=\"external\">" + label + "</a>"; |
|
66 |
} |
|
67 |
|
|
68 |
@Override |
|
69 |
public Class<String> getModelType() { |
|
70 |
return String.class; |
|
71 |
} |
|
72 |
|
|
73 |
@Override |
|
74 |
public Class<String> getPresentationType() { |
|
75 |
return String.class; |
|
76 |
} |
|
77 |
} |
src/main/java/eu/etaxonomy/cdm/vaadin/util/converter/JodaDateTimeConverter.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.Date; |
|
12 |
import java.util.Locale; |
|
13 |
|
|
14 |
import org.joda.time.DateTime; |
|
15 |
|
|
16 |
import com.vaadin.data.util.converter.Converter; |
|
17 |
|
|
18 |
/** |
|
19 |
* @author a.kohlbecker |
|
20 |
* @since Mar 7, 2017 |
|
21 |
* |
|
22 |
*/ |
|
23 |
public final class JodaDateTimeConverter implements Converter<Date, DateTime> { |
|
24 |
@Override |
|
25 |
public DateTime convertToModel(Date value, Class<? extends DateTime> targetType, Locale locale) |
|
26 |
throws com.vaadin.data.util.converter.Converter.ConversionException { |
|
27 |
DateTime dateTime = null; |
|
28 |
if(value != null) { |
|
29 |
try { |
|
30 |
dateTime = new DateTime(value); |
|
31 |
} catch (IllegalArgumentException e) { |
|
32 |
throw new ConversionException(e); |
|
33 |
} |
|
34 |
} |
|
35 |
return dateTime; |
|
36 |
} |
|
37 |
|
|
38 |
@Override |
|
39 |
public Date convertToPresentation(DateTime value, Class<? extends Date> targetType, Locale locale) |
|
40 |
throws com.vaadin.data.util.converter.Converter.ConversionException { |
|
41 |
Date date = null; |
|
42 |
if(value != null){ |
|
43 |
date = value.toDate(); |
|
44 |
} |
|
45 |
return date; |
|
46 |
} |
|
47 |
|
|
48 |
@Override |
|
49 |
public Class<DateTime> getModelType() { |
|
50 |
return DateTime.class; |
|
51 |
} |
|
52 |
|
|
53 |
@Override |
|
54 |
public Class<Date> getPresentationType() { |
|
55 |
return Date.class; |
|
56 |
} |
|
57 |
} |
src/main/java/eu/etaxonomy/cdm/vaadin/util/converter/UrlStringConverter.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 |
|
|
13 |
import com.vaadin.data.util.converter.Converter; |
|
14 |
|
|
15 |
/** |
|
16 |
* Creates a link from the values in the column. |
|
17 |
* |
|
18 |
* @author a.kohlbecker |
|
19 |
* @since Mar 7, 2017 |
|
20 |
* |
|
21 |
*/ |
|
22 |
public final class UrlStringConverter implements Converter<String, String> { |
|
23 |
|
|
24 |
private String regex = null; |
|
25 |
private String replacement = ""; |
|
26 |
|
|
27 |
public UrlStringConverter() { |
|
28 |
|
|
29 |
} |
|
30 |
|
|
31 |
/** |
|
32 |
* @param regex Regular expression for creating an alternative label by string replacement on the value. |
|
33 |
* This is optional. No string replacement will be done when this is <code>null</code>. |
|
34 |
*/ |
|
35 |
public UrlStringConverter(String regex) { |
|
36 |
this(regex, null); |
|
37 |
} |
|
38 |
|
|
39 |
/** |
|
40 |
* @param regex Regular expression for creating an alternative label by string replacement on the value. |
|
41 |
* This is optional. No string replacement will be done when this is <code>null</code>. |
|
42 |
* @param replacement The replacement to be used with the <code>regex</code>. |
|
43 |
* Defaults to an empty string when null. |
|
44 |
*/ |
|
45 |
public UrlStringConverter(String regex, String replacement) { |
|
46 |
this.regex = regex; |
|
47 |
if(replacement != null){ |
|
48 |
this.replacement = replacement; |
|
49 |
} |
|
50 |
} |
|
51 |
|
|
52 |
@Override |
|
53 |
public String convertToModel(String value, Class<? extends String> targetType, Locale locale) |
|
54 |
throws com.vaadin.data.util.converter.Converter.ConversionException { |
|
55 |
return null; |
|
56 |
} |
|
57 |
|
|
58 |
@Override |
|
59 |
public String convertToPresentation(String value, Class<? extends String> targetType, Locale locale) |
|
60 |
throws com.vaadin.data.util.converter.Converter.ConversionException { |
|
61 |
String label = value; |
|
62 |
if(regex != null){ |
|
63 |
label = label.replace(regex, replacement); |
|
64 |
} |
|
65 |
return "<a href=\"" + value + "\" target=\"external\">" + label + "</a>"; |
|
66 |
} |
|
67 |
|
|
68 |
@Override |
|
69 |
public Class<String> getModelType() { |
|
70 |
return String.class; |
|
71 |
} |
|
72 |
|
|
73 |
@Override |
|
74 |
public Class<String> getPresentationType() { |
|
75 |
return String.class; |
|
76 |
} |
|
77 |
} |
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/ListViewBean.java | ||
---|---|---|
36 | 36 |
import com.vaadin.ui.renderers.HtmlRenderer; |
37 | 37 |
|
38 | 38 |
import eu.etaxonomy.cdm.vaadin.component.registration.RegistrationItem; |
39 |
import eu.etaxonomy.cdm.vaadin.util.JodaDateTimeConverter; |
|
40 |
import eu.etaxonomy.cdm.vaadin.util.UrlStringConverter; |
|
39 |
import eu.etaxonomy.cdm.vaadin.util.converter.JodaDateTimeConverter;
|
|
40 |
import eu.etaxonomy.cdm.vaadin.util.converter.UrlStringConverter;
|
|
41 | 41 |
import eu.etaxonomy.cdm.vaadin.view.AbstractPageView; |
42 | 42 |
import eu.etaxonomy.vaadin.ui.navigation.NavigationEvent; |
43 | 43 |
|
Also available in: Unified diff
moving vaadin data converter to sub package