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.awt.Component;
044: import java.beans.PropertyEditorSupport;
045:
046: import org.netbeans.modules.visualweb.extension.openide.util.Trace;
047:
048: import com.sun.rave.designtime.EventDescriptor;
049:
050: /**
051: *
052: */
053: public class EventPropertyEditor extends PropertyEditorSupport {
054:
055: static final boolean USING_TAGS = false;
056:
057: BeansDesignEvent event;
058: String[] methods;
059: String current;
060:
061: public EventPropertyEditor(BeansDesignEvent event) {
062: this .event = event;
063: assert Trace.trace("insync.live", "EPE: " + event);
064: //setValue(event.getHandlerName());
065: }
066:
067: // load up-to-date list of all sibling beans
068: void loadList() {
069: assert Trace.trace("insync.live", "EPE.loadList");
070: BeansDesignBean bean = (BeansDesignBean) event.getDesignBean();
071: LiveUnit unit = bean.unit;
072: EventDescriptor ed = event.getEventDescriptor();
073: java.lang.reflect.Method m = ed.getListenerMethodDescriptor()
074: .getMethod();
075: methods = unit.sourceUnit.getThisClass().getMethodNames(
076: m.getParameterTypes(), m.getReturnType()).toArray(
077: new String[0]);
078: }
079:
080: void update() {
081: if (USING_TAGS)
082: loadList();
083: }
084:
085: public String getAsText() {
086: String text = current != null ? current + "()" : "";
087: assert Trace.trace("insync.live", "EPE.getAsText: " + text);
088: return text;
089: }
090:
091: public String getJavaInitializationString() {
092: return null;
093: }
094:
095: public String[] getMethods() {
096: loadList(); // always load
097: return methods;
098: }
099:
100: public String[] getTags() {
101: update();
102: return USING_TAGS ? methods : null;
103: }
104:
105: public Object getValue() {
106: Object value = current;
107: assert Trace.trace("insync.live", "EPE.getValue: " + value);
108: return value;
109: }
110:
111: public void setAsText(String text) {
112: assert Trace.trace("insync.live", "EPE.setAsText: " + text);
113: setValue(text);
114: }
115:
116: public void setValue(Object value) {
117: assert Trace.trace("insync.live", "EPE.setValue: " + value);
118: String previous = current;
119: if (value instanceof String) {
120: String text = (String) value;
121: if (text.endsWith("()"))
122: text = text.substring(0, text.length() - 2);
123: if (text.trim().length() == 0)
124: text = "";
125: current = text;
126: } else {
127: current = value != null ? value.toString() : null;
128: }
129: if ((previous == null) != (current == null) || previous != null
130: && !previous.equals(current))
131: firePropertyChange();
132: }
133:
134: public boolean supportsCustomEditor() {
135: return true;
136: }
137:
138: public Component getCustomEditor() {
139: EventEditPanel vbp = new EventEditPanel(this, event);
140: return vbp;
141: }
142: }
|