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 com.sun.jsfcl.std.reference.ReferenceDataManager;
044: import java.awt.Component;
045: import java.beans.FeatureDescriptor;
046: import java.util.ArrayList;
047: import java.util.StringTokenizer;
048: import com.sun.jsfcl.std.reference.ReferenceDataItem;
049: import org.openide.explorer.propertysheet.ExPropertyEditor;
050: import org.openide.explorer.propertysheet.PropertyEnv;
051:
052: /**
053: * @author eric
054: * Winston Prakash (modification to include help ID)
055: *
056: * @deprecated
057: */
058: public class ChooseManyReferenceDataPropertyEditor extends
059: ChooseOneReferenceDataPropertyEditor implements
060: ExPropertyEditor {
061:
062: protected ReferenceDataItem[] valueReferenceDataItems;
063: protected String separator;
064:
065: public ChooseManyReferenceDataPropertyEditor() {
066:
067: separator = getDefaultSeparator();
068: }
069:
070: /**
071: * Make this into a parameter read from the properties environment.
072: * @return
073: */
074: protected boolean getAllowDuplicates() {
075:
076: return false;
077: }
078:
079: public String getAsText() {
080:
081: return getStringForManyItems(valueReferenceDataItems);
082: }
083:
084: public Component getCustomEditor() {
085:
086: return new ChooseManyReferenceDataPanel(this ,
087: getDesignProperty());
088: }
089:
090: protected String getDefaultSeparator() {
091:
092: return " "; //NOI18N
093: }
094:
095: protected ReferenceDataItem[] getManyItemsForString(String string) {
096: ArrayList list;
097: StringTokenizer tokenizer;
098: String token;
099: ReferenceDataItem item;
100:
101: if (string == null) {
102: return new ReferenceDataItem[0];
103: }
104: tokenizer = new StringTokenizer(string);
105: list = new ArrayList(16);
106: while (tokenizer.hasMoreTokens()) {
107: token = tokenizer.nextToken();
108: token = token.trim();
109: item = getItemByName(token);
110: if (item != null) {
111: list.add(item);
112: }
113: }
114: ReferenceDataItem result[];
115:
116: result = new ReferenceDataItem[list.size()];
117: result = (ReferenceDataItem[]) list.toArray(result);
118: return result;
119: }
120:
121: protected String getStringForManyItems(Object[] items) {
122: StringBuffer buffer;
123:
124: if (items == null) {
125: return ""; //NOI18N
126: }
127: buffer = new StringBuffer(256);
128: for (int i = 0; i < items.length; i++) {
129: ReferenceDataItem item = (ReferenceDataItem) items[i];
130: String string = getStringForItem(item);
131: buffer.append(string);
132: if (i != (items.length - 1)) {
133: buffer.append(separator);
134: }
135: }
136: return buffer.toString();
137: }
138:
139: public String[] getTags() {
140:
141: return null;
142: }
143:
144: public void setAsText(String text)
145: throws java.lang.IllegalArgumentException {
146:
147: setValue(text);
148: }
149:
150: public ReferenceDataItem[] getValueReferenceDataItems() {
151:
152: return valueReferenceDataItems;
153: }
154:
155: public void setValueImp(Object object) {
156:
157: valueReferenceDataItems = getManyItemsForString((String) object);
158: }
159:
160: public boolean supportsCustomEditor() {
161:
162: return true;
163: }
164:
165: public void attachEnv(PropertyEnv env) {
166: // Add the help button
167: String name = (String) getDesignProperty()
168: .getPropertyDescriptor().getValue(REFERENCE_DATA_NAME);
169: if (name.equals(ReferenceDataManager.STYLE_CLASSES)) {
170: FeatureDescriptor desc = env.getFeatureDescriptor();
171: desc
172: .setValue(ExPropertyEditor.PROPERTY_HELP_ID,
173: "projrave_ui_elements_propeditors_styleclass_prop_ed");
174: }
175: }
176:
177: }
|