001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/osp/tags/sakai_2-4-1/common/api/src/java/org/theospi/portfolio/list/model/ListConfig.java $
003: * $Id: ListConfig.java 18070 2006-11-09 16:11:06Z chmaurer@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.theospi.portfolio.list.model;
021:
022: import java.util.ArrayList;
023: import java.util.HashMap;
024: import java.util.HashSet;
025: import java.util.List;
026: import java.util.Map;
027: import java.util.Set;
028:
029: import org.apache.commons.logging.Log;
030: import org.apache.commons.logging.LogFactory;
031: import org.sakaiproject.metaobj.shared.model.Agent;
032: import org.sakaiproject.metaobj.shared.model.Id;
033:
034: public class ListConfig {
035: protected final transient Log logger = LogFactory
036: .getLog(getClass());
037:
038: private Id id;
039: private Id toolId;
040: private Agent owner;
041: private String title;
042: private List selectedColumns = new ArrayList();
043: private int height;
044: private int rows;
045:
046: // not persisted, used on UI
047: private List columns;
048:
049: public int getHeight() {
050: return height;
051: }
052:
053: public void setHeight(int height) {
054: this .height = height;
055: }
056:
057: public int getRows() {
058: return rows;
059: }
060:
061: public void setRows(int rows) {
062: this .rows = rows;
063: }
064:
065: public List getColumns() {
066: return columns;
067: }
068:
069: public void setColumns(List columns) {
070: this .columns = columns;
071: }
072:
073: public String getTitle() {
074: return title;
075: }
076:
077: public void setTitle(String title) {
078: this .title = title;
079: }
080:
081: public Id getToolId() {
082: return toolId;
083: }
084:
085: public void setToolId(Id toolId) {
086: this .toolId = toolId;
087: }
088:
089: public Agent getOwner() {
090: return owner;
091: }
092:
093: public void setOwner(Agent owner) {
094: this .owner = owner;
095: }
096:
097: public List getSelectedColumns() {
098: return selectedColumns;
099: }
100:
101: public void setSelectedColumns(List selectedColumns) {
102: this .selectedColumns = selectedColumns;
103: }
104:
105: public Map getSelected() {
106: return new ColumnMap(getSelectedColumns());
107: }
108:
109: public Id getId() {
110: return id;
111: }
112:
113: public void setId(Id id) {
114: this .id = id;
115: }
116:
117: private class ColumnMap extends HashMap {
118:
119: private List selectedColumns;
120: private final Column FAKE_COLUMN = new Column("empty", false);
121:
122: /**
123: * Constructs an empty <tt>HashMap</tt> with the default initial capacity
124: * (16) and the default load factor (0.75).
125: */
126: public ColumnMap(List selectedColumns) {
127: this .selectedColumns = selectedColumns;
128: }
129:
130: public Object get(Object indexString) {
131: int index = Integer.parseInt(indexString.toString());
132:
133: if (selectedColumns.size() > index) {
134: return new Column((String) selectedColumns.get(index),
135: true);
136: } else {
137: return FAKE_COLUMN;
138: }
139: }
140:
141: /* (non-Javadoc)
142: * @see java.util.HashMap#entrySet()
143: */
144: public Set entrySet() {
145: Set entries = new HashSet();
146: for (int i = 0; i < this .selectedColumns.size(); i++) {
147: entries.add((Column) get(i));
148: }
149: return entries;
150: }
151:
152: }
153:
154: }
|