1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package com.tapas.evidence.fe.teacher;
20
21 import java.util.List;
22 import java.util.Locale;
23
24 import lombok.extern.slf4j.Slf4j;
25
26 import org.vaadin.mvp.uibinder.IUiMessageSource;
27
28 import com.tapas.evidence.dto.StateDTO;
29 import com.tapas.evidence.fe.form.EvidenceFormFieldFactory;
30 import com.tapas.evidence.service.ServiceHolder;
31 import com.vaadin.data.Item;
32 import com.vaadin.terminal.Sizeable;
33 import com.vaadin.ui.Component;
34 import com.vaadin.ui.DateField;
35 import com.vaadin.ui.Field;
36 import com.vaadin.ui.Select;
37 import com.vaadin.ui.TextField;
38
39
40
41
42
43 @Slf4j
44 public class TeacherDetailFormFieldFactory extends EvidenceFormFieldFactory {
45
46 private static final long serialVersionUID = 1L;
47
48 public TeacherDetailFormFieldFactory(final IUiMessageSource messageSource, final Locale locale) {
49 super(messageSource, locale);
50 }
51
52
53
54
55 @Override
56 public Field createField(final Item item, final Object propertyId, final Component uiContext) {
57 log.debug("Item: {}; Property id: {}; Componet: {}", new Object[] {item, propertyId, uiContext});
58 Field field = null;
59 final String pid = (String) propertyId;
60 if ("contact.address.stateCode".equals(pid)) {
61 final Select select = new Select(pid);
62 final List<StateDTO> states = ServiceHolder.getInstance().getCodeListService().getStates();
63 for (StateDTO stateDTO : states) {
64 select.addItem(stateDTO.getCode());
65 select.setItemCaption(stateDTO.getCode(), stateDTO.getName());
66 }
67 select.setNewItemsAllowed(false);
68 select.setNullSelectionAllowed(false);
69 select.setWidth(100, Sizeable.UNITS_PERCENTAGE);
70 field = select;
71 } else if ("birthDate".equals(pid)) {
72 field = super.createField(item, propertyId, uiContext);
73 ((DateField)field).setDateFormat(this.getMessage("date.format"));
74 field.setWidth(100, Sizeable.UNITS_PERCENTAGE);
75 } else if ("photo".equals(pid)) {
76 } else {
77 field = super.createField(item, propertyId, uiContext);
78 if (field instanceof TextField) {
79 field.setWidth(100, Sizeable.UNITS_PERCENTAGE);
80 }
81 }
82 return field;
83 }
84
85 }