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.insync.live;
042:
043: import java.beans.PropertyDescriptor;
044: import javax.el.MethodExpression;
045:
046: import javax.faces.el.MethodBinding;
047:
048: import org.netbeans.modules.visualweb.extension.openide.util.Trace;
049:
050: import com.sun.rave.designtime.Constants;
051: import com.sun.rave.designtime.EventDescriptor;
052: import com.sun.faces.util.ConstantMethodBinding;
053:
054: /**
055: * A specialized event for MethodBinding based events that coordinates with a MethodBindDesignProperty
056: *
057: * @author Carl Quinn
058: */
059: public class MethodBindDesignEvent extends BeansDesignEvent {
060:
061: MethodBindDesignProperty reference; // cross reference to the shadow MB live property
062:
063: /**
064: * @param ed
065: * @param lbean
066: * @param reference
067: */
068: public MethodBindDesignEvent(EventDescriptor ed,
069: BeansDesignBean lbean, MethodBindDesignProperty reference) {
070: super (ed, lbean);
071: this .reference = reference;
072: reference.setEventReference(this );
073: assert Trace.trace("insync.live", "FLE event:" + reference);
074: }
075:
076: /*
077: * Set the event handler method as an unqualified name string
078: * @see com.sun.rave.designtime.DesignEvent#getHandlerName()
079: */
080: public boolean setHandlerName(String methodName) {
081: if (super .setHandlerName(methodName)) {
082: reference.initLive();
083: return true;
084: }
085: return false;
086: }
087:
088: protected void initEvent(String handlerName) {
089: super .initEvent(handlerName);
090: if (reference != null) {
091: // This looks HACKed, but I am just not sure
092: // I cloned this code from BeansDesignBean.newDesignEvent since when I was created
093: // the property may not have existed, IE not set, on the actual bean
094: Object possiblePropertyDescriptor = descriptor
095: .getEventSetDescriptor()
096: .getValue(
097: Constants.EventSetDescriptor.BINDING_PROPERTY);
098: if (possiblePropertyDescriptor instanceof PropertyDescriptor) {
099: PropertyDescriptor propertyDescriptor = (PropertyDescriptor) possiblePropertyDescriptor;
100: if (MethodBindDesignProperty
101: .isMethodBindingProperty(propertyDescriptor)) {
102: reference.property = ((BeansDesignBean) liveBean).bean
103: .getProperty(propertyDescriptor.getName());
104: }
105: }
106: }
107: }
108:
109: /*
110: * @see com.sun.rave.designtime.DesignEvent#removeHandler()
111: */
112: public boolean removeHandler() {
113: if (super .removeHandler()) {
114: reference.unset();
115: reference.initLive();
116: return true;
117: }
118: return false;
119: }
120:
121: /**
122: * @param value
123: */
124: void propertyChanged(Object value) {
125: if (event != null
126: && ((value instanceof ConstantMethodBinding) || (!(value instanceof MethodBinding) && !(value instanceof MethodExpression)))) {
127: ((BeansDesignBean) liveBean).bean.releaseEventSet(event
128: .getEventSet());
129: event = null;
130: }
131: }
132:
133: }
|