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.std;
042:
043: import org.netbeans.modules.visualweb.faces.dt.HtmlDesignInfoBase;
044: import java.awt.GridBagConstraints;
045: import java.awt.GridBagLayout;
046: import java.awt.Insets;
047: import javax.faces.component.UIData;
048: import javax.faces.component.UISelectItems;
049: import javax.faces.component.UISelectMany;
050: import javax.faces.component.html.HtmlDataTable;
051: import javax.swing.JLabel;
052: import javax.swing.JPanel;
053: import javax.swing.JTabbedPane;
054: import javax.swing.JTextField;
055: import org.netbeans.modules.visualweb.faces.dt.std.table.HtmlDataTableState;
056: import org.netbeans.modules.visualweb.faces.dt.util.ComponentBundle;
057: import com.sun.rave.designtime.DesignBean;
058: import com.sun.rave.designtime.DesignProperty;
059: import com.sun.rave.designtime.faces.FacesDesignProperty;
060: import org.openide.explorer.propertysheet.editors.EnhancedCustomPropertyEditor;
061:
062: public class ValueBindingPanel extends JPanel implements
063: EnhancedCustomPropertyEditor {
064:
065: private static final ComponentBundle bundle = ComponentBundle
066: .getBundle(ValueBindingPanel.class);
067:
068: protected DesignProperty liveProperty;
069: protected boolean isValueProperty;
070: protected FacesDesignProperty facesDesignProperty;
071: protected JTabbedPane tabs = new JTabbedPane();
072:
073: protected ObjectBindingPanel2 objectPanel = null; //new ObjectBindingPanel(this);
074: protected DataModelBindingPanel dmPanel = null; //new DataModelBindingPanel(this);
075: protected RowDataBindingPanel rowDataPanel = null; //new RowDataBindingPanel(this);
076: protected ColumnDataBindingPanel columnDataPanel = null; //new ColumnDataBindingPanel(this);
077:
078: protected JTextField valueTextField = new JTextField();
079: protected GridBagLayout gridBagLayout1 = new GridBagLayout();
080: protected JLabel valueLabel = new JLabel();
081: protected ValueBindingPropertyEditor vbpe;
082:
083: public ValueBindingPanel(ValueBindingPropertyEditor vbpe,
084: DesignProperty lp) {
085: this .vbpe = vbpe;
086: this .liveProperty = lp;
087: // This type of code REALLY sucks, but I'm stuck with it for now :( TODO
088: isValueProperty = "value".equals(liveProperty
089: .getPropertyDescriptor().getName());
090: this .facesDesignProperty = lp instanceof FacesDesignProperty ? (FacesDesignProperty) lp
091: : null;
092: try {
093: jbInit();
094: } catch (Exception e) {
095: e.printStackTrace();
096: }
097:
098: Object bean = lp.getDesignBean().getInstance();
099:
100: // find the current value
101: String currentBinding = lp.getValueSource();
102: valueTextField.setText(currentBinding);
103:
104: if (isValueProperty && bean instanceof HtmlDataTable) {
105: dmPanel = new DataModelBindingPanel(this , null, lp);
106: tabs.add(dmPanel, bundle.getMessage("bindToDb")); //NOI18N
107: } else if (isValueProperty && bean instanceof UISelectItems) {
108: columnDataPanel = new ColumnDataBindingPanel(this , null, lp);
109: tabs.add(columnDataPanel, bundle
110: .getMessage("bindDiplayToDb")); //NOI18N
111: } else if (!isValueProperty || !(bean instanceof UISelectMany)) {
112: rowDataPanel = new RowDataBindingPanel(this , null, lp);
113: tabs.add(rowDataPanel, bundle.getMessage("bindToDb")); //NOI18N
114: }
115:
116: objectPanel = new ObjectBindingPanel2(this , lp);
117: tabs.add(objectPanel, bundle.getMessage("bindToObj")); //NOI18N
118: if (!isValueProperty) {
119: tabs.setSelectedComponent(objectPanel);
120: }
121:
122: initializing = false;
123: }
124:
125: public Object getPropertyValue() throws IllegalStateException {
126: String vb = getValueBinding();
127:
128: // special handling for UISelectItems
129: DesignBean bean = liveProperty.getDesignBean();
130: if (bean.getInstance() instanceof UISelectItems
131: && isValueProperty) { //NOI18N
132:
133: // if we're blanking out the value binding for 'value'
134: // replug-in the default items (or nuke them if not)
135: //MBOHM for 6194849, no harm in calling this line here, and would be more risky to change
136: vb = HtmlDesignInfoBase.maybeSetupDefaultSelectItems(bean,
137: vb);
138: // check and see if we need a converter
139: //MBOHM 6194849 //HtmlDesignInfoBase.maybeSetupConverter(bean, selectItemsValueType);
140: }
141: // special handling for UIData bound to a rowset
142: else if (bean.getInstance() instanceof UIData
143: && "value".equals(liveProperty.getPropertyDescriptor()
144: .getName())) {
145:
146: vb = HtmlDataTableState
147: .maybeGenerateRowsetColumns(bean, vb);
148: }
149:
150: if (vb != null && vb.length() == 0) {
151: vb = null;
152: }
153: return vb;
154: }
155:
156: protected int selectItemsValueType = 0;
157:
158: public void setSelectItemsValueType(int sqlType) {
159: this .selectItemsValueType = sqlType;
160: }
161:
162: protected boolean initializing = true;
163:
164: public void setValueBinding(String valueBinding) {
165: if (initializing) {
166: return;
167: }
168: valueTextField.setText(valueBinding);
169: }
170:
171: public String getValueBinding() {
172: return valueTextField.getText();
173: }
174:
175: private void jbInit() throws Exception {
176: this .setLayout(gridBagLayout1);
177: valueLabel.setText(bundle.getMessage("currValSetting")); //NOI18N
178: this .add(valueLabel, new GridBagConstraints(0, 0, 1, 1, 1.0,
179: 0.0, GridBagConstraints.CENTER,
180: GridBagConstraints.HORIZONTAL, new Insets(8, 8, 2, 8),
181: 0, 0));
182: this .add(valueTextField, new GridBagConstraints(0, 1, 1, 1,
183: 1.0, 0.0, GridBagConstraints.WEST,
184: GridBagConstraints.HORIZONTAL, new Insets(0, 8, 4, 8),
185: 0, 0));
186: this .add(tabs, new GridBagConstraints(0, 2, 1, 1, 1.0, 1.0,
187: GridBagConstraints.CENTER, GridBagConstraints.BOTH,
188: new Insets(0, 8, 8, 8), 0, 0));
189: // valueTextField.getDocument().addUndoableEditListener(new UndoableEditListener() {
190: // public void undoableEditHappened(UndoableEditEvent e) {
191: // if (initializing)
192: // return;
193: // firePropertyChange(null, null, null);
194: // if (vbpe != null) {
195: // vbpe.setAsText(valueTextField.getText());
196: // }
197: // }
198: // });
199: }
200: }
|