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 java.awt.Component;
044: import java.beans.PropertyEditorSupport;
045: import javax.faces.application.Application;
046: import javax.faces.el.ValueBinding;
047: import com.sun.rave.designtime.DesignProperty;
048: import com.sun.rave.designtime.faces.FacesDesignContext;
049: import com.sun.rave.designtime.faces.FacesDesignProperty;
050: import com.sun.rave.designtime.faces.FacesBindingPropertyEditor;
051:
052: public class ValueBindingPropertyEditor extends PropertyEditorSupport
053: implements FacesBindingPropertyEditor {
054:
055: //------------------------------------------------------------------------------- PropertyEditor
056:
057: public Object getValue() {
058: Object value = super .getValue();
059: //System.err.println("VBPE.getValue value:" + value + " " + System.currentTimeMillis());
060: return value;
061: }
062:
063: public void setValue(Object value) {
064: Object v = getValue();
065: // if ((value == v) ||
066: // (value != null && value.equals(v)) ||
067: // (value instanceof ValueBinding && ((ValueBinding)value).getExpressionString().equals(v)) ||
068: // (v instanceof ValueBinding && ((ValueBinding)v).getExpressionString().equals(value)) ||
069: // (value instanceof ValueBinding && v instanceof ValueBinding &&
070: // ((ValueBinding)value).getExpressionString().equals(((ValueBinding)v).getExpressionString()))) {
071: // return;
072: // }
073: //System.err.println("VBPE.setValue value:" + value + " " + System.currentTimeMillis());
074: this .quiet = true;
075: if (facesDesignProperty != null
076: && facesDesignProperty.isBound()) {
077: super .setValue(facesDesignProperty.getValueBinding());
078: } else {
079: super .setValue(value);
080: }
081: this .quiet = false;
082: }
083:
084: protected void super SetValue(Object value) {
085:
086: super .setValue(value);
087: }
088:
089: protected boolean quiet = false;
090:
091: public void firePropertyChange() {
092: if (quiet) {
093: return;
094: }
095: super .firePropertyChange();
096: }
097:
098: public String getAsText() {
099: Object value = getValue();
100: if (value instanceof ValueBinding) {
101: return ((ValueBinding) value).getExpressionString();
102: } else if (facesDesignProperty != null
103: && facesDesignProperty.isBound()) {
104: return facesDesignProperty.getValueBinding()
105: .getExpressionString();
106: }
107: return value != null ? value.toString() : ""; //NOI18N
108: }
109:
110: public void setAsText(String text) throws IllegalArgumentException {
111: if (text.startsWith("#{")) { //NOI18N
112: FacesDesignContext fctx = (FacesDesignContext) liveProperty
113: .getDesignBean().getDesignContext();
114: Application app = fctx.getFacesContext().getApplication();
115: super .setValue(app.createValueBinding(text));
116: } else if (text.length() > 0) {
117: super .setValue(text);
118: } else {
119: super .setValue(null);
120: }
121: }
122:
123: public String getJavaInitializationString() {
124: return "\"" + getAsText() + "\""; //NOI18N
125: }
126:
127: public boolean supportsCustomEditor() {
128: return true;
129: }
130:
131: public Component getCustomEditor() {
132: ValueBindingPanel vbp = new ValueBindingPanel(this ,
133: liveProperty);
134: return vbp;
135: }
136:
137: //--------------------------------------------------------------------------- PropertyEditor2
138:
139: // use only for reference and lookup
140:
141: protected FacesDesignProperty facesDesignProperty;
142: protected DesignProperty liveProperty;
143:
144: public void setDesignProperty(DesignProperty lp) {
145: this .liveProperty = lp;
146: this .facesDesignProperty = lp instanceof FacesDesignProperty ? (FacesDesignProperty) lp
147: : null;
148: }
149: }
|