View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements. See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership. The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License. You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied. See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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   * @author Michal Bocek
41   * @since 1.0.0
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  	/* (non-Javadoc)
53  	 * @see com.vaadin.ui.FormFieldFactory#createField(com.vaadin.data.Item, java.lang.Object, com.vaadin.ui.Component)
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  }