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 218300
Collapse All | Expand All

(-)a/cnd/src/org/netbeans/modules/cnd/builds/package-info.java (+5 lines)
Line 0 Link Here
1
@PropertyEditorSearchPath
2
package org.netbeans.modules.cnd.builds;
3
4
import org.openide.nodes.PropertyEditorSearchPath;
5
(-)a/cnd/src/org/netbeans/modules/cnd/settings/MakeSettings.java (-11 lines)
Lines 43-49 Link Here
43
 */
43
 */
44
package org.netbeans.modules.cnd.settings;
44
package org.netbeans.modules.cnd.settings;
45
45
46
import java.beans.PropertyEditorManager;
47
import java.io.File;
46
import java.io.File;
48
import java.util.ResourceBundle;
47
import java.util.ResourceBundle;
49
import org.netbeans.modules.cnd.utils.CndUtils;
48
import org.netbeans.modules.cnd.utils.CndUtils;
Lines 77-83 Link Here
77
    protected void initialize() {
76
    protected void initialize() {
78
77
79
        super.initialize();
78
        super.initialize();
80
        registerPropertyEditors();
81
79
82
        setReuseOutput(false);
80
        setReuseOutput(false);
83
        setSaveAll(true);
81
        setSaveAll(true);
Lines 107-121 Link Here
107
        return bundle.getString(s);
105
        return bundle.getString(s);
108
    }
106
    }
109
107
110
    private void registerPropertyEditors() {
111
        String[] searchPath = PropertyEditorManager.getEditorSearchPath();
112
        String[] newSP = new String[searchPath.length + 1];
113
        System.arraycopy(searchPath, 0, newSP, 0, searchPath.length);
114
115
        newSP[searchPath.length] = "org.netbeans.modules.cnd.builds"; // NOI18N
116
        PropertyEditorManager.setEditorSearchPath(newSP);
117
    }
118
119
    /**
108
    /**
120
     *  Getter for the default build directory. This should be a relative path
109
     *  Getter for the default build directory. This should be a relative path
121
     *  from the filesystem of the current
110
     *  from the filesystem of the current
(-)a/core.execution/manifest.mf (-1 lines)
Lines 1-7 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.core.execution/1
2
OpenIDE-Module: org.netbeans.core.execution/1
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/core/execution/resources/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/core/execution/resources/Bundle.properties
4
OpenIDE-Module-Install: org/netbeans/core/execution/Install.class
5
OpenIDE-Module-Provides: org.openide.execution.ExecutionEngine
4
OpenIDE-Module-Provides: org.openide.execution.ExecutionEngine
6
AutoUpdate-Essential-Module: true
5
AutoUpdate-Essential-Module: true
7
OpenIDE-Module-Specification-Version: 1.29
6
OpenIDE-Module-Specification-Version: 1.29
(-)a/core.execution/src/org/netbeans/core/execution/Install.java (-42 / +30 lines)
Lines 57-67 Link Here
57
import java.beans.Introspector;
57
import java.beans.Introspector;
58
import java.beans.PropertyChangeEvent;
58
import java.beans.PropertyChangeEvent;
59
import java.beans.PropertyChangeListener;
59
import java.beans.PropertyChangeListener;
60
import java.beans.PropertyEditorManager;
61
import java.util.ArrayList;
60
import java.util.ArrayList;
62
import java.util.Arrays;
61
import java.util.Arrays;
63
import java.util.Collection;
62
import java.util.Collection;
64
import java.util.Collections;
63
import java.util.Collections;
64
import java.util.concurrent.Callable;
65
import java.util.logging.Level;
65
import java.util.logging.Level;
66
import java.util.logging.LogRecord;
66
import java.util.logging.LogRecord;
67
import java.util.logging.Logger;
67
import java.util.logging.Logger;
Lines 86-92 Link Here
86
import org.openide.explorer.ExplorerManager;
86
import org.openide.explorer.ExplorerManager;
87
import org.openide.explorer.ExplorerUtils;
87
import org.openide.explorer.ExplorerUtils;
88
import org.openide.explorer.view.ListView;
88
import org.openide.explorer.view.ListView;
89
import org.openide.modules.ModuleInstall;
89
import org.openide.modules.OnStart;
90
import org.openide.modules.OnStop;
90
import org.openide.nodes.AbstractNode;
91
import org.openide.nodes.AbstractNode;
91
import org.openide.nodes.Children;
92
import org.openide.nodes.Children;
92
import org.openide.nodes.Node;
93
import org.openide.nodes.Node;
Lines 106-121 Link Here
106
 * Also adds/removes specific beaninfo and property editor search paths.
107
 * Also adds/removes specific beaninfo and property editor search paths.
107
 * @author Jesse Glick
108
 * @author Jesse Glick
108
 */
109
 */
109
public class Install extends ModuleInstall {
110
@OnStart
111
public class Install implements Runnable {
110
    
112
    
111
    private static final String BEANINFO_PATH
113
    private static final String BEANINFO_PATH
112
            = "org.netbeans.core.execution.beaninfo"; // NOI18N
114
            = "org.netbeans.core.execution.beaninfo"; // NOI18N
113
    private static final String EDITOR_PATH
114
            = "org.netbeans.core.execution.beaninfo.editors"; // NOI18N
115
115
116
    private static final Logger LOG = Logger.getLogger(Install.class.getName());
116
    private static final Logger LOG = Logger.getLogger(Install.class.getName());
117
    
117
    
118
    public @Override void restored() {
118
    public @Override void run() {
119
        TopSecurityManager.register(SecMan.DEFAULT);
119
        TopSecurityManager.register(SecMan.DEFAULT);
120
        
120
        
121
        // Add beaninfo search path.
121
        // Add beaninfo search path.
Lines 127-172 Link Here
127
            Introspector.setBeanInfoSearchPath(
127
            Introspector.setBeanInfoSearchPath(
128
                    paths.toArray(new String[0]));
128
                    paths.toArray(new String[0]));
129
        }
129
        }
130
    }
131
    
132
    @OnStop
133
    public static final class Down implements Runnable {
130
        
134
        
131
        // Add property editor search path.
135
        public @Override void run() {
132
        sp = PropertyEditorManager.getEditorSearchPath();
136
            showPendingTasks();
133
        paths = Arrays.asList(sp);
137
134
        if(!paths.contains(EDITOR_PATH)) {
138
            TopSecurityManager.unregister(SecMan.DEFAULT);
135
            paths = new ArrayList<String>(paths);
139
136
            paths.add(EDITOR_PATH);
140
            // Remove beaninfo search path.
137
            PropertyEditorManager.setEditorSearchPath(
141
            String[] sp = Introspector.getBeanInfoSearchPath();
138
                    paths.toArray(new String[0]));
142
            java.util.List<String> paths = Arrays.asList(sp);
143
            if(paths.contains(BEANINFO_PATH)) {
144
                paths = new ArrayList<String>(paths);
145
                paths.remove(BEANINFO_PATH);
146
                Introspector.setBeanInfoSearchPath(
147
                        paths.toArray(new String[0]));
148
            }
139
        }
149
        }
140
    }
150
    }
