001: /**********************************************************************************
002: * $URL:https://source.sakaiproject.org/svn/osp/trunk/presentation/tool-lib/src/java/org/theospi/portfolio/presentation/model/impl/PresentationItemCustomEditor.java $
003: * $Id:PresentationItemCustomEditor.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: import java.util.Set;
027:
028: import org.apache.commons.logging.Log;
029: import org.apache.commons.logging.LogFactory;
030: import org.sakaiproject.metaobj.shared.mgt.HomeFactory;
031: import org.sakaiproject.metaobj.shared.mgt.IdManager;
032: import org.sakaiproject.metaobj.utils.mvc.intf.TypedPropertyEditor;
033: import org.theospi.portfolio.presentation.PresentationManager;
034: import org.theospi.portfolio.presentation.model.PresentationItem;
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 PresentationItemCustomEditor extends PropertyEditorSupport
044: implements TypedPropertyEditor {
045: protected final Log logger = LogFactory.getLog(this .getClass());
046: private PresentationManager presentationManager;
047: private IdManager idManager = null;
048: private HomeFactory homeFactory;
049:
050: public void setAsText(String text) throws IllegalArgumentException {
051: if (text == null || text.length() == 0
052: || text.indexOf(".") == -1) {
053: setValue(null);
054: } else {
055: String[] items = text.split(",");
056: Collection presentationItems = new HashSet();
057: for (int i = 0; i < items.length; i++) {
058: PresentationItem item = new PresentationItem();
059: String[] values = items[i].split("\\.");
060: if (values.length != 2)
061: continue;
062: item.setDefinition(getPresentationManager()
063: .getPresentationItemDefinition(
064: getIdManager().getId(values[0])));
065: item.setArtifactId(getIdManager().getId(values[1]));
066: presentationItems.add(item);
067: }
068: setValue(presentationItems);
069: }
070: }
071:
072: public String getAsText() {
073: StringBuffer buffer = new StringBuffer();
074: for (Iterator i = ((Collection) getValue()).iterator(); i
075: .hasNext();) {
076: PresentationItem item = (PresentationItem) i.next();
077: buffer.append(item.getDefinition().getId().getValue() + "."
078: + item.getArtifactId().getValue());
079: }
080: return buffer.toString();
081: }
082:
083: public HomeFactory getHomeFactory() {
084: return homeFactory;
085: }
086:
087: public void setHomeFactory(HomeFactory homeFactory) {
088: this .homeFactory = homeFactory;
089: }
090:
091: public Class getType() {
092: return Set.class;
093: }
094:
095: public PresentationManager getPresentationManager() {
096: return presentationManager;
097: }
098:
099: public void setPresentationManager(
100: PresentationManager presentationManager) {
101: this .presentationManager = presentationManager;
102: }
103:
104: public IdManager getIdManager() {
105: return idManager;
106: }
107:
108: public void setIdManager(IdManager idManager) {
109: this.idManager = idManager;
110: }
111:
112: }
|