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.controller;
17  
18  import java.util.Collection;
19  import java.util.Iterator;
20  
21  import org.seasar.tuigwaa.database.CriteriaFunctionFactory;
22  import org.seasar.tuigwaa.database.function.SearchExeFunction;
23  import org.seasar.tuigwaa.database.function.criteria.AbstractCriteriaFunction;
24  import org.seasar.tuigwaa.database.function.criteria.CriteriaFunction;
25  import org.seasar.tuigwaa.database.function.criteria.CriteriaListFunction;
26  import org.seasar.tuigwaa.model.core.TgwAttribute;
27  import org.seasar.tuigwaa.model.core.TgwEntity;
28  
29  import com.isenshi.util.UniqueNameGenerator;
30  
31  /***
32   * 検索フォームを作成するフォームに対応
33   * 
34   * @author someda
35   */
36  public class SearchFormForm extends AbstractFieldFilterForm {
37  
38  	private static final long serialVersionUID = 4803260749258255581L;
39  
40  	public SearchFormForm(TgwEntity entity) {
41  		setEntity(entity);
42  	}
43  
44  	public SearchFormForm(TgwEntity entity, SearchExeFunction function) {
45  		setEntity(entity);
46  		setName(function.getName());
47  		setFunctions(function.getCriteriaListFunction());
48  	}
49  
50  	private void setFunctions(CriteriaListFunction listFunction) {
51  		Collection list = listFunction.getFunctionList();
52  		Iterator itr = list.iterator();
53  		while (itr.hasNext()) {
54  			AbstractCriteriaFunction f = (AbstractCriteriaFunction) itr.next();
55  			addRow(createFieldForm(getEntity().getField(f.getField()), f.getName(),
56  					false));
57  		}
58  
59  	}
60  
61  	protected void removeRow(int index, Object row) {
62  	}
63  
64  	protected Object createNewRow() {
65  		TgwAttribute field = getEntity().getFirstNotFkField();
66  		String fieldName = getEntity().getFirstNotFkFieldName();
67  		return createFieldForm(field, fieldName, false);
68  	}
69  
70  	protected Object createRow(int index, String value) {
71  		String fieldName = value;
72  		TgwAttribute field = getEntity().getField(fieldName);
73  		return createFieldForm(field, fieldName, false);
74  	}
75  
76  	protected String[] getHtmlData(int index, Object row) {
77  		FieldForm fieldForm = (FieldForm) row;
78  		return fieldForm.getHtmlData(index);
79  	}
80  
81  	public SearchExeFunction getSearchExeFunction() {
82  		CriteriaListFunction function = createCriteriaListFunction();
83  		SearchExeFunction exe = CriteriaFunctionFactory
84  				.createSearchExeFunction(getEntity(), getName(), function);
85  		return exe;
86  	}
87  
88  	private CriteriaListFunction createCriteriaListFunction() {
89  		CriteriaListFunction functionList = new CriteriaListFunction();
90  		UniqueNameGenerator generator = new UniqueNameGenerator();
91  
92  		functionList.setDisjunction(isDisjunction());
93  
94  		for (Iterator itr = getRowSet().iterator(); itr.hasNext();) {
95  			FieldForm form = (FieldForm) itr.next();
96  			String fieldName = form.getFieldName();
97  			CriteriaFunction critariFunction = getFunction(form.getType(),
98  					getEntity(), fieldName);
99  			fieldName = fieldName.replaceAll("//.", "");
100 			critariFunction.setName(generator.nextUniqueName(fieldName));
101 			functionList.addFunction(critariFunction);
102 		}
103 		return functionList;
104 	}
105 }