141
    
151
142
    public @Override void uninstalled() {
152
    @OnStop
143
        showPendingTasks();
153
    public static final class Closing implements Callable {
144
        
154
        @Override
145
        TopSecurityManager.unregister(SecMan.DEFAULT);
155
        public Boolean call() throws Exception {
146
        
156
            return showPendingTasks();
147
        // Remove beaninfo search path.
148
        String[] sp = Introspector.getBeanInfoSearchPath();
149
        java.util.List<String> paths = Arrays.asList(sp);
150
        if(paths.contains(BEANINFO_PATH)) {
151
            paths = new ArrayList<String>(paths);
152
            paths.remove(BEANINFO_PATH);
153
            Introspector.setBeanInfoSearchPath(
154
                    paths.toArray(new String[0]));
155
        }
157
        }
156
        
157
        // Remove property editor seach path.
158
        sp = PropertyEditorManager.getEditorSearchPath();
159
        paths = Arrays.asList(sp);
160
        if(paths.contains(EDITOR_PATH)) {
161
            paths = new ArrayList<String>(paths);
162
            paths.remove(EDITOR_PATH);
163
            PropertyEditorManager.setEditorSearchPath(
164
                    paths.toArray(new String[0]));
165
        }
166
    }
167
    
168
    public @Override boolean closing() {
169
        return showPendingTasks();
170
    }
158
    }
171
    
159
    
172
    /** A class that server as a pending dialog manager.
160
    /** A class that server as a pending dialog manager.
(-)a/core.execution/src/org/netbeans/core/execution/beaninfo/editors/package-info.java (+5 lines)
Line 0 Link Here
1
@PropertyEditorSearchPath
2
package org.netbeans.core.execution.beaninfo.editors;
3
4
import org.openide.nodes.PropertyEditorSearchPath;
5
(-)a/o.n.core/src/org/netbeans/beaninfo/editors/BoolEditor.java (+2 lines)
Lines 50-55 Link Here
50
package org.netbeans.beaninfo.editors;
50
package org.netbeans.beaninfo.editors;
51
import java.beans.*;
51
import java.beans.*;
52
import org.openide.explorer.propertysheet.ExPropertyEditor;
52
import org.openide.explorer.propertysheet.ExPropertyEditor;
53
import org.openide.nodes.PropertyEditorRegistration;
53
import org.openide.util.NbBundle;
54
import org.openide.util.NbBundle;
54
/** Replacement editor for boolean primitive values which supports
55
/** Replacement editor for boolean primitive values which supports
55
 *  internationalization and alternate string values that
56
 *  internationalization and alternate string values that
Lines 63-68 Link Here
63
 *
64
 *
64
 * @author  Tim Boudreau
65
 * @author  Tim Boudreau
65
 */
66
 */
