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:
042: package org.netbeans.modules.sql.framework.model.impl;
043:
044: import java.util.ArrayList;
045: import java.util.Collections;
046: import java.util.HashMap;
047: import java.util.List;
048:
049: import com.sun.sql.framework.exception.BaseException;
050:
051: /**
052: *
053: */
054: public class OperatorFieldNodeX implements
055: org.netbeans.modules.sql.framework.ui.graph.IOperatorField {
056:
057: private String fieldName;
058:
059: private String fieldDisplayName;
060:
061: private HashMap map = new HashMap();
062:
063: private String tTip;
064:
065: private boolean edit;
066:
067: private Object fieldData;
068:
069: private boolean isStatic;
070:
071: private List acceptables = Collections
072: .synchronizedList(new ArrayList());
073:
074: private List displayAcceptables = Collections
075: .synchronizedList(new ArrayList());
076:
077: private String defaultAcceptable;
078:
079: /** Creates a new instance of OperatorFieldNodeX */
080: public OperatorFieldNodeX(String name, String displayName) {
081: this .fieldName = name;
082: this .fieldDisplayName = displayName;
083: }
084:
085: /*
086: * (non-Javadoc)
087: *
088: * @see org.netbeans.modules.sql.framework.ui.graph.IOperatorField#getName()
089: */
090: public String getName() {
091: return fieldName;
092: }
093:
094: /*
095: * (non-Javadoc)
096: *
097: * @see org.netbeans.modules.sql.framework.ui.graph.IOperatorField#setName(java.lang.String)
098: */
099: public void setName(String name) {
100: this .fieldName = name;
101: }
102:
103: /*
104: * (non-Javadoc)
105: *
106: * @see org.netbeans.modules.sql.framework.ui.graph.IOperatorField#getDisplayName()
107: */
108: public String getDisplayName() {
109: return this .fieldDisplayName;
110: }
111:
112: /*
113: * (non-Javadoc)
114: *
115: * @see org.netbeans.modules.sql.framework.ui.graph.IOperatorField#setDisplayName(java.lang.String)
116: */
117: public void setDisplayName(String displayName) {
118: this .fieldDisplayName = displayName;
119: }
120:
121: /*
122: * (non-Javadoc)
123: *
124: * @see org.netbeans.modules.sql.framework.ui.graph.IOperatorField#getAttributeValue(java.lang.String)
125: */
126: public Object getAttributeValue(String attrName) {
127: return map.get(attrName);
128: }
129:
130: /*
131: * (non-Javadoc)
132: *
133: * @see org.netbeans.modules.sql.framework.ui.graph.IOperatorField#setAttributeValue(java.lang.String,
134: * java.lang.Object)
135: */
136: public void setAttributeValue(String attrName, Object val) {
137: map.put(attrName, val);
138: }
139:
140: /*
141: * (non-Javadoc)
142: *
143: * @see org.netbeans.modules.sql.framework.ui.graph.IOperatorField#setToolTip(java.lang.String)
144: */
145: public void setToolTip(String toolTip) {
146: this .tTip = toolTip;
147: }
148:
149: /*
150: * (non-Javadoc)
151: *
152: * @see org.netbeans.modules.sql.framework.ui.graph.IOperatorField#getToolTip()
153: */
154: public String getToolTip() {
155: return tTip;
156: }
157:
158: /*
159: * (non-Javadoc)
160: *
161: * @see org.netbeans.modules.sql.framework.ui.graph.IOperatorField#setEditable(boolean)
162: */
163: public void setEditable(boolean editable) {
164: this .edit = editable;
165: }
166:
167: /*
168: * (non-Javadoc)
169: *
170: * @see org.netbeans.modules.sql.framework.ui.graph.IOperatorField#isEditable()
171: */
172: public boolean isEditable() {
173: return edit;
174: }
175:
176: /*
177: * (non-Javadoc)
178: *
179: * @see org.netbeans.modules.sql.framework.ui.graph.IOperatorField#setStatic(boolean)
180: */
181: public void setStatic(boolean staticFlag) {
182: isStatic = staticFlag;
183: }
184:
185: /*
186: * (non-Javadoc)
187: *
188: * @see org.netbeans.modules.sql.framework.ui.graph.IOperatorField#isStatic()
189: */
190: public boolean isStatic() {
191: return isStatic;
192: }
193:
194: public String getDefaultValue() {
195: return defaultAcceptable;
196: }
197:
198: public void setDefaultValue(String newValue) throws BaseException {
199: if (acceptables.contains(newValue)) {
200: defaultAcceptable = newValue;
201: } else {
202: throw new BaseException(
203: "Given value does not exist in acceptables list: "
204: + newValue);
205: }
206: }
207:
208: /*
209: * (non-Javadoc)
210: *
211: * @see org.netbeans.modules.sql.framework.ui.graph.IOperatorField#getAcceptableValues()
212: */
213: public List getAcceptableValues() {
214: return (isStatic) ? Collections.unmodifiableList(acceptables)
215: : Collections.EMPTY_LIST;
216: }
217:
218: /*
219: * (non-Javadoc)
220: *
221: * @see org.netbeans.modules.sql.framework.ui.graph.IOperatorField#setAcceptableValues(java.util.List)
222: */
223: public void setAcceptableValues(List acceptableValues) {
224: if (isStatic) {
225: acceptables.clear();
226: if (acceptableValues != null) {
227: acceptables.addAll(acceptableValues);
228: } else {
229: // Clear display values as well.
230: displayAcceptables.clear();
231: }
232: }
233: }
234:
235: /*
236: * (non-Javadoc)
237: *
238: * @see org.netbeans.modules.sql.framework.ui.graph.IOperatorField#getAcceptableDisplayValues()
239: */
240: public List getAcceptableDisplayValues() {
241: return (isStatic) ? displayAcceptables.isEmpty() ? getAcceptableValues()
242: : Collections.unmodifiableList(displayAcceptables)
243: : Collections.EMPTY_LIST;
244: }
245:
246: /*
247: * (non-Javadoc)
248: *
249: * @see org.netbeans.modules.sql.framework.ui.graph.IOperatorField#setAcceptableDisplayValues(java.util.List)
250: */
251: public void setAcceptableDisplayValues(List displayValues) {
252: if (isStatic) {
253: displayAcceptables.clear();
254: if (displayValues != null) {
255: if (displayValues.isEmpty()) {
256: return;
257: } else if (displayValues.size() != acceptables.size()) {
258: throw new IllegalArgumentException(
259: "Count of display values must match acceptable values.");
260: }
261:
262: displayAcceptables.addAll(displayValues);
263: }
264: }
265: }
266:
267: public Object getFieldDataObject() {
268: return fieldData;
269: }
270:
271: public void setFieldDataObject(Object dObj) {
272: this.fieldData = dObj;
273: }
274: }
|