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.html;
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 com.sun.rave.faces.data.DefaultTableDataModel;
048: import com.sun.rave.faces.data.RowSetDataModel;
049: import org.netbeans.modules.visualweb.faces.dt.std.DataModelBindingCustomizerAction;
050: import org.netbeans.modules.visualweb.faces.dt.util.ComponentBundle;
051: import javax.faces.component.UIColumn;
052: import javax.faces.component.html.HtmlDataTable;
053: import javax.faces.component.html.HtmlOutputText;
054:
055: public class HtmlDataTableDesignInfo implements DesignInfo {
056:
057: private static final ComponentBundle bundle = ComponentBundle
058: .getBundle(HtmlDataTableDesignInfo.class);
059:
060: public Class getBeanClass() {
061: return HtmlDataTable.class;
062: }
063:
064: public boolean acceptParent(DesignBean parentBean,
065: DesignBean childBean, Class childClass) {
066: return true;
067: }
068:
069: public boolean acceptChild(DesignBean parentBean,
070: DesignBean childBean, Class childClass) {
071: if (childClass == null) { //defensive
072: return true;
073: }
074: if (UIColumn.class.isAssignableFrom(childClass)
075: || javax.faces.component.html.HtmlPanelGroup.class
076: .isAssignableFrom(childClass)
077: || javax.faces.component.html.HtmlPanelGrid.class
078: .isAssignableFrom(childClass)) {
079: return true;
080: }
081: return false;
082: }
083:
084: public Result beanCreatedSetup(DesignBean bean) {
085: try {
086: DesignContext context = bean.getDesignContext();
087: FacesDesignContext fcontext = null;
088: if (context instanceof FacesDesignContext) {
089: fcontext = (FacesDesignContext) context;
090: }
091:
092: /* Controversial.... now that we have our own default stylesheet
093: with alternating even/row colors, this just adds visual
094: clutter. See the "rowClasses" property setting below.
095: // set the border to 1
096: DesignProperty borderProp = bean.getProperty("border"); //NOI18N
097: if (borderProp != null) {
098: borderProp.setValue(new Integer(1));
099: }
100: */
101:
102: // create and setup a default datamodel
103: DesignBean dm = context.createBean(
104: DefaultTableDataModel.class.getName(), null, null);
105: dm.setInstanceName(bean.getInstanceName() + "Model", true); //NOI18N
106: bean.getProperty("var").setValue("currentRow"); //NOI18N
107:
108: bean.getProperty("headerClass").setValue("list-header"); //NOI18N
109: bean.getProperty("rowClasses").setValue(
110: "list-row-even,list-row-odd"); //NOI18N
111:
112: if (fcontext != null) {
113: String ref = fcontext.getBindingExpr(dm);
114: bean.getProperty("value").setValueSource(ref); //NOI18N
115: } else {
116: String outerName = context.getDisplayName();
117: bean.getProperty("value").setValueSource(
118: "#{" + outerName + "." + //NOI18N
119: dm.getInstanceName() + "}"); //NOI18N
120: }
121:
122: // create the three initial default columns
123: for (int i = 1; i <= 3; i++) {
124: DesignBean col = context.createBean(UIColumn.class
125: .getName(), bean, null);
126: if (col != null) {
127: DesignBean input = context.createBean(
128: HtmlOutputText.class.getName(), col, null);
129: if (input != null) {
130: input.getProperty("value").setValueSource( //NOI18N
131: "#{currentRow['COLUMN" + i + "']}"); //NOI18N
132: }
133: DesignBean header = ((FacesDesignContext) context)
134: .createFacet("header", HtmlOutputText.class
135: .getName(), col); //NOI18N
136: if (header != null) {
137: //header.getProperty("value").setValue("column" + i); //NOI18N
138: header.getProperty("value").setValue(
139: bundle.getMessage("Table_Column") + i); //NOI18N
140: }
141: }
142: }
143: } catch (Exception x) {
144: x.printStackTrace();
145: }
146: return Result.SUCCESS;
147: }
148:
149: public Result beanPastedSetup(DesignBean bean) {
150: return Result.SUCCESS;
151: }
152:
153: public Result beanDeletedCleanup(DesignBean bean) {
154: DesignContext context = bean.getDesignContext();
155:
156: DesignBean dm = context.getBeanByName(bean.getInstanceName()
157: + "Model"); //NOI18N
158: if (dm != null
159: && (dm.getInstance() instanceof DefaultTableDataModel || dm
160: .getInstance() instanceof RowSetDataModel)) {
161: context.deleteBean(dm);
162: }
163:
164: return Result.SUCCESS;
165: }
166:
167: public DisplayAction[] getContextItems(DesignBean bean) {
168: return new DisplayAction[] {
169: new DataModelBindingCustomizerAction(bean),
170: new HtmlDataTableCustomizerAction(bean),
171: new HtmlDataTableAddColumnAction(bean),
172: // This action is now "hardcoded" into the designer. All
173: // FacesDesignBeans will get this action. This is done such
174: // that third party libraries pick it up too.
175: //new BindingsCustomizerAction(bean),
176: };
177: }
178:
179: public boolean acceptLink(DesignBean targetBean,
180: DesignBean sourceBean, Class sourceClass) {
181: return HtmlDesignInfoBase.isResultSetClass(sourceClass);
182: // return ResultSet.class.isAssignableFrom(sourceClass);
183: }
184:
185: public Result linkBeans(DesignBean targetBean, DesignBean sourceBean) {
186: // if cachedRowSetDataProvider, switch the sourceBean to
187: // it's rowset.
188: if (HtmlDesignInfoBase.isCachedRowSetDP(sourceBean
189: .getInstance())) {
190: DesignBean db = HtmlDesignInfoBase
191: .findCachedRowSetBean(sourceBean);
192: if (db != null) {
193: sourceBean = db;
194: }
195: }
196: if (sourceBean.getInstance() instanceof ResultSet) {
197:
198: HtmlDataTableState ts = new HtmlDataTableState(targetBean);
199: ts.varName = HtmlDataTableState.DEFAULT_VAR_NAME;
200: ts.setSourceBean(sourceBean);
201: ts.refreshColumnInfo();
202: ts.saveState();
203: }
204: return Result.SUCCESS;
205: }
206:
207: public void beanContextActivated(DesignBean bean) {
208: }
209:
210: public void beanContextDeactivated(DesignBean bean) {
211: }
212:
213: public void instanceNameChanged(DesignBean bean,
214: String oldInstanceName) {
215: }
216:
217: public void beanChanged(DesignBean bean) {
218: }
219:
220: public void propertyChanged(DesignProperty prop, Object oldValue) {
221: }
222:
223: public void eventChanged(DesignEvent event) {
224: }
225: }
|