01: /**********************************************************************************
02: * $URL:https://source.sakaiproject.org/svn/osp/trunk/common/api-impl/src/java/org/theospi/portfolio/shared/mgt/IdListCustomEditor.java $
03: * $Id:IdListCustomEditor.java 9134 2006-05-08 20:28:42Z chmaurer@iupui.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2005, 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.theospi.portfolio.shared.mgt;
21:
22: import java.beans.PropertyEditorSupport;
23: import java.util.ArrayList;
24: import java.util.Iterator;
25: import java.util.List;
26:
27: import org.apache.commons.logging.Log;
28: import org.apache.commons.logging.LogFactory;
29: import org.sakaiproject.metaobj.shared.mgt.IdManager;
30: import org.sakaiproject.metaobj.shared.model.Id;
31: import org.sakaiproject.metaobj.utils.mvc.intf.TypedPropertyEditor;
32:
33: public class IdListCustomEditor extends PropertyEditorSupport implements
34: TypedPropertyEditor {
35: protected final transient Log logger = LogFactory
36: .getLog(getClass());
37:
38: private IdManager idManager = null;
39:
40: /**
41: * Parse the Date from the given text, using the specified DateFormat.
42: */
43: public void setAsText(String text) throws IllegalArgumentException {
44: if (text == null || text.length() == 0) {
45: setValue(new ArrayList());
46: } else {
47: String[] items = text.split(",");
48: List ids = new ArrayList();
49: for (int i = 0; i < items.length; i++) {
50: ids.add(getIdManager().getId(items[i]));
51: }
52: setValue(ids);
53: }
54: }
55:
56: /**
57: * Format the Date as String, using the specified DateFormat.
58: */
59: public String getAsText() {
60: if (!(getValue() instanceof List))
61: return null;
62:
63: List ids = (List) getValue();
64:
65: StringBuffer sb = new StringBuffer();
66:
67: for (Iterator i = ids.iterator(); i.hasNext();) {
68: Id id = (Id) i.next();
69: sb.append(id.getValue());
70: if (i.hasNext()) {
71: sb.append(',');
72: }
73: }
74:
75: return sb.toString();
76: }
77:
78: public IdManager getIdManager() {
79: return idManager;
80: }
81:
82: public void setIdManager(IdManager idManager) {
83: this .idManager = idManager;
84: }
85:
86: public Class getType() {
87: return List.class;
88: }
89:
90: }
|