Revision 931fe3c9
Added by Andreas Kohlbecker over 5 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/util/converter/DoiConverter.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 org.apache.commons.lang3.StringUtils; |
|
14 |
|
|
15 |
import com.vaadin.data.util.converter.Converter; |
|
16 |
|
|
17 |
import eu.etaxonomy.cdm.common.DOI; |
|
18 |
|
|
19 |
/** |
|
20 |
* Creates a link from the values in the column. |
|
21 |
* |
|
22 |
* @author a.kohlbecker |
|
23 |
* @since Mar 7, 2017 |
|
24 |
* |
|
25 |
*/ |
|
26 |
public final class DoiConverter implements Converter<String, DOI> { |
|
27 |
|
|
28 |
private static final long serialVersionUID = -6695362724769275484L; |
|
29 |
|
|
30 |
public DoiConverter() { |
|
31 |
|
|
32 |
} |
|
33 |
|
|
34 |
|
|
35 |
@Override |
|
36 |
public Class<DOI> getModelType() { |
|
37 |
return DOI.class; |
|
38 |
} |
|
39 |
|
|
40 |
@Override |
|
41 |
public Class<String> getPresentationType() { |
|
42 |
return String.class; |
|
43 |
} |
|
44 |
|
|
45 |
|
|
46 |
/** |
|
47 |
* {@inheritDoc} |
|
48 |
*/ |
|
49 |
@Override |
|
50 |
public DOI convertToModel(String value, Class<? extends DOI> targetType, Locale locale) |
|
51 |
throws com.vaadin.data.util.converter.Converter.ConversionException { |
|
52 |
if(StringUtils.isNoneEmpty(value)){ |
|
53 |
try{ |
|
54 |
DOI doi = DOI.fromString(value); |
|
55 |
return doi; |
|
56 |
} catch (Exception e){ |
|
57 |
throw new com.vaadin.data.util.converter.Converter.ConversionException(e); |
|
58 |
} |
|
59 |
} |
|
60 |
return null; |
|
61 |
} |
|
62 |
|
|
63 |
|
|
64 |
/** |
|
65 |
* {@inheritDoc} |
|
66 |
*/ |
|
67 |
@Override |
|
68 |
public String convertToPresentation(DOI value, Class<? extends String> targetType, Locale locale) |
|
69 |
throws com.vaadin.data.util.converter.Converter.ConversionException { |
|
70 |
if(value != null){ |
|
71 |
try{ |
|
72 |
return value.toString(); |
|
73 |
} catch (Exception e){ |
|
74 |
throw new com.vaadin.data.util.converter.Converter.ConversionException(e); |
|
75 |
} |
|
76 |
} |
|
77 |
return null; |
|
78 |
} |
|
79 |
} |
src/main/java/eu/etaxonomy/cdm/vaadin/view/reference/ReferencePopupEditor.java | ||
---|---|---|
20 | 20 |
|
21 | 21 |
import eu.etaxonomy.cdm.model.reference.Reference; |
22 | 22 |
import eu.etaxonomy.cdm.model.reference.ReferenceType; |
23 |
import eu.etaxonomy.cdm.vaadin.component.TextFieldNFix; |
|
23 | 24 |
import eu.etaxonomy.cdm.vaadin.component.common.TeamOrPersonField; |
24 | 25 |
import eu.etaxonomy.cdm.vaadin.component.common.TimePeriodField; |
25 | 26 |
import eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction; |
26 | 27 |
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction; |
27 | 28 |
import eu.etaxonomy.cdm.vaadin.security.AccessRestrictedView; |
29 |
import eu.etaxonomy.cdm.vaadin.util.converter.DoiConverter; |
|
30 |
import eu.etaxonomy.cdm.vaadin.util.converter.UriConverter; |
|
28 | 31 |
import eu.etaxonomy.vaadin.component.SwitchableTextField; |
29 | 32 |
import eu.etaxonomy.vaadin.component.ToOneRelatedEntityCombobox; |
30 | 33 |
import eu.etaxonomy.vaadin.mvp.AbstractCdmPopupEditor; |
... | ... | |
148 | 151 |
row++; |
149 | 152 |
addTextField("ISSN", "issn", 0, row); |
150 | 153 |
addTextField("ISBN", "isbn", 1, row); |
151 |
addTextField("DOI", "doi", 2, row); |
|
152 |
addTextField("Uri", "uri", 3, row); |
|
154 |
TextFieldNFix doiField = new TextFieldNFix("DOI"); |
|
155 |
doiField.setConverter(new DoiConverter()); |
|
156 |
addField(doiField, "doi", 2, row); |
|
157 |
TextFieldNFix uriField = new TextFieldNFix("Uri"); |
|
158 |
uriField.setConverter(new UriConverter()); |
|
159 |
addField(uriField, "uri", 3, row); |
|
153 | 160 |
|
154 | 161 |
// titleField.setRequired(true); |
155 | 162 |
// publisherField.setRequired(true); |
Also available in: Unified diff
fix #7187 adding converter for DOI and URI