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.model.core.impl;
17  
18  import java.util.Collection;
19  import java.util.LinkedHashMap;
20  import java.util.Map;
21  
22  import org.seasar.tuigwaa.database.DataRow;
23  import org.seasar.tuigwaa.database.DataTable;
24  import org.seasar.tuigwaa.model.common.DataServiceUtils;
25  import org.seasar.tuigwaa.system.Constants;
26  
27  public abstract class AbstractLinkAttribute extends AbstractAttribute implements
28  		LinkAttribute {
29  
30  	private String refEntityFilter;
31  
32  	public void setRefEntityFilter(String refEntityFilter) {
33  		this.refEntityFilter = refEntityFilter;
34  	}
35  
36  	public String getRefEntityFilter() {
37  		return refEntityFilter;
38  	}
39  
40  	public DataTable getDataTable() {
41  		return DataServiceUtils.getDataTable(getRefEntity(), refEntityFilter);
42  	}
43  
44  	public Collection getDataList() {
45  		return getDataTable().getDataList();
46  	}
47  
48  	/***
49  	 * 指定したモデル(テーブル)にある、各データの代表カラムの表示名と ID(主キー)の値を返す
50  	 */
51  	public Map getLabelValueMap() {
52  		DataTable table = getDataTable();
53  		Map map = new LinkedHashMap();
54  		while (table.hasNext()) {
55  			DataRow row = (DataRow) table.next();
56  
57  			String repre = getRefEntity().getRepresentativeField();
58  			if (repre == null) {
59  				repre = getRefEntity().getFirstField().getName();
60  			}
61  			String label = "" + row.getCell(repre);
62  			Long id = (Long) row.getCell(Constants.ENTITY_BUILTIN_ID);
63  			String value = String.valueOf(id);
64  			map.put(label, value);
65  		}
66  		return map;
67  	}
68  
69  	
70  }