001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package com.sun.jsfcl.std.property;
042:
043: import java.awt.Component;
044: import java.util.ArrayList;
045: import java.util.Iterator;
046: import java.util.List;
047: import java.util.StringTokenizer;
048: import com.sun.jsfcl.std.reference.ReferenceDataItem;
049:
050: /**
051: * @author eric
052: *
053: * @deprecated
054: */
055: public class ChooseManyOfManyReferenceDataPropertyEditor extends
056: ChooseManyReferenceDataPropertyEditor {
057: protected List valueListOfManyOfManyReferenceDataItems;
058:
059: /**
060: *
061: */
062: public ChooseManyOfManyReferenceDataPropertyEditor() {
063: super ();
064: }
065:
066: public String getAsText() {
067:
068: return getStringForManyOfManyItems(valueListOfManyOfManyReferenceDataItems);
069: }
070:
071: public Component getCustomEditor() {
072:
073: return new ChooseManyOfManyReferenceDataPanel(this ,
074: getDesignProperty());
075: }
076:
077: protected List getManyOfManyItemsForString(String string) {
078: ArrayList result, itemList;
079: StringTokenizer tokenizer;
080: String token;
081: ReferenceDataItem item;
082:
083: result = new ArrayList(16);
084: if (string == null) {
085: return result;
086: }
087: tokenizer = new StringTokenizer(string, " \t\n\r\f,", true);
088: itemList = new ArrayList(16);
089: result.add(itemList);
090: while (tokenizer.hasMoreTokens()) {
091: token = tokenizer.nextToken();
092: token = token.trim();
093: if (token.length() == 0
094: || Character.isWhitespace(token.charAt(0))) {
095: // whitespace token
096: } else if (token.equals(",")) {
097: itemList = new ArrayList(16);
098: result.add(itemList);
099: } else {
100: item = getItemByName(token);
101: itemList.add(item);
102: }
103: }
104: return result;
105: }
106:
107: protected String getStringForManyOfManyItems(List manyOfManyList) {
108: StringBuffer buffer;
109: Iterator manyOfManyIterator, manyIterator;
110: ReferenceDataItem item;
111: List manyItems;
112: String result;
113:
114: if (manyOfManyList == null) {
115: Object value = getDesignProperty().getValue();
116: if (value != null) {
117: return value.toString();
118: } else {
119: return "";
120: }
121: }
122: buffer = new StringBuffer(256);
123: manyOfManyIterator = manyOfManyList.iterator();
124: while (manyOfManyIterator.hasNext()) {
125: manyItems = (List) manyOfManyIterator.next();
126: manyIterator = manyItems.iterator();
127: while (manyIterator.hasNext()) {
128: item = (ReferenceDataItem) manyIterator.next();
129: buffer.append(getStringForItem(item));
130: if (manyIterator.hasNext()) {
131: buffer.append(" ");
132: }
133: }
134: if (manyOfManyIterator.hasNext()) {
135: buffer.append(", ");
136: }
137: }
138: result = buffer.toString();
139: return result;
140: }
141:
142: public List getValueListOfManyOfManyReferenceDataItems() {
143:
144: return valueListOfManyOfManyReferenceDataItems;
145: }
146:
147: public void setValueImp(Object object) {
148:
149: valueListOfManyOfManyReferenceDataItems = getManyOfManyItemsForString((String) object);
150: }
151:
152: }
|