67
@PropertyEditorRegistration(targetType=Boolean.class)
66
public class BoolEditor extends ExPropertyEditorSupport {
68
public class BoolEditor extends ExPropertyEditorSupport {
67
    String[] stringValues = null;
69
    String[] stringValues = null;
68
    /** Creates a new instance of BoolEditor */
70
    /** Creates a new instance of BoolEditor */
(-)a/o.n.core/src/org/netbeans/beaninfo/editors/CharEditor.java (+2 lines)
Lines 46-56 Link Here
46
46
47
import java.beans.*;
47
import java.beans.*;
48
import org.openide.explorer.propertysheet.editors.EnhancedPropertyEditor;
48
import org.openide.explorer.propertysheet.editors.EnhancedPropertyEditor;
49
import org.openide.nodes.PropertyEditorRegistration;
49
50
50
/**
51
/**
51
 * Editor for Character.TYPE
52
 * Editor for Character.TYPE
52
 * @author  Petr Zajac, David Strupl
53
 * @author  Petr Zajac, David Strupl
53
 */
54
 */
55
@PropertyEditorRegistration(targetType=Character.class)
54
public class CharEditor extends PropertyEditorSupport implements EnhancedPropertyEditor {
56
public class CharEditor extends PropertyEditorSupport implements EnhancedPropertyEditor {
55
57
56
    /**
58
    /**
(-)a/o.n.core/src/org/netbeans/beaninfo/editors/IntEditor.java (+2 lines)
Lines 52-57 Link Here
52
import org.netbeans.beaninfo.editors.ExPropertyEditorSupport.EnvException;
52
import org.netbeans.beaninfo.editors.ExPropertyEditorSupport.EnvException;
53
import org.netbeans.core.UIExceptions;
53
import org.netbeans.core.UIExceptions;
54
import org.openide.explorer.propertysheet.*;
54
import org.openide.explorer.propertysheet.*;
55
import org.openide.nodes.PropertyEditorRegistration;
55
import org.openide.util.NbBundle;
56
import org.openide.util.NbBundle;
56
/** An editor for primitive integer types which allows hinting of tag
57
/** An editor for primitive integer types which allows hinting of tag
57
 *  values and handles whitespace in setAsText better than the default
58
 *  values and handles whitespace in setAsText better than the default
Lines 68-73 Link Here
68
 * @author  Tim Boudreau
69
 * @author  Tim Boudreau
69
 * @version 1.0
70
 * @version 1.0
70
 */
71
 */
72
@PropertyEditorRegistration(targetType=Integer.class)
71
public class IntEditor extends ExPropertyEditorSupport {
73
public class IntEditor extends ExPropertyEditorSupport {
72
    
74
    
73
    public static final String KEYS = "stringKeys"; //NOI18N
75
    public static final String KEYS = "stringKeys"; //NOI18N
(-)a/o.n.core/src/org/netbeans/beaninfo/editors/StringArrayEditor.java (+2 lines)
Lines 53-62 Link Here
53
import org.openide.explorer.propertysheet.PropertyEnv;
53
import org.openide.explorer.propertysheet.PropertyEnv;
54
import org.openide.explorer.propertysheet.editors.XMLPropertyEditor;
54
import org.openide.explorer.propertysheet.editors.XMLPropertyEditor;
55
import org.openide.nodes.Node;
55
import org.openide.nodes.Node;
56
import org.openide.nodes.PropertyEditorRegistration;
56
57
57
/** A property editor for array of Strings.
58
/** A property editor for array of Strings.
58
 * @author  Ian Formanek
59
 * @author  Ian Formanek
59
 */
60
 */
61
@PropertyEditorRegistration(targetType=String[].class)
60
public class StringArrayEditor implements XMLPropertyEditor, StringArrayCustomizable, ExPropertyEditor {
62
public class StringArrayEditor implements XMLPropertyEditor, StringArrayCustomizable, ExPropertyEditor {
61
63
62
    // constants for XML persistence
64
    // constants for XML persistence
(-)a/o.n.core/src/org/netbeans/beaninfo/editors/package-info.java (+5 lines)
Line 0 Link Here
1
@PropertyEditorSearchPath
2
package org.netbeans.beaninfo.editors;
3
4
import org.openide.nodes.PropertyEditorSearchPath;
5
(-)a/o.n.core/src/org/netbeans/core/CoreBridgeImpl.java (-14 / +24 lines)
Lines 48-57 Link Here
48
import java.io.File;
48
import java.io.File;
49
import java.io.InputStream;
49
import java.io.InputStream;
50
import java.io.OutputStream;
50
import java.io.OutputStream;
51
import javax.swing.SwingUtilities;
51
import org.netbeans.core.startup.CoreBridge;
52
import org.netbeans.core.startup.CoreBridge;
52
import org.netbeans.core.startup.MainLookup;
53
import org.netbeans.core.startup.MainLookup;
53
import org.netbeans.core.startup.ManifestSection;
54
import org.netbeans.core.startup.ManifestSection;
54
import org.netbeans.swing.plaf.Startup;
55
import org.netbeans.swing.plaf.Startup;
56
import org.openide.nodes.NodeOp;
55
import org.openide.util.NbBundle;
57
import org.openide.util.NbBundle;
56
import org.openide.util.RequestProcessor;
58
import org.openide.util.RequestProcessor;
57
import org.openide.util.lookup.ServiceProvider;
59
import org.openide.util.lookup.ServiceProvider;
Lines 173-192 Link Here
173
    private static final void doRegisterPropertyEditors() {
175
    private static final void doRegisterPropertyEditors() {
174
        //issue 31879
176
        //issue 31879
175
        if (editorsRegistered) return;
177
        if (editorsRegistered) return;
176
        String[] syspesp = PropertyEditorManager.getEditorSearchPath();
178
//        String[] syspesp = PropertyEditorManager.getEditorSearchPath();
177
        String[] nbpesp = new String[] {
179
//        String[] nbpesp = new String[] {
178
            "org.netbeans.beaninfo.editors", // NOI18N
180
//            "org.netbeans.beaninfo.editors", // NOI18N
179
            "org.openide.explorer.propertysheet.editors", // NOI18N
181
//            "org.openide.explorer.propertysheet.editors", // NOI18N
180
        };
182
//        };
181
        String[] allpesp = new String[syspesp.length + nbpesp.length];
183
//        String[] allpesp = new String[syspesp.length + nbpesp.length];
182
        System.arraycopy(nbpesp, 0, allpesp, 0, nbpesp.length);
184
//        System.arraycopy(nbpesp, 0, allpesp, 0, nbpesp.length);
183
        System.arraycopy(syspesp, 0, allpesp, nbpesp.length, syspesp.length);
185
//        System.arraycopy(syspesp, 0, allpesp, nbpesp.length, syspesp.length);
184
        PropertyEditorManager.setEditorSearchPath(allpesp);
186
//        PropertyEditorManager.setEditorSearchPath(allpesp);
185
        PropertyEditorManager.registerEditor (java.lang.Character.TYPE, org.netbeans.beaninfo.editors.CharEditor.class);
187
//        PropertyEditorManager.registerEditor (java.lang.Character.TYPE, org.netbeans.beaninfo.editors.CharEditor.class);
186
        PropertyEditorManager.registerEditor(String[].class, org.netbeans.beaninfo.editors.StringArrayEditor.class); 
188
//        PropertyEditorManager.registerEditor(String[].class, org.netbeans.beaninfo.editors.StringArrayEditor.class); 
187
        // use replacement hintable/internationalizable primitive editors - issues 20376, 5278
189
//        // use replacement hintable/internationalizable primitive editors - issues 20376, 5278
188
        PropertyEditorManager.registerEditor (Integer.TYPE, org.netbeans.beaninfo.editors.IntEditor.class);
190
//        PropertyEditorManager.registerEditor (Integer.TYPE, org.netbeans.beaninfo.editors.IntEditor.class);
189
        PropertyEditorManager.registerEditor (Boolean.TYPE, org.netbeans.beaninfo.editors.BoolEditor.class);
191
//        PropertyEditorManager.registerEditor (Boolean.TYPE, org.netbeans.beaninfo.editors.BoolEditor.class);
192
        
193
        NodeOp.registerPropertyEditors();
194
        SwingUtilities.invokeLater(new Runnable() {
195
            @Override
196
            public void run() {
197
                NodeOp.registerPropertyEditors();
198
            }
199
        });
190
        
200
        
191
        // install java.net.ProxySelector
201
        // install java.net.ProxySelector
192
        NbProxySelector.register();
202
        NbProxySelector.register();
(-)a/openide.explorer/src/org/openide/explorer/propertysheet/editors/package-info.java (+5 lines)
Line 0 Link Here
1
@PropertyEditorSearchPath
2
package org.openide.explorer.propertysheet.editors;
3
4
import org.openide.nodes.PropertyEditorSearchPath;
5
(-)a/openide.nodes/apichanges.xml (+18 lines)
Lines 49-54 Link Here
49
<apidef name="nodes">Nodes API</apidef>
49
<apidef name="nodes">Nodes API</apidef>
50
</apidefs>
50
</apidefs>
51
<changes>
51
<changes>
52
    <change id="PropertyEditorRegistration">
53
        <api name="nodes"/>
54
        <summary>Adding <code>@PropertyEditorRegistration</code> and <code>@PropertyEditorSearchPath</code> annotations</summary>
55
        <version major="7" minor="30"/>
56
        <date year="2012" month="9" day="12"/>
57
        <author login="jhorvath"/>
58
        <compatibility addition="yes" binary="compatible" source="compatible" deprecation="no" deletion="no"/>
59
        <description>
60
            <p>
61
                Adding <code>@PropertyEditorRegistration</code> and <code>@PropertyEditorSearchPath</code> annotations
62
                to allow convenient way of registering property editors.
63
            </p>
64
        </description>
65
        <class package="org.openide.nodes" name="NodeOp"/>
66
        <class package="org.openide.nodes" name="PropertyEditorRegistration"/>
67
        <class package="org.openide.nodes" name="PropertyEditorSearchPath"/>
68
        <issue number="218300"/>
69
    </change>
52
    <change id="ChildFactory.incremental">
70
    <change id="ChildFactory.incremental">
53
        <api name="nodes"/>
71
        <api name="nodes"/>
54
        <summary><code>ChildFactory.createKeys</code> better supports incremental display</summary>
72
        <summary><code>ChildFactory.createKeys</code> better supports incremental display</summary>
(-)a/openide.nodes/manifest.mf (-1 / +1 lines)
Lines 2-6 Link Here
2
OpenIDE-Module: org.openide.nodes
2
OpenIDE-Module: org.openide.nodes
3
OpenIDE-Module-Localizing-Bundle: org/openide/nodes/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/openide/nodes/Bundle.properties
4
AutoUpdate-Essential-Module: true
4
AutoUpdate-Essential-Module: true
5
OpenIDE-Module-Specification-Version: 7.29
5
OpenIDE-Module-Specification-Version: 7.30
6
6
(-)a/openide.nodes/nbproject/project.xml (+5 lines)
Lines 66-71 Link Here
66
                    </run-dependency>
66
                    </run-dependency>
67
                </dependency>
67
                </dependency>
68
                <dependency>
68
                <dependency>
69
                    <code-name-base>org.openide.filesystems</code-name-base>
70
                    <build-prerequisite/>
71
                    <compile-dependency/>
72
                </dependency>
73
                <dependency>
69
                    <code-name-base>org.openide.util</code-name-base>
74
                    <code-name-base>org.openide.util</code-name-base>
70
                    <build-prerequisite/>
75
                    <build-prerequisite/>
71
                    <compile-dependency/>
76
                    <compile-dependency/>
(-)a/openide.nodes/src/org/netbeans/modules/openide/nodes/PEAnnotationProcessor.java (+158 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 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
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.openide.nodes;
43
44
import java.util.Collection;
45
import java.util.HashSet;
46
import java.util.List;
47
import java.util.Map.Entry;
48
import java.util.Set;
49
import javax.annotation.processing.Messager;
50
import javax.annotation.processing.Processor;
51
import javax.annotation.processing.RoundEnvironment;
52
import javax.lang.model.element.AnnotationMirror;
53
import javax.lang.model.element.AnnotationValue;
54
import javax.lang.model.element.Element;
55
import javax.lang.model.element.ElementKind;
56
import javax.lang.model.element.ExecutableElement;
57
import javax.lang.model.element.PackageElement;
58
import javax.lang.model.element.TypeElement;
59
import javax.lang.model.type.TypeMirror;
60
import javax.lang.model.util.SimpleAnnotationValueVisitor6;
61
import javax.tools.Diagnostic.Kind;
62
import org.openide.filesystems.annotations.LayerBuilder;
63
import org.openide.filesystems.annotations.LayerGeneratingProcessor;
64
import org.openide.filesystems.annotations.LayerGenerationException;
65
import org.openide.nodes.PropertyEditorRegistration;
66
import org.openide.nodes.PropertyEditorSearchPath;
67
import org.openide.util.lookup.ServiceProvider;
68
69
/**
70
 * Processing annotation <code>@PropertyEditorSearchPath</code> 
71
 * and <code>@PropertyEditorRegistration</code>
72
 * 
73
 * @author Jan Horvath <jhorvath@netbeans.org>
74
 */
75
@ServiceProvider(service=Processor.class)
76
public class PEAnnotationProcessor extends LayerGeneratingProcessor {
77
78
    public PEAnnotationProcessor() {
79
    }
80
81
    @Override
82
    public Set<String> getSupportedAnnotationTypes() {
83
        Set<String> set = new HashSet<String>();
84
        set.add(PropertyEditorSearchPath.class.getName());
85
        set.add(PropertyEditorRegistration.class.getName());
86
        return set;
87
    }
88
89
    @Override
90
    protected boolean handleProcess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) 
91
            throws LayerGenerationException {
92
        Messager messager = processingEnv.getMessager();
93
        for (Element e : roundEnv.getElementsAnnotatedWith(PropertyEditorSearchPath.class)) {
94
            String pkg = findPackage(e);
95
            String pkgFilename = pkg.replace(".", "-"); //NOI18N
96
            LayerBuilder builder = layer(e);
97
            LayerBuilder.File file = builder.file(PERegistrationSupport.LOOKUP_PATH 
98
                    + "/Package-" + pkgFilename + ".instance"); //NOI18N
99
            file.methodvalue("instanceCreate", PERegistrationSupport.class.getName(), 
100
                    "createPackageRegistration"); //NOI18N
101
            file.stringvalue(PERegistrationSupport.PACKAGE, pkg);
102
            file.write();
103
        }
104
105
        for (Element e : roundEnv.getElementsAnnotatedWith(PropertyEditorRegistration.class)) {
106
            if (e.getKind() == ElementKind.CLASS) {
107
                String className = ((TypeElement) e).getQualifiedName().toString();
108
                Collection<AnnotationValue> targetTypes = null;
109
                List<? extends AnnotationMirror> annotationMirrors = e.getAnnotationMirrors();
110
                for (AnnotationMirror am : annotationMirrors) {
111
                    for (Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : am.getElementValues().entrySet()) {
112
                        if ("targetType".equals(entry.getKey().getSimpleName().toString())) { //NOI18N
113
                            targetTypes = (Collection<AnnotationValue>) entry.getValue().getValue();
114
                        }
115
                    }
116
                }
117
                if (targetTypes == null) {
118
                    messager.printMessage(Kind.ERROR, "No targetType is specified", e); //NOI18N
119
                    continue;
120
                }
121
                TypeElement typeElement = processingEnv.getElementUtils().getTypeElement("java.beans.PropertyEditor"); //NOI18N
122
                if (!processingEnv.getTypeUtils().isSubtype(e.asType(), typeElement.asType())) {
123
                    messager.printMessage(Kind.ERROR, className + " is not subtype of PropertyEditor", e); //NOI18N
124
                    continue;
125
                }
126
127
                LayerBuilder builder = layer(e);
128
                String clsFileName = className.replace(".", "-"); //NOI18N
129
                LayerBuilder.File file = builder.instanceFile(PERegistrationSupport.LOOKUP_PATH, "Class-" + clsFileName); //NOI18N
130
                file.methodvalue("instanceCreate", PERegistrationSupport.class.getName(), "createClassRegistration"); //NOI18N
131
                file.stringvalue(PERegistrationSupport.EDITOR_CLASS, className); //NOI18N
132
                int i = 1;
133
                for (AnnotationValue type : targetTypes) {
134
                    String clsName = type.accept(new SimpleAnnotationValueVisitor6<String, Object>() {
135
                        
136
                        @Override
137
                        public String visitType(TypeMirror t, Object p) {
138
                            return t.toString();
139
                        }
140
                    }, null);
141
                    file.stringvalue("targetType." + i, clsName); //NOI18N
142
                    i++;
143
                }
144
                file.write();
145
            }
146
        }
147
        return true;
148
    }
149
150
    private String findPackage(Element e) {
151
        switch (e.getKind()) {
152
            case PACKAGE:
153
                return ((PackageElement) e).getQualifiedName().toString();
154
            default:
155
                return findPackage(e.getEnclosingElement());
156
        }
157
    }
158
}
(-)a/openide.nodes/src/org/netbeans/modules/openide/nodes/PERegistrationSupport.java (+232 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 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
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.openide.nodes;
43
44
import java.beans.PropertyEditorManager;
45
import java.lang.reflect.Array;
46
import java.util.Arrays;
47
import java.util.HashSet;
48
import java.util.LinkedHashSet;
49
import java.util.List;
50
import java.util.Map;
51
import java.util.Set;
52
import org.openide.util.Exceptions;
53
import org.openide.util.Lookup;
54
import org.openide.util.Lookup.Result;
55
import org.openide.util.LookupEvent;
56
import org.openide.util.LookupListener;
57
58
/**
59
 * Class for registering property editors.
60
 * 
61
 * @author Jan Horvath <jhorvath@netbeans.org>
62
 */
63
public final class PERegistrationSupport {
64
    
65
    static final String LOOKUP_PATH = "Services/PropertyEditorManager"; //NOI18N
66
    static final String PACKAGE = "packagePath"; //NOI18N
67
    static final String EDITOR_CLASS = "propertyEditorClass"; //NOI18N
68
    
69
    static ClassReg clsReg = null;
70
    static PkgReg pkgReg = null;
71
    
72
    public static synchronized void registerPropertyEditors() {
73
        if (clsReg == null) {
74
            clsReg = new ClassReg();
75
        }
76
        if (pkgReg == null) {
77
            pkgReg = new PkgReg();
78
        }
79
    }
80
    
81
    /**
82
     * Creates instance of <code>PEPackageRegistration</code> based on layer.xml
83
     * attribute values
84
     * 
85
     * @param attrs attributes loaded from layer.xml
86
     * @return
87
     */
88
    public static PEPackageRegistration createPackageRegistration(final Map attrs) {
89
        String pkg = (String) attrs.get(PACKAGE);
90
        return new PEPackageRegistration(pkg);
91
    }
92
    
93
    /**
94
     * Creates instance of <code>PEClassRegistration</code> based on layer.xml
95
     * attribute values
96
     * 
97
     * @param attrs attributes loaded from layer.xml
98
     * @return
99
     */
100
    public static PEClassRegistration createClassRegistration(final Map attrs) {
101
        String editorClass = (String) attrs.get(EDITOR_CLASS);
102
        Set<String> targetTypes = new LinkedHashSet<String> ();
103
        for (int i = 1; ; i++) {
104
            String targetType = (String) attrs.get("targetType." + i); //NOI18N
105
            if (targetType == null) {
106
                break;
107
            }
108
            targetTypes.add(targetType);
109
        }
110
        return new PEClassRegistration(editorClass, targetTypes);
111
    }
112
    
113
    /**
114
     * returns Class from canonical class name like <code>java.lang.String[]</code>
115
     */
116
    protected static Class<?> getClassFromCanonicalName(String name) throws ClassNotFoundException {
117
        Class<?> result;
118
        String type = name;
119
        int dimensions = 0;
120
        while (type.endsWith("[]")) { //NOI18N
121
            dimensions++;
122
            type = type.substring(0, type.length() - 2);
123
        }
124
        if ("byte".equals(type)) { //NOI18N
125
            result = byte.class;
126
        } else if ("short".equals(type)) { //NOI18N
127
            result = short.class;
128
        } else if ("char".equals(type)) { //NOI18N
129
            result = char.class;
130
        } else if ("int".equals(type)) { //NOI18N
131
            result = int.class;
132
        } else if ("long".equals(type)) { //NOI18N
133
            result = long.class;
134
        } else if ("float".equals(type)) { //NOI18N
135
            result = float.class;
136
        } else if ("double".equals(type)) { //NOI18N
137
            result = double.class;
138
        } else if ("boolean".equals(type)) { //NOI18N
139
            result = boolean.class;
140
        } else {
141
            ClassLoader clsLoader = Thread.currentThread().getContextClassLoader();
142
            result = Class.forName(type, true, clsLoader);
143
        }
144
        if (dimensions > 0) {
145
            int d[] = new int[dimensions];
146
            for (int i = 0; i < d.length; i++) {
147
                d[i] = 0;
148
            }
149
            result = Array.newInstance(result, d).getClass();
150
        }
151
        return result;
152
    }
153
    
154
    public static class PEPackageRegistration {
155
        final String pkg;
156
157
        PEPackageRegistration(String pkg) {
158
            this.pkg = pkg;
159
        }
160
    }
161
    
162
    public static class PEClassRegistration {
163
        final Set<String> targetTypes;
164
        final String editorClass;
165
        
166
        PEClassRegistration(String editorClass, Set<String> targetTypes) {
167
            this.editorClass = editorClass;
168
            this.targetTypes = targetTypes;
169
        }
170
    }
171
    
172
    private static final class ClassReg implements LookupListener {
173
        Result<PEClassRegistration> lookupResult = null;
174
        
175
        ClassReg() {
176
            lookupResult = Lookup.getDefault().lookupResult(PERegistrationSupport.PEClassRegistration.class);
177
            register();
178
            lookupResult.addLookupListener(this);
179
        }
180
                
181
        synchronized void register() {
182
            lookupResult = Lookup.getDefault().lookupResult(PERegistrationSupport.PEClassRegistration.class);
183
            ClassLoader clsLoader = Thread.currentThread().getContextClassLoader();
184
            
185
            for (PEClassRegistration clsReg : lookupResult.allInstances()) {
186
                for (String type : clsReg.targetTypes) {
187
                    try {
188
                        Class<?> cls = getClassFromCanonicalName(type);
189
                        Class<?> editorCls = Class.forName(clsReg.editorClass, true, clsLoader);
190
                        PropertyEditorManager.registerEditor(cls, editorCls);
191
                    } catch (ClassNotFoundException ex) {
192
                        Exceptions.printStackTrace(ex);
193
                    }
194
                }
195
            }
196
        }
197
        
198
        @Override
199
        public void resultChanged(LookupEvent ev) {
200
            register();
201
        }
202
    }
203
    
204
    static final class PkgReg implements LookupListener {
205
        Result<PEPackageRegistration> pkgResult;
206
        private static List<String> originalPath = null;
207
        
208
        PkgReg() {
209
            if (originalPath == null) {
210
                originalPath = Arrays.asList(PropertyEditorManager.getEditorSearchPath());
211
            }
212
            pkgResult = Lookup.getDefault().lookupResult(PERegistrationSupport.PEPackageRegistration.class);
213
            register();
214
            pkgResult.addLookupListener(this);
215
        }
216
        
217
        synchronized void register() {
218
            pkgResult = Lookup.getDefault().lookupResult(PERegistrationSupport.PEPackageRegistration.class);
219
            Set<String> newPath = new HashSet<String> ();
220
            for (PEPackageRegistration pkgReg : pkgResult.allInstances()) {
221
                newPath.add(pkgReg.pkg);
222
            }
223
            newPath.addAll(originalPath);
224
            PropertyEditorManager.setEditorSearchPath(newPath.toArray(new String[newPath.size()]));
225
        }
226
227
        @Override
228
        public void resultChanged(LookupEvent ev) {
229
            register();
230
        }
231
    }
232
}
(-)a/openide.nodes/src/org/openide/nodes/NodeOp.java (+12 lines)
Lines 56-61 Link Here
56
import java.util.logging.Logger;
56
import java.util.logging.Logger;
57
import javax.swing.Action;
57
import javax.swing.Action;
58
import javax.swing.JPopupMenu;
58
import javax.swing.JPopupMenu;
59
import org.netbeans.modules.openide.nodes.PERegistrationSupport;
59
import org.openide.util.Enumerations;
60
import org.openide.util.Enumerations;
60
import org.openide.util.Lookup;
61
import org.openide.util.Lookup;
61
import org.openide.util.Utilities;
62
import org.openide.util.Utilities;
Lines 458-463 Link Here
458
    public static NodeListener weakNodeListener(NodeListener l, Object source) {
459
    public static NodeListener weakNodeListener(NodeListener l, Object source) {
459
        return WeakListeners.create(NodeListener.class, l, source);
460
        return WeakListeners.create(NodeListener.class, l, source);
460
    }
461
    }
462
    
463
    /** Registers Property Editors and sets the Property Editors search path.
464
     * 
465
     * @see PropertyEditorSearchPath
466
     * @see PropertyEditorRegistration
467
     * 
468
     * @since 7.30
469
     */
470
    public static void registerPropertyEditors() {
471
        PERegistrationSupport.registerPropertyEditors();
472
    }
461
473
462
    /** more info in class javadoc.
474
    /** more info in class javadoc.
463
     * @since 7.9
475
     * @since 7.9
(-)a/openide.nodes/src/org/openide/nodes/PropertyEditorRegistration.java (+66 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 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
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.openide.nodes;
43
44
import java.lang.annotation.ElementType;
45
import java.lang.annotation.Retention;
46
import java.lang.annotation.RetentionPolicy;
47
import java.lang.annotation.Target;
48
49
/**
50
 * Register an editor class to be used to editor values of a given target class. 
51
 * Editor class must implement PropertyEditor interface.
52
 * At runtime the editors are registered by {@link NodeOp#registerPropertyEditors() }
53
 * 
54
 * @since 7.30
55
 * @author Jan Horvath <jhorvath@netbeans.org>
56
 */
57
@Retention(RetentionPolicy.RUNTIME)
58
@Target(ElementType.TYPE)
59
public @interface PropertyEditorRegistration {
60
    
61
    /**
62
     * The Class object of the type to be edited
63
     */
64
    Class<?>[] targetType();
65
    
66
}
(-)a/openide.nodes/src/org/openide/nodes/PropertyEditorSearchPath.java (+60 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 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
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.openide.nodes;
43
44
import java.lang.annotation.ElementType;
45
import java.lang.annotation.Retention;
46
import java.lang.annotation.RetentionPolicy;
47
import java.lang.annotation.Target;
48
49
/**
50
 * Add the annotated package to the list of package names that will be used for finding property editors. 
51
 * At runtime the path is registered by {@link NodeOp#registerPropertyEditors() }
52
 * 
53
 * @since 7.30
54
 * @author Jan Horvath <jhorvath@netbeans.org>
55
 */
56
@Retention(RetentionPolicy.SOURCE)
57
@Target(ElementType.PACKAGE)
58
public @interface PropertyEditorSearchPath {  
59
60
}
(-)a/openide.nodes/test/unit/src/org/netbeans/modules/openide/nodes/PEAnnotationProcessorTest.java (+151 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 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
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.openide.nodes;
43
44
import java.beans.PropertyEditor;
45
import java.beans.PropertyEditorManager;
46
import java.io.ByteArrayOutputStream;
47
import java.io.IOException;
48
import java.util.Collection;
49
import org.netbeans.junit.NbTestCase;
50
import org.netbeans.modules.openide.nodes.PERegistrationSupport.PEClassRegistration;
51
import org.netbeans.modules.openide.nodes.PERegistrationSupport.PEPackageRegistration;
52
import org.openide.nodes.NodeOp;
53
import org.openide.util.Lookup;
54
import org.openide.util.test.AnnotationProcessorTestUtils;
55
56
/**
57
 *
58
 * @author Jan Horvath <jhorvath@netbeans.org>
59
 */
60
public class PEAnnotationProcessorTest extends NbTestCase {
61
    
62
    static {
63
        System.setProperty("org.openide.util.Lookup.paths", "Services");
64
    }
65
    
66
    public PEAnnotationProcessorTest(String name) {
67
        super(name);
68
    }
69
    
70
    @Override
71
    protected void setUp() throws Exception {
72
        clearWorkDir();
73
    }
74
    
75
    public void testDuplicateRegistration() {
76
        NodeOp.registerPropertyEditors();
77
        NodeOp.registerPropertyEditors();
78
        
79
        int count = 0;
80
        String[] editorSearchPath = PropertyEditorManager.getEditorSearchPath();
81
        for (int i = 0; i < editorSearchPath.length; i++) {
82
            if ("org.netbeans.modules.openide.nodes".equals(editorSearchPath[i])) {
83
                count++;
84
            }
85
        }
86
        assertEquals("Package path is registered multiple times", 1, count);
87
    }
88
        
89
    public void testPERegistered() {
90
        NodeOp.registerPropertyEditors();
91
        PropertyEditor pEditor = PropertyEditorManager.findEditor(Double[].class);
92
        assertEquals("org.netbeans.modules.openide.nodes.TestPropertyEditor", pEditor.getClass().getName());
93
        pEditor = PropertyEditorManager.findEditor(Integer.class);
94
        assertEquals("org.netbeans.modules.openide.nodes.TestPropertyEditor", pEditor.getClass().getName());
95
        pEditor = PropertyEditorManager.findEditor(char[][].class);
96
        assertEquals("org.netbeans.modules.openide.nodes.TestPropertyEditor", pEditor.getClass().getName());
97
        pEditor = PropertyEditorManager.findEditor(short.class);
98
        assertEquals("org.netbeans.modules.openide.nodes.TestPropertyEditor", pEditor.getClass().getName());
99
    }
100
    
101
    public void testClassRegistration() {
102
        Collection<? extends PEClassRegistration> lookup = Lookup.getDefault().lookupAll(PEClassRegistration.class);
103
        assertTrue("failed to lookup class registrations", lookup.size() > 0);
104
        PEClassRegistration classReg = lookup.iterator().next();
105
        assertEquals("org.netbeans.modules.openide.nodes.TestPropertyEditor", classReg.editorClass);
106
        assertTrue(classReg.targetTypes.contains(Integer.class.getCanonicalName()));
107
        assertTrue(classReg.targetTypes.contains(Double[].class.getCanonicalName()));
108
    }
109
    
110
    public void testCheckForSubtype() throws IOException {
111
        clearWorkDir();
112
        AnnotationProcessorTestUtils.makeSource(getWorkDir(), "test.A", 
113
            "import org.openide.nodes.PropertyEditorRegistration;\n" +    
114
            "@PropertyEditorRegistration(targetType={Integer.class})\n" +
115
            "public class A {\n" +
116
            "}\n"
117
        );
118
        ByteArrayOutputStream os = new ByteArrayOutputStream();
119
        boolean r = AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, getWorkDir(), null, os);
120
        assertFalse("Compilation has to fail:\n" + os, r);
121
        if (!os.toString().contains("is not subtype of PropertyEditor")) {
122
            fail(os.toString());
123
        }
124
    }
125
    
126
    public void testRegistrationOnMethod() throws IOException {
127
        clearWorkDir();
128
        AnnotationProcessorTestUtils.makeSource(getWorkDir(), "test.A", 
129
            "import org.openide.nodes.PropertyEditorRegistration;\n" +    
130
            "public class A {\n" +
131
            "    @PropertyEditorRegistration(targetType={Integer.class})\n" +
132
            "    public void myMethod(String a) {\n" +
133
            "    }\n" +
134
            "}\n"
135
        );
136
        ByteArrayOutputStream os = new ByteArrayOutputStream();
137
        boolean r = AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, getWorkDir(), null, os);
138
        assertFalse("Compilation has to fail:\n" + os, r);
139
        if (!os.toString().contains("not applicable")) {
140
            fail(os.toString());
141
        }
142
    }
143
    
144
    public void testPackageRegistration() {
145
        Collection<? extends PEPackageRegistration> lookup = Lookup.getDefault().lookupAll(PEPackageRegistration.class);
146
        assertTrue("failed to lookup class registrations", lookup.size() > 0);
147
        PEPackageRegistration pkgReg = lookup.iterator().next();
148
        assertEquals("org.netbeans.modules.openide.nodes", pkgReg.pkg);
149
    }
150
        
151
}
(-)a/openide.nodes/test/unit/src/org/netbeans/modules/openide/nodes/PELookupTest.java (+81 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 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
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.openide.nodes;
43
44
import java.beans.PropertyEditorManager;
45
import org.netbeans.junit.NbTestCase;
46
import org.openide.nodes.NodeOp;
47
import org.openide.util.Exceptions;
48
import org.openide.util.test.MockLookup;
49
50
/**
51
 *
52
 * @author Jan Horvath <jhorvath@netbeans.org>
53
 */
54
public class PELookupTest extends NbTestCase {
55
    
56
    public PELookupTest(String name) {
57
        super(name);
58
    }
59
    
60
    static {
61
        System.setProperty("org.openide.util.Lookup.paths", "Services");
62
    }
63
    
64
    public void testPackageUnregistering() {
65
        MockLookup.setInstances(new PERegistrationSupport.PEPackageRegistration("test1.pkg"));
66
        NodeOp.registerPropertyEditors();
67
        MockLookup.setInstances(new PERegistrationSupport.PEPackageRegistration("test2.pkg"));
68
        
69
        String[] editorSearchPath = PropertyEditorManager.getEditorSearchPath();
70
        int count = 0;
71
        for (int i = 0; i < editorSearchPath.length; i++) {
72
            assertNotSame("test1.pkg", editorSearchPath[i]);
73
            if ("test2.pkg".equals(editorSearchPath[i])) {
74
                count++;
75
            }
76
        }
77
        assertEquals(1, count);
78
        
79
    }
80
    
81
}
(-)a/openide.nodes/test/unit/src/org/netbeans/modules/openide/nodes/PERegistrationSupportTest.java (+83 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 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
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.openide.nodes;
43
44
import org.netbeans.junit.NbTestCase;
45
46
/**
47
 *
48
 * @author Jan Horvath <jhorvath@netbeans.org>
49
 */
50
public class PERegistrationSupportTest extends NbTestCase {
51
    
52
    public PERegistrationSupportTest(String name) {
53
        super(name);
54
    }
55
    
56
    public void doTest(String type) throws ClassNotFoundException {
57
        Class<?> cls = PERegistrationSupport.getClassFromCanonicalName(type);
58
        assertEquals(type, cls.getCanonicalName());
59
    }
60
    
61
    public void testPrimitives() throws ClassNotFoundException {
62
        String[] classNames = {"int", "boolean", "float", "short", "char"};
63
        for (int i = 0; i < classNames.length; i++) {
64
            doTest(classNames[i]);
65
        }
66
    }
67
    
68
    public void testArrays() throws ClassNotFoundException {
69
        String[] classNames = {"int[][][]", "boolean[]", "java.lang.String[]"};
70
        for (int i = 0; i < classNames.length; i++) {
71
            doTest(classNames[i]);
72
        }
73
    }
74
    
75
    public void testTypes() throws ClassNotFoundException {
76
        String[] classNames = {"java.lang.String", "java.lang.Integer"};
77
        for (int i = 0; i < classNames.length; i++) {
78
            doTest(classNames[i]);
79
        }
80
    }
81
    
82
    
83
}
(-)a/openide.nodes/test/unit/src/org/netbeans/modules/openide/nodes/TestPropertyEditor.java (+117 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 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
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.openide.nodes;
43
44
import java.awt.Component;
45
import java.awt.Graphics;
46
import java.awt.Rectangle;
47
import java.beans.PropertyChangeListener;
48
import java.beans.PropertyEditor;
49
import org.openide.nodes.PropertyEditorRegistration;
50
51
/**
52
 *
53
 * @author Jan Horvath <jhorvath@netbeans.org>
54
 */
55
@PropertyEditorRegistration(targetType = {Integer.class, Double[].class, byte.class, char[][].class, short.class})
56
public final class TestPropertyEditor implements PropertyEditor {
57
58
    @Override
59
    public void setValue(Object value) {
60
        throw new UnsupportedOperationException("Not supported yet.");
61
    }
62
63
    @Override
64
    public Object getValue() {
65
        throw new UnsupportedOperationException("Not supported yet.");
66
    }
67
68
    @Override
69
    public boolean isPaintable() {
70
        throw new UnsupportedOperationException("Not supported yet.");
71
    }
72
73
    @Override
74
    public void paintValue(Graphics gfx, Rectangle box) {
75
        throw new UnsupportedOperationException("Not supported yet.");
76
    }
77
78
    @Override
79
    public String getJavaInitializationString() {
80
        throw new UnsupportedOperationException("Not supported yet.");
81
    }
82
83
    @Override
84
    public String getAsText() {
85
        throw new UnsupportedOperationException("Not supported yet.");
86
    }
87
88
    @Override
89
    public void setAsText(String text) throws IllegalArgumentException {
90
        throw new UnsupportedOperationException("Not supported yet.");
91
    }
92
93
    @Override
94
    public String[] getTags() {
95
        throw new UnsupportedOperationException("Not supported yet.");
96
    }
97
98
    @Override
99
    public Component getCustomEditor() {
100
        throw new UnsupportedOperationException("Not supported yet.");
101
    }
102
103
    @Override
104
    public boolean supportsCustomEditor() {
105
        throw new UnsupportedOperationException("Not supported yet.");
106
    }
107
108
    @Override
109
    public void addPropertyChangeListener(PropertyChangeListener listener) {
110
        throw new UnsupportedOperationException("Not supported yet.");
111
    }
112
113
    @Override
114
    public void removePropertyChangeListener(PropertyChangeListener listener) {
115
        throw new UnsupportedOperationException("Not supported yet.");
116
    }
117
}
(-)a/openide.nodes/test/unit/src/org/netbeans/modules/openide/nodes/package-info.java (+5 lines)
Line 0 Link Here
1
@PropertyEditorSearchPath
2
package org.netbeans.modules.openide.nodes;
3
4
import org.openide.nodes.PropertyEditorSearchPath;
5
(-)a/xml.tax/manifest.mf (-1 lines)
Lines 1-6 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.xml.tax/2
2
OpenIDE-Module: org.netbeans.modules.xml.tax/2
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/xml/tax/resources/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/xml/tax/resources/Bundle.properties
4
OpenIDE-Module-Install: org/netbeans/modules/xml/tax/TAXModuleInstall.class
5
OpenIDE-Module-Requires: org.openide.modules.InstalledFileLocator
4
OpenIDE-Module-Requires: org.openide.modules.InstalledFileLocator
6
5
(-)a/xml.tax/src/org/netbeans/modules/xml/tax/TAXModuleInstall.java (-44 / +18 lines)
Lines 45-111 Link Here
45
45
46
import java.beans.*;
46
import java.beans.*;
47
import java.util.Arrays;
47
import java.util.Arrays;
48
import java.util.LinkedList;
48
import java.util.List;
49
import java.util.List;
49
import java.util.LinkedList;
50
import org.openide.modules.OnStart;
50
51
import org.openide.modules.OnStop;
51
import org.openide.modules.ModuleInstall;
52
52
53
/**
53
/**
54
 * Module installation class for tax module.
54
 * Module installation class for tax module.
55
 *
55
 *
56
 * @author Libor Kramolis
56
 * @author Libor Kramolis
57
 */
57
 */
58
public class TAXModuleInstall extends ModuleInstall {
58
@OnStart
59
public class TAXModuleInstall implements Runnable {
59
60
60
    private static final String BEANINFO_PATH = "org.netbeans.modules.xml.tax.beans.beaninfo"; // NOI18N
61
    private static final String BEANINFO_PATH = "org.netbeans.modules.xml.tax.beans.beaninfo"; // NOI18N
61
    private static final String EDITOR_PATH   = "org.netbeans.modules.xml.tax.beans.editor";
62
62
63
63
    @Override
64
    /**
64
    public void run () {
65
     */
66
    public void restored () {
67
        installBeans();
68
    }
69
70
    /**
71
     */
72
    public void uninstalled () {
73
        uninstallBeans();
74
    }
75
76
77
    //
78
    // beans
79
    //
80
81
    /**
82
     */
83
    private void installBeans () {
84
        String[] sp = Introspector.getBeanInfoSearchPath();
65
        String[] sp = Introspector.getBeanInfoSearchPath();
85
        String[] newSP = new String[sp.length + 1];
66
        String[] newSP = new String[sp.length + 1];
86
        System.arraycopy(sp, 0, newSP, 0, sp.length);
67
        System.arraycopy(sp, 0, newSP, 0, sp.length);
87
        newSP[newSP.length - 1] = BEANINFO_PATH;
68
        newSP[newSP.length - 1] = BEANINFO_PATH;
88
        Introspector.setBeanInfoSearchPath(newSP);
69
        Introspector.setBeanInfoSearchPath(newSP);
89
90
        sp = PropertyEditorManager.getEditorSearchPath();
91
        newSP = new String[sp.length + 1];
92
        System.arraycopy(sp, 0, newSP, 0, sp.length);
93
        newSP[newSP.length - 1] = EDITOR_PATH;
94
        PropertyEditorManager.setEditorSearchPath(newSP);
95
    }
70
    }
96
71
97
    /**
72
    @OnStop
98
     */
73
    public static final class Down implements Runnable{
99
    private void uninstallBeans () {
74
        
100
	List searchPath;
75
        @Override
76
        public void run () {
77
            List searchPath;
101
78
102
	searchPath = new LinkedList (Arrays.asList (Introspector.getBeanInfoSearchPath()));
79
            searchPath = new LinkedList (Arrays.asList (Introspector.getBeanInfoSearchPath()));
103
	searchPath.remove (BEANINFO_PATH);
80
            searchPath.remove (BEANINFO_PATH);
104
        Introspector.setBeanInfoSearchPath ((String[])searchPath.toArray (new String[0]));
81
            Introspector.setBeanInfoSearchPath ((String[])searchPath.toArray (new String[0]));
105
82
        }
106
	searchPath = new LinkedList (Arrays.asList (PropertyEditorManager.getEditorSearchPath()));
107
	searchPath.remove (EDITOR_PATH);
108
        PropertyEditorManager.setEditorSearchPath  ((String[])searchPath.toArray (new String[0]));
109
    }
83
    }
110
84
    
111
}
85
}
(-)a/xml.tax/src/org/netbeans/modules/xml/tax/beans/editor/package-info.java (+5 lines)
Line 0 Link Here
1
@PropertyEditorSearchPath
2
package org.netbeans.modules.xml.tax.beans.editor;
3
4
import org.openide.nodes.PropertyEditorSearchPath;
5

Return to bug 218300