001: /**********************************************************************************
002: * $URL:https://source.sakaiproject.org/svn/osp/trunk/presentation/tool-lib/src/java/org/theospi/portfolio/presentation/model/impl/PresentationViewerCustomEditor.java $
003: * $Id:PresentationViewerCustomEditor.java 9134 2006-05-08 20:28:42Z 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.presentation.model.impl;
021:
022: import java.beans.PropertyEditorSupport;
023: import java.util.Collection;
024: import java.util.HashSet;
025: import java.util.Iterator;
026:
027: import org.apache.commons.logging.Log;
028: import org.apache.commons.logging.LogFactory;
029: import org.sakaiproject.metaobj.shared.mgt.AgentManager;
030: import org.sakaiproject.metaobj.shared.mgt.IdManager;
031: import org.sakaiproject.metaobj.shared.model.Agent;
032: import org.sakaiproject.metaobj.shared.model.impl.AgentImpl;
033: import org.sakaiproject.metaobj.utils.mvc.intf.TypedPropertyEditor;
034: import org.theospi.portfolio.presentation.PresentationManager;
035:
036: /**
037: * Created by IntelliJ IDEA.
038: * User: John Ellis
039: * Date: May 19, 2004
040: * Time: 2:23:28 PM
041: * To change this template use File | Settings | File Templates.
042: */
043: public class PresentationViewerCustomEditor extends
044: PropertyEditorSupport implements TypedPropertyEditor {
045: protected final Log logger = LogFactory.getLog(this .getClass());
046: private PresentationManager presentationManager;
047: private IdManager idManager = null;
048: private AgentManager agentManager;
049:
050: public void setAsText(String text) throws IllegalArgumentException {
051: if (text == null || text.length() == 0) {
052: setValue(new HashSet());
053: } else {
054: String[] items = text.split(",");
055: Collection viewers = new HashSet();
056:
057: for (int i = 0; i < items.length; i++) {
058: Agent agent = getAgentManager().getAgent(items[i]);
059: if (agent == null) {
060: agent = createGuest(items[i]);
061: }
062: viewers.add(agent);
063: }
064: setValue(viewers);
065: }
066: }
067:
068: protected Agent createGuest(String item) {
069: AgentImpl viewer = new AgentImpl();
070: viewer.setDisplayName(item);
071: viewer.setRole(Agent.ROLE_GUEST);
072: viewer.setId(getIdManager().getId(viewer.getDisplayName()));
073: return viewer;
074: }
075:
076: public String getAsText() {
077: StringBuffer buffer = new StringBuffer();
078: for (Iterator i = ((Collection) getValue()).iterator(); i
079: .hasNext();) {
080: Agent agent = (Agent) i.next();
081: buffer.append(agent.getId().getValue());
082: }
083: return buffer.toString();
084: }
085:
086: public AgentManager getAgentManager() {
087: return agentManager;
088: }
089:
090: public void setAgentManager(AgentManager agentManager) {
091: this .agentManager = agentManager;
092: }
093:
094: public Class getType() {
095: return Collection.class;
096: }
097:
098: public PresentationManager getPresentationManager() {
099: return presentationManager;
100: }
101:
102: public void setPresentationManager(
103: PresentationManager presentationManager) {
104: this .presentationManager = presentationManager;
105: }
106:
107: public IdManager getIdManager() {
108: return idManager;
109: }
110:
111: public void setIdManager(IdManager idManager) {
112: this.idManager = idManager;
113: }
114:
115: }
|