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