diff -r cb6bcdf0c6ce o.n.core/src/org/netbeans/beaninfo/editors/ObjectEditor.java --- a/o.n.core/src/org/netbeans/beaninfo/editors/ObjectEditor.java Thu Jun 10 14:53:23 2010 +0200 +++ b/o.n.core/src/org/netbeans/beaninfo/editors/ObjectEditor.java Wed Dec 22 11:45:18 2010 +0100 @@ -85,7 +85,7 @@ * Either Boolean.TRUE or a String, in such case the string represents * human readable name of the value. */ - private static final String PROP_NULL = "nullValue"; // NOI18N + /*package*/ static final String PROP_NULL = "nullValue"; // NOI18N /** Name of the custom property that can be passed in PropertyEnv. * A lookup to use to query for results. */ diff -r cb6bcdf0c6ce o.n.core/src/org/netbeans/beaninfo/editors/StringEditor.java --- a/o.n.core/src/org/netbeans/beaninfo/editors/StringEditor.java Thu Jun 10 14:53:23 2010 +0200 +++ b/o.n.core/src/org/netbeans/beaninfo/editors/StringEditor.java Wed Dec 22 11:45:18 2010 +0100 @@ -51,11 +51,11 @@ import org.openide.explorer.propertysheet.PropertyEnv; import java.beans.FeatureDescriptor; import org.openide.nodes.Node; +import org.openide.util.NbBundle; - -/** A property editor for String class. +/** + * A property editor for String class. * @author Ian Formanek -* @version 1.00, 18 Sep, 1998 */ public class StringEditor extends PropertyEditorSupport implements ExPropertyEditor { @@ -68,33 +68,52 @@ return (editable); } + @Override + public String getAsText() { + Object value = getValue(); + if (value != null) { + return value.toString(); + } else { + return nullValue != null ? nullValue : NbBundle.getMessage(StringEditor.class, "CTL_NullValue"); + } + } + /** sets new value */ + @Override public void setAsText(String s) { if ( "null".equals( s ) && getValue() == null ) // NOI18N return; + if (nullValue != null && nullValue.equals (s)) { + setValue (null); + return; + } + setValue(s); } + @Override public String getJavaInitializationString () { String s = (String) getValue (); return "\"" + toAscii(s) + "\""; // NOI18N } + @Override public boolean supportsCustomEditor () { return customEd; } + @Override public java.awt.Component getCustomEditor () { Object val = getValue(); String s = ""; // NOI18N if (val != null) { s = val instanceof String ? (String) val : val.toString(); } - return new StringCustomEditor (s, isEditable(), oneline, instructions, this, env); // NOI18N + return new StringCustomEditor (s, isEditable(), oneline, instructions, this, env); } private static String toAscii(String str) { - StringBuffer buf = new StringBuffer(str.length() * 6); // x -> \u1234 + StringBuilder buf = new StringBuilder(str.length() * 6); // x -> \u1234 char[] chars = str.toCharArray(); for (int i = 0; i < chars.length; i++) { char c = chars[i]; @@ -126,12 +145,18 @@ private boolean oneline=false; private boolean customEd=true; private PropertyEnv env; + /** null or name to use for null value */ + private String nullValue; // bugfix# 9219 added attachEnv() method checking if the user canWrite in text box + @Override public void attachEnv(PropertyEnv env) { this.env = env; - FeatureDescriptor desc = env.getFeatureDescriptor(); + readEnv(env.getFeatureDescriptor()); + } + + /*@VisibleForTesting*/ void readEnv (FeatureDescriptor desc) { if (desc instanceof Node.Property){ Node.Property prop = (Node.Property)desc; editable = prop.canWrite(); @@ -139,8 +164,18 @@ //editor instructions = (String) prop.getValue ("instructions"); //NOI18N oneline = Boolean.TRUE.equals (prop.getValue ("oneline")); //NOI18N - customEd = !Boolean.TRUE.equals (prop.getValue + customEd = !Boolean.TRUE.equals (prop.getValue ("suppressCustomEditor")); //NOI18N } + Object obj = desc.getValue(ObjectEditor.PROP_NULL); + if (Boolean.TRUE.equals(obj)) { + nullValue = NbBundle.getMessage(StringEditor.class, "CTL_NullValue"); + } else { + if (obj instanceof String) { + nullValue = (String)obj; + } else { + nullValue = null; + } + } } } diff -r cb6bcdf0c6ce o.n.core/test/unit/src/org/netbeans/beaninfo/editors/StringEditorTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/o.n.core/test/unit/src/org/netbeans/beaninfo/editors/StringEditorTest.java Wed Dec 22 11:45:18 2010 +0100 @@ -0,0 +1,114 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ + +package org.netbeans.beaninfo.editors; + +import java.beans.PropertyEditor; +import java.beans.PropertyEditorManager; +import java.lang.reflect.InvocationTargetException; +import junit.framework.TestCase; +import org.openide.nodes.Node; + +/** + * + * @author rkubacki + */ +public class StringEditorTest extends TestCase { + static { + PropertyEditorManager.registerEditor (String.class, StringEditor.class); + } + + public void testNullValueSupport() throws Exception { + NP np = new NP(); + String defaultValue = ""; + String customValue = "Hello world!"; + np.setValue(ObjectEditor.PROP_NULL, defaultValue); + + PropertyEditor p = np.getPropertyEditor(); + assertNotNull("There is some editor", p); + assertEquals("It is StringEditor", StringEditor.class, p.getClass()); + ((StringEditor) p).readEnv(np); + + p.setValue(null); + String value = (String)p.getValue (); + assertNull(value); + assertEquals(defaultValue, p.getAsText()); + + p.setValue(customValue); + value = (String)p.getValue (); + assertEquals(customValue, value); + assertEquals(customValue, p.getAsText()); + + np.setValue(ObjectEditor.PROP_NULL, Boolean.TRUE); + ((StringEditor) p).readEnv(np); + p.setValue(null); + value = (String)p.getValue (); + assertNull(value); + assertFalse("we've better than default 'null' string", "null".equals(defaultValue)); + } + + class NP extends Node.Property { + public String value; + + public NP () { + super (String.class); + } + + public @Override void setValue(String val) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { + value = val; + } + + public @Override String getValue() throws IllegalAccessException, InvocationTargetException { + return value; + } + + public @Override boolean canWrite() { + return true; + } + + public @Override boolean canRead() { + return true; + } + } +} diff -r cb6bcdf0c6ce openide.explorer/src/org/openide/explorer/doc-files/propertyViewCustomization.html --- a/openide.explorer/src/org/openide/explorer/doc-files/propertyViewCustomization.html Thu Jun 10 14:53:23 2010 +0200 +++ b/openide.explorer/src/org/openide/explorer/doc-files/propertyViewCustomization.html Wed Dec 22 11:45:18 2010 +0100 @@ -210,6 +210,11 @@ String custom editor + nullValue + Boolean, String + Either Boolean.TRUE or a String, in such case the string represents human readable name of the null value + + oneline Boolean Instructs the property editor that the custom editor should present