This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 193252
Collapse All | Expand All

(-)a/o.n.core/src/org/netbeans/beaninfo/editors/ObjectEditor.java (-1 / +1 lines)
Lines 85-91 Link Here
85
     * Either Boolean.TRUE or a String, in such case the string represents
85
     * Either Boolean.TRUE or a String, in such case the string represents
86
     * human readable name of the value.
86
     * human readable name of the value.
87
     */
87
     */
88
    private static final String PROP_NULL = "nullValue"; // NOI18N
88
    /*package*/ static final String PROP_NULL = "nullValue"; // NOI18N
89
    /** Name of the custom property that can be passed in PropertyEnv. 
89
    /** Name of the custom property that can be passed in PropertyEnv. 
90
     * A lookup to use to query for results.
90
     * A lookup to use to query for results.
91
     */
91
     */
(-)a/o.n.core/src/org/netbeans/beaninfo/editors/StringEditor.java (-7 / +42 lines)
Lines 51-61 Link Here
51
import org.openide.explorer.propertysheet.PropertyEnv;
51
import org.openide.explorer.propertysheet.PropertyEnv;
52
import java.beans.FeatureDescriptor;
52
import java.beans.FeatureDescriptor;
53
import org.openide.nodes.Node;
53
import org.openide.nodes.Node;
54
import org.openide.util.NbBundle;
54
55
55
56
/**
56
/** A property editor for String class.
57
 * A property editor for String class.
57
* @author   Ian Formanek
58
* @author   Ian Formanek
58
* @version  1.00, 18 Sep, 1998
59
*/
59
*/
60
public class StringEditor extends PropertyEditorSupport implements ExPropertyEditor
60
public class StringEditor extends PropertyEditorSupport implements ExPropertyEditor
61
{
61
{
Lines 68-100 Link Here
68
        return (editable);
68
        return (editable);
69
    }
69
    }
70
                
70
                
71
    @Override
72
    public String getAsText() {
73
        Object value = getValue();
74
        if (value != null) {
75
            return value.toString();
76
        } else {
77
            return nullValue != null ? nullValue : NbBundle.getMessage(StringEditor.class, "CTL_NullValue");
78
        }
79
    }
80
71
    /** sets new value */
81
    /** sets new value */
82
    @Override
72
    public void setAsText(String s) {
83
    public void setAsText(String s) {
73
        if ( "null".equals( s ) && getValue() == null ) // NOI18N
84
        if ( "null".equals( s ) && getValue() == null ) // NOI18N
74
            return;
85
            return;
86
        if (nullValue != null && nullValue.equals (s)) {
87
            setValue (null);
88
            return;
89
        }
90
75
        setValue(s);
91
        setValue(s);
76
    }
92
    }
77
93
94
    @Override
78
    public String getJavaInitializationString () {
95
    public String getJavaInitializationString () {
79
        String s = (String) getValue ();
96
        String s = (String) getValue ();
80
        return "\"" + toAscii(s) + "\""; // NOI18N
97
        return "\"" + toAscii(s) + "\""; // NOI18N
81
    }
98
    }
82
99
100
    @Override
83
    public boolean supportsCustomEditor () {
101
    public boolean supportsCustomEditor () {
84
        return customEd;
102
        return customEd;
85
    }
103
    }
86
104
105
    @Override
87
    public java.awt.Component getCustomEditor () {
106
    public java.awt.Component getCustomEditor () {
88
        Object val = getValue();
107
        Object val = getValue();
89
        String s = ""; // NOI18N
108
        String s = ""; // NOI18N
90
        if (val != null) {
109
        if (val != null) {
91
            s = val instanceof String ? (String) val : val.toString();
110
            s = val instanceof String ? (String) val : val.toString();
92
        }
111
        }
93
        return new StringCustomEditor (s, isEditable(), oneline, instructions, this, env); // NOI18N
112
        return new StringCustomEditor (s, isEditable(), oneline, instructions, this, env);
94
    }
113
    }
