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.rave.designtime.DesignContext;
044: import com.sun.rave.designtime.DesignBean;
045: import com.sun.rave.designtime.DesignProperty;
046: import com.sun.rave.designtime.Result;
047: import com.sun.rave.web.ui.component.*;
048: import org.netbeans.modules.visualweb.web.ui.dt.AbstractDesignInfo;
049: import org.netbeans.modules.visualweb.web.ui.dt.component.table.TableDesignHelper;
050: import org.netbeans.modules.visualweb.web.ui.dt.component.util.DesignMessageUtil;
051:
052: /**
053: * DesignInfo for the <code>TableColumn</code> component. The following behavior is
054: * implemented:
055: * <ul>
056: * <li>Upon component creation, pre-populate with one Static Text.</li>
057: * </ul>
058: *
059: * @author Winston Prakash
060: */
061: public class TableColumnDesignInfo extends AbstractDesignInfo {
062:
063: private static final String WIDTH_PROPERTY = "width";
064:
065: public TableColumnDesignInfo() {
066: super (TableColumn.class);
067: }
068:
069: public Result beanCreatedSetup(DesignBean tableColumnBean) {
070: int colNo = tableColumnBean.getBeanParent().getChildBeanCount();
071: String columnHeaderText = DesignMessageUtil.getMessage(
072: TableColumnDesignInfo.class, "tableColumn.headerText",
073: new Object[] { String.valueOf(colNo) });
074: DesignProperty headerTextProperty = tableColumnBean
075: .getProperty("headerText"); //NOI18N
076: headerTextProperty.setValue(columnHeaderText);
077: DesignProperty widthProperty = tableColumnBean
078: .getProperty("width"); //NOI18N
079: widthProperty.setValue(String.valueOf(200));
080: DesignContext context = tableColumnBean.getDesignContext();
081: if (context.canCreateBean(StaticText.class.getName(),
082: tableColumnBean, null)) {
083: DesignBean staticTextBean = context.createBean(
084: StaticText.class.getName(), tableColumnBean, null);
085: DesignProperty textProperty = staticTextBean
086: .getProperty("text"); //NOI18N
087: textProperty.setValue(staticTextBean.getBeanInfo()
088: .getBeanDescriptor().getDisplayName());
089: }
090: return Result.SUCCESS;
091: }
092:
093: /** {@inheritDoc} */
094: public Result beanDeletedCleanup(DesignBean bean) {
095: // Adjust table width if table column width is et in pixels
096: int oldColumnWidth = -1;
097: Object oldValue = bean.getProperty(WIDTH_PROPERTY).getValue();
098: if (oldValue != null) {
099: String oldColumnWidthStr = (String) oldValue;
100: if (oldColumnWidthStr.indexOf("%") == -1) {
101: //NOI18N
102: try {
103: oldColumnWidth = Integer
104: .parseInt(oldColumnWidthStr);
105: } catch (Exception exc) {
106: }
107: }
108: }
109: if (bean.getBeanParent() != null) {
110: TableDesignHelper.adjustTableWidth(bean.getBeanParent()
111: .getBeanParent(), oldColumnWidth, 0);
112: }
113: return Result.SUCCESS;
114: }
115:
116: /**
117: * {@inheritDoc}
118: * Accept only StaticText, Button or Field as Child
119: */
120: public boolean acceptChild(DesignBean parentBean,
121: DesignBean childBean, Class childClass) {
122: if (childClass.isAssignableFrom(StaticText.class)
123: || childClass.isAssignableFrom(Button.class)
124: || childClass.isAssignableFrom(TextField.class)
125: || childClass.isAssignableFrom(TextArea.class)
126: || childClass.isAssignableFrom(StaticText.class)
127: || childClass.isAssignableFrom(Label.class)
128: || childClass.isAssignableFrom(DropDown.class)
129: || childClass.isAssignableFrom(Hyperlink.class)
130: || childClass.isAssignableFrom(ImageHyperlink.class)
131: || childClass.isAssignableFrom(Checkbox.class)
132: || childClass.isAssignableFrom(RadioButton.class)
133: || childClass.isAssignableFrom(ImageComponent.class)
134: || childClass.isAssignableFrom(PanelGroup.class)
135: || childClass.isAssignableFrom(Message.class)) {
136: return true;
137: }
138: return false;
139: }
140:
141: /**
142: * {@inheritDoc}
143: * Accept only TableRowGroup as Parent
144: */
145: public boolean acceptParent(DesignBean parentBean,
146: DesignBean childBean, Class parentClass) {
147: return parentBean.getInstance().getClass().isAssignableFrom(
148: TableRowGroup.class);
149: }
150:
151: /**
152: * Accept only Reult Set (may be not required in future) or TableDataProvider as links
153: *
154: * {@inheritDoc}
155: */
156: public boolean acceptLink(DesignBean targetBean,
157: DesignBean sourceBean, Class sourceClass) {
158: return false;
159: }
160:
161: /**
162: * TBD - remove the earlier child and add the source bean as child
163: *
164: * {@inheritDoc}
165: */
166: public Result linkBeans(DesignBean targetBean, DesignBean sourceBean) {
167: System.out.println(targetBean);
168: System.out.println(sourceBean);
169: return Result.SUCCESS;
170: }
171:
172: /**
173: * Modify the width of the table if the column width changes
174: */
175: public void propertyChanged(DesignProperty property, Object oldValue) {
176: String propertyName = property.getPropertyDescriptor()
177: .getName();
178: if (propertyName.equals(WIDTH_PROPERTY)) {
179: String columnWidth = (String) property.getValue();
180: if (columnWidth != null) {
181: // If not a percentage, units are in pixels.
182: // Ajust the table width only if the column width is specified in pixles
183: if (columnWidth.indexOf("%") == -1) {
184: TableDesignHelper.adjustTableWidth(property
185: .getDesignBean().getBeanParent());
186: }
187: }
188: }
189: }
190: }
|