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.reference;
042:
043: import java.io.BufferedReader;
044: import java.io.BufferedWriter;
045: import java.io.IOException;
046: import java.io.StringReader;
047: import java.io.StringWriter;
048: import java.util.Iterator;
049: import java.util.List;
050: import com.sun.rave.designtime.DesignProperty;
051:
052: /**
053: * @author eric
054: *
055: * TODO To change the template for this generated type comment go to
056: * Window - Preferences - Java - Code Generation - Code and Comments
057: */
058: public abstract class ReferenceDataDefiner {
059:
060: /*
061: public static List stringListFromString(String string) {
062:
063: List result = new ArrayList(16);
064: if (string == null) {
065: return result;
066: }
067: StringReader stringReader = new StringReader(string);
068: BufferedReader reader = new BufferedReader(stringReader);
069: try {
070: while (true) {
071: String line = reader.readLine();
072: if (line == null) {
073: break;
074: }
075: line = line.trim();
076: result.add(line);
077: }
078: } catch (IOException e) {
079: assert ReferenceDataManager.loggerUtil.warning("Got IO error, should never really happen", e); // NOI18N
080: }
081: return result;
082: }*/
083:
084: /*
085: public static String stringListToString(List strings) {
086:
087: StringWriter stringWriter = new StringWriter(1024);
088: BufferedWriter writer = new BufferedWriter(stringWriter);
089: Iterator iterator = strings.iterator();
090: try {
091: while (iterator.hasNext()) {
092: String string = (String) iterator.next();
093: writer.write(string);
094: writer.newLine();
095: }
096: writer.flush();
097: stringWriter.flush();
098: } catch (IOException e) {
099: assert ReferenceDataManager.loggerUtil.warning("Got IO error, should never really happen", e); // NOI18N
100: }
101: return stringWriter.toString();
102: }*/
103:
104: public void addBaseItems(List list) {
105: }
106:
107: public void addDesignPropertyItems(DesignProperty liveProperty,
108: List list) {
109: }
110:
111: public void addProjectItems(String itemsString, List list) {
112:
113: if (!definesProjectItems()) {
114: return;
115: }
116: if (itemsString == null) {
117: return;
118: }
119:
120: StringReader stringReader;
121: BufferedReader reader;
122: ReferenceDataItem item;
123:
124: stringReader = new StringReader(itemsString);
125: reader = new BufferedReader(stringReader);
126: try {
127: while (true) {
128: String line = reader.readLine();
129: if (line == null) {
130: break;
131: }
132: line = line.trim();
133: item = newItem(line, line, null, false, true);
134: list.add(item);
135: }
136: } catch (IOException e) {
137: assert ReferenceDataManager.loggerUtil.warning(
138: "Got IO error, should never really happen", e); // NOI18N
139: }
140: }
141:
142: public abstract boolean canAddRemoveItems();
143:
144: public boolean canOrderItems() {
145: return true;
146: }
147:
148: public ReferenceDataItem newItem(String name, String value,
149: boolean isUnsetMarker, boolean isRemoveable) {
150:
151: return newItem(name, value, null, isUnsetMarker, isRemoveable,
152: null);
153: }
154:
155: public boolean definesBaseItems() {
156:
157: return true;
158: }
159:
160: public boolean definesDesignPropertyItems() {
161:
162: return false;
163: }
164:
165: public boolean definesProjectItems() {
166:
167: return canAddRemoveItems();
168: }
169:
170: public String getProjectItemsString(List items) {
171: StringWriter stringWriter;
172: BufferedWriter writer;
173: Iterator iterator;
174:
175: stringWriter = new StringWriter(1024);
176: writer = new BufferedWriter(stringWriter);
177: iterator = items.iterator();
178: try {
179: while (iterator.hasNext()) {
180: ReferenceDataItem item;
181:
182: item = (ReferenceDataItem) iterator.next();
183: writer.write(item.getName());
184: writer.newLine();
185: }
186: writer.flush();
187: stringWriter.flush();
188: } catch (IOException e) {
189: assert ReferenceDataManager.loggerUtil.warning(
190: "Got IO error, should never really happen", e); // NOI18N
191: }
192: return stringWriter.toString();
193: }
194:
195: public abstract boolean isValueAString();
196:
197: public ReferenceDataItem newItem(String name, Object value,
198: String javaInitializationString, boolean isUnsetMarker,
199: boolean isRemoveable) {
200:
201: return newItem(name, value, javaInitializationString,
202: isUnsetMarker, isRemoveable, null);
203: }
204:
205: public ReferenceDataItem newItem(String name, Object value,
206: String javaInitializationString, boolean isUnsetMarker,
207: boolean isRemoveable, ReferenceDataItem aliasFor) {
208:
209: return new ReferenceDataItem(name, value,
210: javaInitializationString, isUnsetMarker, isRemoveable,
211: aliasFor);
212: }
213:
214: public boolean shouldPersistProjectItems() {
215:
216: return true;
217: }
218:
219: public boolean supportsDesignPropertyItems() {
220:
221: return false;
222: }
223:
224: public boolean userMultipleColumnsToDisplay() {
225:
226: return false;
227: }
228:
229: }
|