View Javadoc

1   /*
2    * Copyright 2004-2006 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.tuigwaa.view;
17  
18  import java.util.ArrayList;
19  import java.util.Iterator;
20  import java.util.List;
21  
22  import org.seasar.tuigwaa.database.function.UpdateExeFunction;
23  import org.seasar.tuigwaa.model.core.TgwAttribute;
24  import org.seasar.tuigwaa.model.core.TgwEntity;
25  
26  public class CustomFormComponent extends EntityFormComponent {
27  
28  	private UpdateExeFunction updateExe;
29  
30  	public CustomFormComponent(String javascript, TgwEntity entity,
31  			Object object, UpdateExeFunction updateExe) {
32  		super(javascript, entity, object);
33  		this.updateExe = updateExe;
34  	}
35  
36  	public String getCustomFormName() {
37  		return updateExe.getName();
38  	}
39  
40  	public String getName() {
41  		return updateExe.getName();
42  	}
43  
44  	public List getFormElements() {
45  		List list = new ArrayList();
46  		Iterator itr = getEntity().getFieldIterator();
47  		while (itr.hasNext()) {
48  			TgwAttribute field = (TgwAttribute) itr.next();
49  			String fieldName = field.getName();
50  			if (needAttribute(fieldName)) {
51  				FormElement elem = createFormElement(field);
52  				if (elem != null) {
53  					list.add(elem);
54  				}
55  				String hidden = createExtraHidden(field);
56  				addExtraHidden(hidden);
57  			}
58  		}
59  		return list;
60  	}
61  
62  	private boolean needAttribute(String attrName) {
63  		return updateExe.getDtoFieldList().contains(attrName);
64  	}
65  
66  	protected FormElement getRowElement(TgwAttribute attr) {
67  		if (needAttribute(attr.getName())) {
68  			return createFormElement(attr);
69  		} else {
70  			// Object obj = EntityUtils.getProperty(getValueObject(), attr);
71  			Object obj = DataViewUtils.getTableData(getValueObject(), attr);
72  			return new FormElement(attr.getName(), null, attr.getDisplayName(),
73  					String.valueOf(obj), false, "");
74  		}
75  	}
76  }