95
114
96
    private static String toAscii(String str) {
115
    private static String toAscii(String str) {
97
        StringBuffer buf = new StringBuffer(str.length() * 6); // x -> \u1234
116
        StringBuilder buf = new StringBuilder(str.length() * 6); // x -> \u1234
98
        char[] chars = str.toCharArray();
117
        char[] chars = str.toCharArray();
99
        for (int i = 0; i < chars.length; i++) {
118
        for (int i = 0; i < chars.length; i++) {
100
            char c = chars[i];
119
            char c = chars[i];
Lines 126-137 Link Here
126
    private boolean oneline=false;
145
    private boolean oneline=false;
127
    private boolean customEd=true;
146
    private boolean customEd=true;
128
    private PropertyEnv env;
147
    private PropertyEnv env;
148
    /** null or name to use for null value */
149
    private String nullValue;
129
150
130
    // bugfix# 9219 added attachEnv() method checking if the user canWrite in text box 
151
    // bugfix# 9219 added attachEnv() method checking if the user canWrite in text box 
152
    @Override
131
    public void attachEnv(PropertyEnv env) {
153
    public void attachEnv(PropertyEnv env) {
132
        this.env = env;
154
        this.env = env;
133
155
134
        FeatureDescriptor desc = env.getFeatureDescriptor();
156
        readEnv(env.getFeatureDescriptor());
157
    }
158
159
    /*@VisibleForTesting*/ void readEnv (FeatureDescriptor desc) {
135
        if (desc instanceof Node.Property){
160
        if (desc instanceof Node.Property){
136
            Node.Property prop = (Node.Property)desc;
161
            Node.Property prop = (Node.Property)desc;
137
            editable = prop.canWrite();
162
            editable = prop.canWrite();
Lines 139-146 Link Here
139
            //editor
164
            //editor
140
            instructions = (String) prop.getValue ("instructions"); //NOI18N
165
            instructions = (String) prop.getValue ("instructions"); //NOI18N
141
            oneline = Boolean.TRUE.equals (prop.getValue ("oneline")); //NOI18N
166
            oneline = Boolean.TRUE.equals (prop.getValue ("oneline")); //NOI18N
142
            customEd = !Boolean.TRUE.equals (prop.getValue 
167
            customEd = !Boolean.TRUE.equals (prop.getValue
143
                ("suppressCustomEditor")); //NOI18N
168
                ("suppressCustomEditor")); //NOI18N
144
        }
169
        }
170
        Object obj = desc.getValue(ObjectEditor.PROP_NULL);
171
        if (Boolean.TRUE.equals(obj)) {
172
            nullValue = NbBundle.getMessage(StringEditor.class, "CTL_NullValue");
173
        } else {
174
            if (obj instanceof String) {
175
                nullValue = (String)obj;
176
            } else {
177
                nullValue = null;
178
            }
179
        }
145
    }
180
    }
146
}
181
}
(-)cb6bcdf0c6ce (+114 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * Contributor(s):
28
 *
29
 * The Original Software is NetBeans. The Initial Developer of the Original
30
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
31
 * Microsystems, Inc. All Rights Reserved.
32
 *
33
 * If you wish your version of this file to be governed by only the CDDL
34
 * or only the GPL Version 2, indicate your decision by adding
35
 * "[Contributor] elects to include this software in this distribution
36
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
37
 * single choice of license, a recipient has the option to distribute
38
 * your version of this file under either the CDDL, the GPL Version 2 or
39
 * to extend the choice of license to its licensees as provided above.
40
 * However, if you add GPL Version 2 code and therefore, elected the GPL
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
43
 */
44
45
package org.netbeans.beaninfo.editors;
46
47
import java.beans.PropertyEditor;
48
import java.beans.PropertyEditorManager;
49
import java.lang.reflect.InvocationTargetException;
50
import junit.framework.TestCase;
51
import org.openide.nodes.Node;
52
53
/**
54
 *
55
 * @author rkubacki
56
 */
57
public class StringEditorTest extends TestCase {
58
    static {
59
        PropertyEditorManager.registerEditor (String.class, StringEditor.class);
60
    }
61
62
    public void testNullValueSupport() throws Exception {
63
        NP np = new NP();
64
        String defaultValue = "<null value>";
65
        String customValue = "Hello world!";
66
        np.setValue(ObjectEditor.PROP_NULL, defaultValue);
67
        
68
        PropertyEditor p = np.getPropertyEditor();
69
        assertNotNull("There is some editor", p);
70
        assertEquals("It is StringEditor", StringEditor.class, p.getClass());
71
        ((StringEditor) p).readEnv(np);
72
        
73
        p.setValue(null);
74
        String value = (String)p.getValue ();
75
        assertNull(value);
76
        assertEquals(defaultValue, p.getAsText());
77
78
        p.setValue(customValue);
79
        value = (String)p.getValue ();
80
        assertEquals(customValue, value);
81
        assertEquals(customValue, p.getAsText());
82
83
        np.setValue(ObjectEditor.PROP_NULL, Boolean.TRUE);
84
        ((StringEditor) p).readEnv(np);
85
        p.setValue(null);
86
        value = (String)p.getValue ();
87
        assertNull(value);
88
        assertFalse("we've better than default 'null' string", "null".equals(defaultValue));
89
    }
90
91
    class NP extends Node.Property<String> {
92
        public String value;
93
        
94
        public NP () {
95
            super (String.class);
96
        }
97
98
        public @Override void setValue(String val) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
99
            value = val;
100
        }
101
102
        public @Override String getValue() throws IllegalAccessException, InvocationTargetException {
103
            return value;
104
        }
105
106
        public @Override boolean canWrite() {
107
            return true;
108
        }
109
110
        public @Override boolean canRead() {
111
            return true;
112
        }
113
    }
114
}
(-)a/openide.explorer/src/org/openide/explorer/doc-files/propertyViewCustomization.html (+5 lines)
Lines 210-215 Link Here
210
                String custom editor</TD>
210
                String custom editor</TD>
211
        </TR>
211
        </TR>
212
        <TR>
212
        <TR>
213
            <TD> nullValue</TD>
214
            <TD> Boolean, String </TD>
215
            <TD> Either Boolean.TRUE or a String, in such case the string represents human readable name of the null value</TD>
216
        </TR>
217
        <TR>
213
            <TD>oneline</TD>
218
            <TD>oneline</TD>
214
            <TD>Boolean</TD>
219
            <TD>Boolean</TD>
215
            <TD>Instructs the property editor that the custom editor should present
220
            <TD>Instructs the property editor that the custom editor should present

Return to bug 193252