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.responsible;
20  
21  import java.util.List;
22  import java.util.Locale;
23  
24  import org.vaadin.mvp.uibinder.IUiMessageSource;
25  
26  import com.tapas.evidence.dto.StateDTO;
27  import com.tapas.evidence.entity.ResponsibilityType;
28  import com.tapas.evidence.fe.form.EvidenceFormFieldFactory;
29  import com.tapas.evidence.service.ServiceHolder;
30  import com.tapas.evidence.utility.KeyBuilder;
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  public class ResponsiblePersonDetailFormFieldFactory extends EvidenceFormFieldFactory {
44  
45  	private static final long serialVersionUID = 1L;
46  
47  	public ResponsiblePersonDetailFormFieldFactory(final IUiMessageSource messageSource, final Locale locale) {
48  		super(messageSource, locale);
49  	}
50  
51  	/* (non-Javadoc)
52  	 * @see com.vaadin.ui.FormFieldFactory#createField(com.vaadin.data.Item, java.lang.Object, com.vaadin.ui.Component)
53  	 */
54  	@Override
55  	public Field createField(final Item item, final Object propertyId, final Component uiContext) {
56  		Field field = null;
57  		final String pid = (String) propertyId;
58  		if ("contact.address.stateCode".equals(pid)) {
59  			final Select select = new Select(pid);
60  			final List<StateDTO> states = ServiceHolder.getInstance().getCodeListService().getStates();
61  			for (StateDTO stateDTO : states) {
62  				select.addItem(stateDTO.getCode());
63  				select.setItemCaption(stateDTO.getCode(), stateDTO.getName());
64  			}
65  			select.setNewItemsAllowed(false);
66  			select.setNullSelectionAllowed(false);
67  			select.setWidth(100, Sizeable.UNITS_PERCENTAGE);
68  			field = select;
69  		} else if ("type".equals(pid)) {
70  			final Select select = new Select(pid);
71  			for (ResponsibilityType type : ResponsibilityType.values()) {
72  				select.addItem(type.name());
73  				select.setItemCaption(type.name(), getMessage(new KeyBuilder(ResponsibilityType.key, type.name()).getKey()));
74  			}
75  			select.setNewItemsAllowed(false);
76  			select.setNullSelectionAllowed(false);
77  			select.setWidth(100, Sizeable.UNITS_PERCENTAGE);
78  			field = select;
79  		} else if ("birthDate".equals(pid)) {
80  			field = super.createField(item, propertyId, uiContext);
81  			field.setWidth(100, Sizeable.UNITS_PERCENTAGE);
82  			((DateField)field).setDateFormat(this.getMessage("date.format"));
83  		} else if ("photo".equals(pid)) {
84  		} else {
85  			field = super.createField(item, propertyId, uiContext);
86  			if ( field instanceof TextField) {
87  				field.setWidth(100, Sizeable.UNITS_PERCENTAGE);
88  			}
89  		}
90  		return field;
91  	}
92  
93  }