01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/metaobj/tags/sakai_2-4-1/metaobj-util/tool-lib/src/java/org/sakaiproject/metaobj/shared/mgt/IdListCustomEditor.java $
03: * $Id: IdListCustomEditor.java 14230 2006-09-05 18:02:51Z chmaurer@iupui.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2004, 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.sakaiproject.metaobj.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.model.Id;
30: import org.sakaiproject.metaobj.utils.mvc.intf.TypedPropertyEditor;
31:
32: public class IdListCustomEditor extends PropertyEditorSupport implements
33: TypedPropertyEditor {
34: protected final transient Log logger = LogFactory
35: .getLog(getClass());
36:
37: private IdManager idManager = null;
38:
39: /**
40: * Parse the Date from the given text, using the specified DateFormat.
41: */
42: public void setAsText(String text) throws IllegalArgumentException {
43: if (text == null || text.length() == 0) {
44: setValue(new ArrayList());
45: } else {
46: String[] items = text.split(",");
47: List ids = new ArrayList();
48: for (int i = 0; i < items.length; i++) {
49: ids.add(getIdManager().getId(items[i]));
50: }
51: setValue(ids);
52: }
53: }
54:
55: /**
56: * Format the Date as String, using the specified DateFormat.
57: */
58: public String getAsText() {
59: if (!(getValue() instanceof List)) {
60: return null;
61: }
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: }
|