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.web.ui.dt.component;
042:
043: import com.sun.data.provider.FieldKey;
044: import com.sun.data.provider.TableDataProvider;
045: import com.sun.data.provider.impl.CachedRowSetDataProvider;
046: import com.sun.rave.designtime.DesignBean;
047: import com.sun.rave.designtime.DesignProperty;
048: import com.sun.rave.designtime.DisplayAction;
049: import com.sun.rave.designtime.DisplayActionSet;
050: import com.sun.rave.designtime.Result;
051: import com.sun.rave.designtime.faces.FacesDesignContext;
052: import com.sun.rave.web.ui.component.Table;
053: import com.sun.rave.web.ui.component.TableColumn;
054: import com.sun.rave.web.ui.component.TableRowGroup;
055: import java.awt.Image;
056: import javax.swing.ImageIcon;
057: import org.netbeans.modules.visualweb.web.ui.dt.AbstractDesignInfo;
058: import org.netbeans.modules.visualweb.web.ui.dt.component.customizers.TableBindToDataAction;
059: import org.netbeans.modules.visualweb.web.ui.dt.component.customizers.TableCustomizerAction;
060: import org.netbeans.modules.visualweb.web.ui.dt.component.table.TableDesignHelper;
061: import org.netbeans.modules.visualweb.web.ui.dt.component.table.TableRowGroupDesignState;
062:
063: /**
064: * DesignInfo for the <code>TableRowGroup</code> component. The following behavior is
065: * implemented:
066: * <ul>
067: * <li>Upon component creation, pre-populate with one table coulum.</li>
068: * </ul>
069: *
070: * @author Winston Prakash
071: */
072: public class TableRowGroupDesignInfo extends AbstractDesignInfo {
073:
074: private static final String SOURCE_DATA_PROPERTY = "sourceData";
075:
076: public TableRowGroupDesignInfo() {
077: super (TableRowGroup.class);
078: }
079:
080: public DisplayActionSet getContextItemsExt(final DesignBean bean) {
081:
082: return new DisplayActionSet() {
083:
084: public DisplayAction[] getDisplayActions() {
085: return new DisplayAction[] {
086: new TableCustomizerAction(bean),
087: new TableBindToDataAction(bean) };
088: }
089:
090: public boolean isPopup() {
091: return true;
092: }
093:
094: public boolean isEnabled() {
095: return true;
096: }
097:
098: public Result invoke() {
099: throw new UnsupportedOperationException(
100: "Not supported yet."); //NOI18N
101: }
102:
103: public String getDisplayName() {
104: return "";
105: }
106:
107: public String getDescription() {
108: return "";
109: }
110:
111: public Image getLargeIcon() {
112: return new ImageIcon(getClass().getResource(
113: AbstractDesignInfo.DECORATION_ICON)).getImage();
114: }
115:
116: public Image getSmallIcon() {
117: return new ImageIcon(getClass().getResource(
118: AbstractDesignInfo.DECORATION_ICON)).getImage();
119: }
120:
121: public String getHelpKey() {
122: throw new UnsupportedOperationException(
123: "Not supported yet."); //NOI18N
124: }
125:
126: };
127: }
128:
129: /** {@inheritDoc} */
130: public DisplayAction[] getContextItems(DesignBean bean) {
131: return new DisplayAction[] { new TableCustomizerAction(bean),
132: new TableBindToDataAction(bean) };
133: }
134:
135: /**
136: * Create Table Row Group Design State with the design bean and save its state
137: * which in turn would create default no of table columns with few row of data.
138: * {@inheritDoc}
139: */
140: public Result beanCreatedSetup(DesignBean tableRowGroupBean) {
141: DesignProperty rowCountProperty = tableRowGroupBean
142: .getProperty("rows"); //NOI18N
143: rowCountProperty.setValue(new Integer(5));
144: // Now table automatically created the column header. So may not be required.
145: /*if (tableRowGroupBean.getBeanParent().getChildBeanCount() > 0){
146: DesignProperty headerProperty = tableRowGroupBean.getProperty("headerText"); //NOI18N
147: headerProperty.setValue(DesignMessageUtil.getMessage(TableRowGroupDesignInfo.class,"tableRowGroupHeader.headerText"));
148: }*/
149: FacesDesignContext fcontext = (FacesDesignContext) tableRowGroupBean
150: .getDesignContext();
151: TableRowGroupDesignState tblRowGroupDesignState = new TableRowGroupDesignState(
152: tableRowGroupBean);
153: tblRowGroupDesignState.setDataProviderBean(TableDesignHelper
154: .createDefaultDataProvider(tableRowGroupBean
155: .getBeanParent()));
156: tblRowGroupDesignState.saveState();
157: return Result.SUCCESS;
158: }
159:
160: /**
161: * {@inheritDoc}
162: * Accept only TableColumn as Child
163: */
164: public boolean acceptChild(DesignBean parentBean,
165: DesignBean childBean, Class childClass) {
166: return childClass.isAssignableFrom(TableColumn.class);
167: }
168:
169: /**
170: * {@inheritDoc}
171: * Accept only Table as Parent
172: */
173: public boolean acceptParent(DesignBean parentBean,
174: DesignBean childBean, Class parentClass) {
175: return parentBean.getInstance().getClass().isAssignableFrom(
176: Table.class);
177: }
178:
179: /**
180: * Accept only Reult Set (may be not required in future) or TableDataProvider as links
181: *
182: * {@inheritDoc}
183: */
184: public boolean acceptLink(DesignBean targetBean,
185: DesignBean sourceBean, Class sourceClass) {
186: if (TableDataProvider.class.isAssignableFrom(sourceClass)) {
187: return true;
188: }
189: return false;
190: }
191:
192: /**
193: * If child bean is a TableDataProvider create TableRowGroupDesignState with the target bean
194: * and set TableDataProvider as source bean and then save its state which in turn would create
195: * corresponding tables and columns with the data in the TableDataProvider.
196: *
197: * TBD - if the child bean is TableColumn
198: *
199: * {@inheritDoc}
200: */
201: public Result linkBeans(DesignBean targetBean, DesignBean sourceBean) {
202: if (sourceBean.getInstance() instanceof TableDataProvider) {
203: // Bug 6333281 - After cancelling rowset previous table binding lost
204: // After dropping a CachedRowsetDataProvider, a dialog pops up if
205: // already a CachedRowset exists in the session bean. If the user
206: // Cancels this dialog, then the rowset is not set and the data provider
207: // is deleted.
208: if (sourceBean.getInstance() instanceof CachedRowSetDataProvider) {
209: CachedRowSetDataProvider cachedRowSetDataProvider = (CachedRowSetDataProvider) sourceBean
210: .getInstance();
211: if (cachedRowSetDataProvider.getCachedRowSet() == null) {
212: return Result.FAILURE;
213: }
214: }
215:
216: TableDataProvider tdp = (TableDataProvider) sourceBean
217: .getInstance();
218: FieldKey[] columns = tdp.getFieldKeys();
219: if ((columns == null) || (columns.length == 0)) {
220: return Result.FAILURE;
221: }
222:
223: TableRowGroupDesignState ts = new TableRowGroupDesignState(
224: targetBean);
225: ts.setDataProviderBean(sourceBean);
226: ts.saveState();
227: TableDesignHelper.deleteDefaultDataProvider(targetBean);
228: }
229: return Result.SUCCESS;
230: }
231:
232: /** {@inheritDoc} */
233: public Result beanDeletedCleanup(DesignBean bean) {
234: TableDesignHelper.deleteDefaultDataProvider(bean);
235: return Result.SUCCESS;
236: }
237:
238: /**
239: * Reset the table row group to use default table if the source data is set to null
240: * This could happen if the user deleted the data provider.
241: * @param property The <code>DesignProperty</code> that has changed.
242: * @param oldValue Optional oldValue, or <code>null</code> if the
243: * previous value is not known
244: */
245: public void propertyChanged(DesignProperty property, Object oldValue) {
246: String propertyName = property.getPropertyDescriptor()
247: .getName();
248: if (propertyName.equals(SOURCE_DATA_PROPERTY)) {
249: if ((oldValue != null) && (!property.isModified())) {
250: DesignBean tableRowGroupBean = property.getDesignBean();
251: TableRowGroupDesignState tblRowGroupDesignState = new TableRowGroupDesignState(
252: tableRowGroupBean);
253: tblRowGroupDesignState
254: .setDataProviderBean(
255: TableDesignHelper
256: .createDefaultDataProvider(tableRowGroupBean
257: .getBeanParent()), true);
258: tblRowGroupDesignState.saveState();
259: }
260: }
261: }
262:
263: }
|