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.propertyeditors.binding.data;
042:
043: import java.awt.Component;
044: import com.sun.rave.designtime.DesignBean;
045: import com.sun.rave.designtime.DesignProperty;
046: import com.sun.rave.designtime.impl.BasicCustomizer2;
047: import com.sun.rave.designtime.faces.FacesDesignProperty;
048: import org.netbeans.modules.visualweb.propertyeditors.binding.BindingTargetCallback;
049: import org.netbeans.modules.visualweb.propertyeditors.util.Bundle;
050: import com.sun.rave.designtime.Result;
051:
052: public class DataBindingCustomizer extends BasicCustomizer2 implements
053: BindingTargetCallback {
054:
055: private static final Bundle bundle = Bundle
056: .getBundle(DataBindingCustomizer.class);
057:
058: public DataBindingCustomizer(String propName, Class[] panelClasses,
059: boolean showExpr, String dialogTitle) {
060: super (null, dialogTitle, null, null); //NOI18N
061: this .propName = propName;
062: this .panelClasses = panelClasses;
063: this .showExpr = showExpr;
064: // The first panel must be always Bind to dataprovider (by design)
065: // It can be either BIND_OPTIONS_TO_DATAPROVIDER or BIND_VALUE_TO_DATAPROVIDER
066: if (panelClasses[0] == DataBindingHelper.BIND_OPTIONS_TO_DATAPROVIDER) {
067: setHelpKey("projrave_ui_elements_dialogs_bindtodata_list_db");
068: } else { //BIND_VALUE_TO_DATAPROVIDER
069: setHelpKey("projrave_ui_elements_dialogs_bindtodata_simple_db");
070: }
071: }
072:
073: public DataBindingCustomizer(String propName, Class[] panelClasses,
074: boolean showExpr) {
075: this (propName, panelClasses, showExpr, bundle
076: .getMessage("bindToData"));
077: }
078:
079: public DataBindingCustomizer(String propName, Class[] panelClasses) {
080: this (propName, panelClasses, false, bundle
081: .getMessage("bindToData"));
082: }
083:
084: public void refresh() {
085: }
086:
087: public void setNewExpressionText(String newExpr) {
088: this .newExpression = newExpr;
089: if (newExpression != null) {
090: if (!newExpression.trim().equals(originalValueSource)) {
091: setModified(true);
092: } else {
093: setModified(false);
094: }
095: } else if (originalValueSource != null) {
096: setModified(true);
097: } else {
098: setModified(false);
099: }
100: }
101:
102: String propName;
103: DesignProperty prop;
104: FacesDesignProperty fprop;
105: String newExpression = null;
106: Class[] panelClasses = null;
107: boolean showExpr = true;
108:
109: Object originalValue;
110: String originalValueSource;
111:
112: protected TabbedDataBindingPanel tabbedPanel = null;
113:
114: public Component getCustomizerPanel(DesignBean designBean) {
115: setDisplayName(bundle.getMessage("bindToData") + " - "
116: + designBean.getInstanceName());
117: this .designBean = designBean;
118: this .prop = designBean.getProperty(propName);
119: if (prop instanceof FacesDesignProperty) {
120: fprop = (FacesDesignProperty) prop;
121: if (fprop.isBound() && fprop.getValueBinding() != null) {
122: this .newExpression = fprop.getValueBinding()
123: .getExpressionString();
124: }
125: }
126: if (prop instanceof FacesDesignProperty) {
127: FacesDesignProperty facesProp = (FacesDesignProperty) prop;
128: if (facesProp.isBound()) {
129: originalValueSource = facesProp.getValueSource();
130: if (originalValueSource != null)
131: originalValueSource = originalValueSource.trim();
132: } else {
133: originalValue = facesProp.getValue();
134: }
135: }
136: tabbedPanel = new TabbedDataBindingPanel(this , prop,
137: panelClasses, showExpr); //NOI18N
138: return tabbedPanel;
139: }
140:
141: public boolean isApplyCapable() {
142: return true;
143: }
144:
145: public Result applyChanges() {
146: if (isModified()) {
147: // Do not clear the original values or unset the property
148: // if the new value binding is null or empty - Winston
149: if (newExpression == null
150: || newExpression.trim().equals("")) {
151: if (originalValueSource != originalValue) {
152: prop.unset();
153: } else {
154: prop.setValue(originalValue);
155: }
156: } else {
157: prop.setValueSource(newExpression);
158: }
159: }
160: return super.applyChanges();
161: }
162: }
|