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 org.netbeans.modules.visualweb.faces.dt.data;
042:
043: import java.beans.PropertyEditorSupport;
044: import java.sql.ResultSetMetaData;
045: import java.util.ArrayList;
046: import java.util.StringTokenizer;
047: import javax.sql.RowSet;
048: import com.sun.rave.designtime.DesignProperty;
049: import com.sun.rave.designtime.PropertyEditor2;
050: import com.sun.rave.faces.data.ColumnBinding;
051: import com.sun.rave.faces.data.RowSetBindable;
052:
053: public class BoundRowSetColumnPropertyEditor extends
054: PropertyEditorSupport implements PropertyEditor2 {
055:
056: protected DesignProperty prop = null;
057:
058: public void setDesignProperty(DesignProperty prop) {
059: this .prop = prop;
060: }
061:
062: public String[] getTags() {
063: if (prop != null
064: && prop.getDesignBean().getInstance() instanceof RowSetBindable) {
065: RowSet rs = ((RowSetBindable) prop.getDesignBean()
066: .getInstance()).getBoundRowSet();
067: if (rs != null) {
068: try {
069: ResultSetMetaData rsmd = rs.getMetaData();
070: ArrayList tagList = new ArrayList();
071: for (int i = 1; i <= rsmd.getColumnCount(); i++) {
072: String tableName = rsmd.getTableName(i);
073: String columnName = rsmd.getColumnName(i);
074: String tag = tableName + "." + columnName; //NOI18N
075: tagList.add(tag);
076: }
077: return (String[]) tagList
078: .toArray(new String[tagList.size()]);
079: } catch (Exception x) {
080: System.err
081: .println(">>>>>>>>>> Could not get column meta-data to show column list"); //NOI18N
082: x.printStackTrace();
083: }
084: }
085: }
086: return null;
087: }
088:
089: public void setAsText(String text) {
090: // may be one of these:
091: // TABLE.COLUMN
092: // new com.sun.fcl.data.ColumnBinding("TABLE", "COLUMN")
093: // or null!
094: if (text != null && text.indexOf("ColumnBinding(") > -1) { //NOI18N
095: StringTokenizer st = new StringTokenizer(text, "\""); //NOI18N
096: if (st.countTokens() == 5) {
097: st.nextToken();
098: String tableName = st.nextToken();
099: st.nextToken();
100: String columnName = st.nextToken();
101: setValue(new ColumnBinding(tableName, columnName));
102: }
103: } else if (text != null && text.indexOf(".") > -1) { //NOI18N
104: StringTokenizer st = new StringTokenizer(text, "."); //NOI18N
105: if (st.countTokens() == 2) {
106: String tableName = st.nextToken();
107: String columnName = st.nextToken();
108: setValue(new ColumnBinding(tableName, columnName));
109: }
110: } else if (text == null) {
111: setValue(null);
112: }
113: }
114:
115: public String getAsText() {
116: ColumnBinding cb = (ColumnBinding) getValue();
117: if (cb != null) {
118: return cb.getTableName() + "." + cb.getColumnName(); //NOI18N
119: }
120: return null;
121: }
122:
123: public String getJavaInitializationString() {
124: ColumnBinding cb = (ColumnBinding) getValue();
125: if (cb != null) {
126: return "new com.sun.fcl.data.ColumnBinding(\"" + //NOI18N
127: cb.getTableName() + "\", \"" + //NOI18N
128: cb.getColumnName() + "\")"; //NOI18N
129: }
130: return "null"; //NOI18N
131: }
132: }
|