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_1_1.component;
042:
043: import org.netbeans.modules.visualweb.faces.dt.HtmlDesignInfoBase;
044: import java.sql.*;
045: import com.sun.rave.designtime.*;
046: import com.sun.rave.designtime.faces.*;
047: import org.netbeans.modules.visualweb.faces.dt.std.RowDataBindingCustomizerAction;
048: import org.netbeans.modules.visualweb.faces.dt.util.ComponentBundle;
049: import javax.faces.component.UISelectItem;
050:
051: public class UISelectItemDesignInfo implements DesignInfo {
052:
053: private static final ComponentBundle bundle = ComponentBundle
054: .getBundle(UISelectItemDesignInfo.class);
055:
056: public Class getBeanClass() {
057: return UISelectItem.class;
058: }
059:
060: public boolean acceptParent(DesignBean parentBean,
061: DesignBean childBean, Class childClass) {
062: return true;
063: }
064:
065: public boolean acceptChild(DesignBean parentBean,
066: DesignBean childBean, Class childClass) {
067: return true;
068: }
069:
070: public Result beanCreatedSetup(DesignBean bean) {
071: return null;
072: }
073:
074: public Result beanPastedSetup(DesignBean bean) {
075: return null;
076: }
077:
078: public Result beanDeletedCleanup(DesignBean bean) {
079: return null;
080: }
081:
082: public DisplayAction[] getContextItems(DesignBean bean) {
083: return new DisplayAction[] { new RowDataBindingCustomizerAction(
084: bean),
085: // This action is now "hardcoded" into the designer. All
086: // FacesDesignBeans will get this action. This is done such
087: // that third party libraries pick it up too.
088: //new BindingsCustomizerAction(bean),
089: };
090: }
091:
092: public boolean acceptLink(DesignBean targetBean,
093: DesignBean sourceBean, Class sourceClass) {
094: return HtmlDesignInfoBase.isResultSetClass(sourceClass);
095: // return ResultSet.class.isAssignableFrom(sourceClass);
096: }
097:
098: public Result linkBeans(DesignBean targetBean, DesignBean sourceBean) {
099: // if cachedRowSetDataProvider, switch the sourceBean to
100: // it's rowset.
101: if (HtmlDesignInfoBase.isCachedRowSetDP(sourceBean
102: .getInstance())) {
103: DesignBean db = HtmlDesignInfoBase
104: .findCachedRowSetBean(sourceBean);
105: if (db != null) {
106: sourceBean = db;
107: }
108: }
109: if (sourceBean.getInstance() instanceof ResultSet) {
110: try {
111: ResultSet rs = (ResultSet) sourceBean.getInstance();
112: if (rs != null) {
113: ResultSetMetaData rsmd = rs.getMetaData();
114: if (rsmd.getColumnCount() >= 1) {
115: String table = rsmd.getTableName(1);
116: String column = rsmd.getColumnName(1);
117: String outerName = ((FacesDesignContext) sourceBean
118: .getDesignContext()).getReferenceName();
119: String valueRef = "#{" + outerName + "."
120: + sourceBean.getInstanceName()
121: + ".rowData." + column + "}"; //NOI18N
122: String dtvalue = "[" + table + "." + column
123: + "]"; //NOI18N
124: targetBean.getProperty("value").setValue(
125: valueRef); //NOI18N
126: targetBean.getDesignContext().setContextData(
127: targetBean.getInstanceName()
128: + ".databind", dtvalue); //NOI18N
129: //System.err.println("Linking target:" + targetBean + " src:" + sourceBean + " valueRef:" + valueRef);
130: }
131: }
132: } catch (Exception x) {
133: System.err.println(bundle
134: .getMessage("getMetaDataException")); //NOI18N
135: x.printStackTrace();
136: }
137: } else if (sourceBean.getInstance() instanceof ResultSet) {
138: try {
139: ResultSet rs = (ResultSet) sourceBean.getInstance();
140: ResultSetMetaData rsmd = rs.getMetaData();
141: if (rsmd.getColumnCount() >= 1) {
142: String table = rsmd.getTableName(1);
143: String column = rsmd.getColumnName(1);
144: String outerName = ((FacesDesignContext) sourceBean
145: .getDesignContext()).getReferenceName();
146: String valueRef = "#{" + outerName + "."
147: + sourceBean.getInstanceName()
148: + ".currentRow['" + column + "']}"; //NOI18N
149: targetBean.getProperty("value").setValue(valueRef); //NOI18N
150: // String dtvalue = "[" + table + "." + column + "]";
151: // targetBean.getDesignContext().setContextData(targetBean.getInstanceName() + ".databind", dtvalue);
152: //System.err.println("Linking target:" + targetBean + " src:" + sourceBean + " valueRef:" + valueRef);
153: }
154: } catch (Exception x) {
155: System.err.println(bundle
156: .getMessage("getMetaDataException")); //NOI18N
157: x.printStackTrace();
158: }
159: }
160: return Result.SUCCESS;
161: }
162:
163: public void beanContextActivated(DesignBean bean) {
164: }
165:
166: public void beanContextDeactivated(DesignBean bean) {
167: }
168:
169: public void instanceNameChanged(DesignBean bean,
170: String oldInstanceName) {
171: }
172:
173: public void beanChanged(DesignBean bean) {
174: }
175:
176: public void propertyChanged(DesignProperty prop, Object oldValue) {
177: }
178:
179: public void eventChanged(DesignEvent event) {
180: }
181: }
|