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.plugin.database.component;
17  
18  import java.util.ArrayList;
19  import java.util.Iterator;
20  import java.util.List;
21  import java.util.Set;
22  
23  import org.seasar.tuigwaa.database.DataTable;
24  import org.seasar.tuigwaa.database.DataTableFactory;
25  import org.seasar.tuigwaa.database.SelectedColumnDataTableImpl;
26  import org.seasar.tuigwaa.model.common.EntityUtils;
27  import org.seasar.tuigwaa.model.core.TgwAttribute;
28  import org.seasar.tuigwaa.model.core.TgwEntity;
29  import org.seasar.tuigwaa.model.core.impl.FkAttribute;
30  import org.seasar.tuigwaa.model.core.impl.SetAttribute;
31  import org.seasar.tuigwaa.view.SearchFormComponent.SearchKey;
32  
33  import com.isenshi.util.CharUtil;
34  
35  public class ResultDto {
36  
37  	private TgwEntity entity;
38  
39  	private Object searchDto;
40  
41  	private String searchName;
42  	
43  	private List searchKeyList;
44  
45  	private DataTable resultDataTable;
46  
47  	private SetAttribute childAttribute;
48  
49  	private int first;
50  
51  	private int max;
52  
53  	private int rows;
54  
55  	private String path;
56  
57  	private List actionLinks;
58  
59  	private List pages;
60  
61  	private String editActionPath;
62  
63  	public ResultDto(TgwEntity entity, DataTable dataTable) {
64  		this.entity = entity;
65  		this.resultDataTable = dataTable;
66  	}
67  
68  	public int getFirst() {
69  		return first;
70  	}
71  
72  	public void setFirst(int first) {
73  		this.first = first;
74  	}
75  
76  	public int getMax() {
77  		return max;
78  	}
79  
80  	public void setMax(int max) {
81  		this.max = max;
82  	}
83  
84  	public DataTable getResultDataTable() {
85  		return resultDataTable;
86  	}
87  
88  	public void setResultDataTable(DataTable resultDataTable) {
89  		this.resultDataTable = resultDataTable;
90  	}
91  
92  	public TgwAttribute getChildAttribute() {
93  		return childAttribute;
94  	}
95  
96  	public void setChildAttribute(SetAttribute expandAttribute) {
97  		this.childAttribute = expandAttribute;
98  	}
99  
100 	public int getRows() {
101 		return rows;
102 	}
103 
104 	public void setRows(int rows) {
105 		this.rows = rows;
106 	}
107 
108 	public Object getSearchDto() {
109 		return searchDto;
110 	}
111 
112 	public void setSearchDto(Object searchDto) {
113 		this.searchDto = searchDto;
114 	}
115 
116 	public void setEntity(TgwEntity entity) {
117 		this.entity = entity;
118 	}
119 
120 	public TgwEntity getEntity() {
121 		return entity;
122 	}
123 
124 	public void setPath(String path) {
125 		this.path = path;
126 	}
127 
128 	public String getEncodedCurrentPath() {
129 		return CharUtil.urlEncode(path);
130 	}
131 
132 	public String getPath() {
133 		int index = path.indexOf("&first=");
134 		if (index < 0) {
135 			return path;
136 		}
137 		return path.substring(0, index);
138 	}
139 
140 	public List getActionLinks() {
141 		return actionLinks;
142 	}
143 
144 	public void setActionLinks(List actionLinks) {
145 		this.actionLinks = actionLinks;
146 	}
147 
148 	public List getPages() {
149 		return pages;
150 	}
151 
152 	public void setPages(List pages) {
153 		this.pages = pages;
154 	}
155 
156 	public Object getSearchValue(String name) {
157 		return null;
158 		// return EntityUtils.getProperty(searchDto, name);
159 	}
160 
161 	public boolean isChildEntity() {
162 		return childAttribute != null;
163 	}
164 
165 	public DataTable createChildDataTable() {
166 		TgwEntity childEntity = childAttribute.getRefEntity();
167 		Set set = (Set) EntityUtils.getProperty(resultDataTable.getRowObject(),
168 				childAttribute);
169 		DataTable childDataTable = DataTableFactory.create(childEntity, set);
170 
171 		List list = new ArrayList();
172 
173 		for (Iterator i = childEntity.getFieldIterator(); i.hasNext();) {
174 			TgwAttribute attr = (TgwAttribute) i.next();
175 
176 			if (!(attr instanceof FkAttribute)
177 					|| !((FkAttribute) attr).getRefEntity().equals(entity)) {
178 				list.add(attr.getName());
179 			}
180 		}
181 		return new SelectedColumnDataTableImpl(childDataTable, list);
182 	}
183 
184 	public void setEditActionPath(String editActionPath) {
185 		this.editActionPath = editActionPath;
186 	}
187 
188 	public String getEditActionPath() {
189 		return editActionPath;
190 	}
191 
192 	public void setSearchKeyList(List searchKeyList) {
193 		this.searchKeyList = searchKeyList;
194 	}
195 	
196 	public List getSearchKeyList() {
197 		return searchKeyList;
198 	}
199 	
200 	public int getSearchKeySize(){
201 		if(searchKeyList == null){
202 			return 0;
203 		}
204 		int num =0; 
205 		for(Iterator i = searchKeyList.iterator(); i.hasNext();){
206 			SearchKey key = (SearchKey)i.next();
207 			if(key != null && key.getValue() != null){
208 				num ++;
209 			}
210 		}
211 		return num;
212 	}
213 	
214 	public void setSearchName(String searchName) {
215 		this.searchName = searchName;
216 	}
217 	
218 	public String getSearchName() {
219 		return searchName;
220 	}
221 }