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;
042:
043: import java.beans.FeatureDescriptor;
044: import java.beans.PropertyEditorSupport;
045: import com.sun.rave.designtime.DesignProperty;
046: import com.sun.rave.designtime.PropertyEditor2;
047: import com.sun.rave.propertyeditors.util.JavaInitializer;
048: import org.netbeans.modules.visualweb.propertyeditors.util.Bundle;
049:
050: import org.openide.explorer.propertysheet.ExPropertyEditor;
051: import org.openide.explorer.propertysheet.PropertyEnv;
052:
053: /**
054: * An abstract base class for property editors. Provides support for getting
055: * and setting of {@link com.sun.rave.designtime.DesignProperty} information
056: * about the property to be edited.
057: *
058: * @author gjmurphy
059: */
060: public abstract class PropertyEditorBase extends PropertyEditorSupport
061: implements PropertyEditor2, ExPropertyEditor {
062:
063: /**
064: * A static {@link com.sun.rave.propertyeditors.util.Bundle} for use by
065: * implementing classes in this package.
066: */
067: protected static final Bundle bundle = Bundle
068: .getBundle(PropertyEditorBase.class);
069:
070: /**
071: * The property's "unset" value. This value will be null until the editor's
072: * DesignProperty has been set.
073: */
074: protected Object unsetValue;
075:
076: PropertyEnv propertyEnv;
077: DesignProperty designProperty;
078:
079: /**
080: * Set the design property for this editor.
081: */
082: public void setDesignProperty(DesignProperty designProperty) {
083: this .designProperty = designProperty;
084: unsetValue = designProperty.getUnsetValue();
085: }
086:
087: /**
088: * Get this editor's design property.
089: */
090: public DesignProperty getDesignProperty() {
091: return this .designProperty;
092: }
093:
094: /**
095: * Returns <code>true</code> is this editor's value can be edited in-line.
096: * If this method returns <code>false</code>, the implementing editor must
097: * provide a custom pop-up editor.
098: */
099: public boolean isEditableAsText() {
100: return true;
101: }
102:
103: /**
104: * Returns the unique property help id that maps to the help topic for this
105: * property editor. By default, returns null. Extending classes that provide
106: * help should override this method.
107: */
108: protected String getPropertyHelpId() {
109: return null;
110: }
111:
112: /**
113: * Used by the NetBeans IDE to pass an object that represents the property's
114: * environment, and that editors may use to send and receive notification of
115: * editing state.
116: */
117: public final void attachEnv(PropertyEnv propertyEnv) {
118: this .propertyEnv = propertyEnv;
119: if (!this .isEditableAsText())
120: propertyEnv.getFeatureDescriptor().setValue(
121: "canEditAsText", Boolean.FALSE);
122: String propertyHelpId = this .getPropertyHelpId();
123: if (propertyHelpId != null) {
124: FeatureDescriptor descriptor = propertyEnv
125: .getFeatureDescriptor();
126: descriptor.setValue(ExPropertyEditor.PROPERTY_HELP_ID,
127: propertyHelpId);
128: }
129: }
130:
131: PropertyEnv getEnv() {
132: return this .propertyEnv;
133: }
134:
135: /**
136: * Returns a string that contains Java code for initializing the property
137: * with this editor's current value. This method defers to {@link
138: * com.sun.rave.propertyeditors.util.JavaInitializer#toJavaInitializationString(Object)}.
139: */
140: public String getJavaInitializationString() {
141: return JavaInitializer.toJavaInitializationString(getValue());
142: }
143:
144: }
|