diff --git a/cnd/src/org/netbeans/modules/cnd/builds/package-info.java b/cnd/src/org/netbeans/modules/cnd/builds/package-info.java new file mode 100644 --- /dev/null +++ b/cnd/src/org/netbeans/modules/cnd/builds/package-info.java @@ -0,0 +1,5 @@ +@PropertyEditorSearchPath +package org.netbeans.modules.cnd.builds; + +import org.openide.nodes.PropertyEditorSearchPath; + diff --git a/cnd/src/org/netbeans/modules/cnd/settings/MakeSettings.java b/cnd/src/org/netbeans/modules/cnd/settings/MakeSettings.java --- a/cnd/src/org/netbeans/modules/cnd/settings/MakeSettings.java +++ b/cnd/src/org/netbeans/modules/cnd/settings/MakeSettings.java @@ -43,7 +43,6 @@ */ package org.netbeans.modules.cnd.settings; -import java.beans.PropertyEditorManager; import java.io.File; import java.util.ResourceBundle; import org.netbeans.modules.cnd.utils.CndUtils; @@ -77,7 +76,6 @@ protected void initialize() { super.initialize(); - registerPropertyEditors(); setReuseOutput(false); setSaveAll(true); @@ -107,15 +105,6 @@ return bundle.getString(s); } - private void registerPropertyEditors() { - String[] searchPath = PropertyEditorManager.getEditorSearchPath(); - String[] newSP = new String[searchPath.length + 1]; - System.arraycopy(searchPath, 0, newSP, 0, searchPath.length); - - newSP[searchPath.length] = "org.netbeans.modules.cnd.builds"; // NOI18N - PropertyEditorManager.setEditorSearchPath(newSP); - } - /** * Getter for the default build directory. This should be a relative path * from the filesystem of the current diff --git a/core.execution/manifest.mf b/core.execution/manifest.mf --- a/core.execution/manifest.mf +++ b/core.execution/manifest.mf @@ -1,7 +1,6 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.core.execution/1 OpenIDE-Module-Localizing-Bundle: org/netbeans/core/execution/resources/Bundle.properties -OpenIDE-Module-Install: org/netbeans/core/execution/Install.class OpenIDE-Module-Provides: org.openide.execution.ExecutionEngine AutoUpdate-Essential-Module: true OpenIDE-Module-Specification-Version: 1.29 diff --git a/core.execution/src/org/netbeans/core/execution/Install.java b/core.execution/src/org/netbeans/core/execution/Install.java --- a/core.execution/src/org/netbeans/core/execution/Install.java +++ b/core.execution/src/org/netbeans/core/execution/Install.java @@ -57,11 +57,11 @@ import java.beans.Introspector; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; -import java.beans.PropertyEditorManager; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.concurrent.Callable; import java.util.logging.Level; import java.util.logging.LogRecord; import java.util.logging.Logger; @@ -86,7 +86,8 @@ import org.openide.explorer.ExplorerManager; import org.openide.explorer.ExplorerUtils; import org.openide.explorer.view.ListView; -import org.openide.modules.ModuleInstall; +import org.openide.modules.OnStart; +import org.openide.modules.OnStop; import org.openide.nodes.AbstractNode; import org.openide.nodes.Children; import org.openide.nodes.Node; @@ -106,16 +107,15 @@ * Also adds/removes specific beaninfo and property editor search paths. * @author Jesse Glick */ -public class Install extends ModuleInstall { +@OnStart +public class Install implements Runnable { private static final String BEANINFO_PATH = "org.netbeans.core.execution.beaninfo"; // NOI18N - private static final String EDITOR_PATH - = "org.netbeans.core.execution.beaninfo.editors"; // NOI18N private static final Logger LOG = Logger.getLogger(Install.class.getName()); - public @Override void restored() { + public @Override void run() { TopSecurityManager.register(SecMan.DEFAULT); // Add beaninfo search path. @@ -127,46 +127,34 @@ Introspector.setBeanInfoSearchPath( paths.toArray(new String[0])); } + } + + @OnStop + public static final class Down implements Runnable { - // Add property editor search path. - sp = PropertyEditorManager.getEditorSearchPath(); - paths = Arrays.asList(sp); - if(!paths.contains(EDITOR_PATH)) { - paths = new ArrayList(paths); - paths.add(EDITOR_PATH); - PropertyEditorManager.setEditorSearchPath( - paths.toArray(new String[0])); + public @Override void run() { + showPendingTasks(); + + TopSecurityManager.unregister(SecMan.DEFAULT); + + // Remove beaninfo search path. + String[] sp = Introspector.getBeanInfoSearchPath(); + java.util.List paths = Arrays.asList(sp); + if(paths.contains(BEANINFO_PATH)) { + paths = new ArrayList(paths); + paths.remove(BEANINFO_PATH); + Introspector.setBeanInfoSearchPath( + paths.toArray(new String[0])); + } } } - - public @Override void uninstalled() { - showPendingTasks(); - - TopSecurityManager.unregister(SecMan.DEFAULT); - - // Remove beaninfo search path. - String[] sp = Introspector.getBeanInfoSearchPath(); - java.util.List paths = Arrays.asList(sp); - if(paths.contains(BEANINFO_PATH)) { - paths = new ArrayList(paths); - paths.remove(BEANINFO_PATH); - Introspector.setBeanInfoSearchPath( - paths.toArray(new String[0])); + + @OnStop + public static final class Closing implements Callable { + @Override + public Boolean call() throws Exception { + return showPendingTasks(); } - - // Remove property editor seach path. - sp = PropertyEditorManager.getEditorSearchPath(); - paths = Arrays.asList(sp); - if(paths.contains(EDITOR_PATH)) { - paths = new ArrayList(paths); - paths.remove(EDITOR_PATH); - PropertyEditorManager.setEditorSearchPath( - paths.toArray(new String[0])); - } - } - - public @Override boolean closing() { - return showPendingTasks(); } /** A class that server as a pending dialog manager. diff --git a/core.execution/src/org/netbeans/core/execution/beaninfo/editors/package-info.java b/core.execution/src/org/netbeans/core/execution/beaninfo/editors/package-info.java new file mode 100644 --- /dev/null +++ b/core.execution/src/org/netbeans/core/execution/beaninfo/editors/package-info.java @@ -0,0 +1,5 @@ +@PropertyEditorSearchPath +package org.netbeans.core.execution.beaninfo.editors; + +import org.openide.nodes.PropertyEditorSearchPath; + diff --git a/o.n.core/src/org/netbeans/beaninfo/editors/BoolEditor.java b/o.n.core/src/org/netbeans/beaninfo/editors/BoolEditor.java --- a/o.n.core/src/org/netbeans/beaninfo/editors/BoolEditor.java +++ b/o.n.core/src/org/netbeans/beaninfo/editors/BoolEditor.java @@ -50,6 +50,7 @@ package org.netbeans.beaninfo.editors; import java.beans.*; import org.openide.explorer.propertysheet.ExPropertyEditor; +import org.openide.nodes.PropertyEditorRegistration; import org.openide.util.NbBundle; /** Replacement editor for boolean primitive values which supports * internationalization and alternate string values that @@ -63,6 +64,7 @@ * * @author Tim Boudreau */ +@PropertyEditorRegistration(targetType=Boolean.class) public class BoolEditor extends ExPropertyEditorSupport { String[] stringValues = null; /** Creates a new instance of BoolEditor */ diff --git a/o.n.core/src/org/netbeans/beaninfo/editors/CharEditor.java b/o.n.core/src/org/netbeans/beaninfo/editors/CharEditor.java --- a/o.n.core/src/org/netbeans/beaninfo/editors/CharEditor.java +++ b/o.n.core/src/org/netbeans/beaninfo/editors/CharEditor.java @@ -46,11 +46,13 @@ import java.beans.*; import org.openide.explorer.propertysheet.editors.EnhancedPropertyEditor; +import org.openide.nodes.PropertyEditorRegistration; /** * Editor for Character.TYPE * @author Petr Zajac, David Strupl */ +@PropertyEditorRegistration(targetType=Character.class) public class CharEditor extends PropertyEditorSupport implements EnhancedPropertyEditor { /** diff --git a/o.n.core/src/org/netbeans/beaninfo/editors/IntEditor.java b/o.n.core/src/org/netbeans/beaninfo/editors/IntEditor.java --- a/o.n.core/src/org/netbeans/beaninfo/editors/IntEditor.java +++ b/o.n.core/src/org/netbeans/beaninfo/editors/IntEditor.java @@ -52,6 +52,7 @@ import org.netbeans.beaninfo.editors.ExPropertyEditorSupport.EnvException; import org.netbeans.core.UIExceptions; import org.openide.explorer.propertysheet.*; +import org.openide.nodes.PropertyEditorRegistration; import org.openide.util.NbBundle; /** An editor for primitive integer types which allows hinting of tag * values and handles whitespace in setAsText better than the default @@ -68,6 +69,7 @@ * @author Tim Boudreau * @version 1.0 */ +@PropertyEditorRegistration(targetType=Integer.class) public class IntEditor extends ExPropertyEditorSupport { public static final String KEYS = "stringKeys"; //NOI18N diff --git a/o.n.core/src/org/netbeans/beaninfo/editors/StringArrayEditor.java b/o.n.core/src/org/netbeans/beaninfo/editors/StringArrayEditor.java --- a/o.n.core/src/org/netbeans/beaninfo/editors/StringArrayEditor.java +++ b/o.n.core/src/org/netbeans/beaninfo/editors/StringArrayEditor.java @@ -53,10 +53,12 @@ import org.openide.explorer.propertysheet.PropertyEnv; import org.openide.explorer.propertysheet.editors.XMLPropertyEditor; import org.openide.nodes.Node; +import org.openide.nodes.PropertyEditorRegistration; /** A property editor for array of Strings. * @author Ian Formanek */ +@PropertyEditorRegistration(targetType=String[].class) public class StringArrayEditor implements XMLPropertyEditor, StringArrayCustomizable, ExPropertyEditor { // constants for XML persistence diff --git a/o.n.core/src/org/netbeans/beaninfo/editors/package-info.java b/o.n.core/src/org/netbeans/beaninfo/editors/package-info.java new file mode 100644 --- /dev/null +++ b/o.n.core/src/org/netbeans/beaninfo/editors/package-info.java @@ -0,0 +1,5 @@ +@PropertyEditorSearchPath +package org.netbeans.beaninfo.editors; + +import org.openide.nodes.PropertyEditorSearchPath; + diff --git a/o.n.core/src/org/netbeans/core/CoreBridgeImpl.java b/o.n.core/src/org/netbeans/core/CoreBridgeImpl.java --- a/o.n.core/src/org/netbeans/core/CoreBridgeImpl.java +++ b/o.n.core/src/org/netbeans/core/CoreBridgeImpl.java @@ -48,10 +48,12 @@ import java.io.File; import java.io.InputStream; import java.io.OutputStream; +import javax.swing.SwingUtilities; import org.netbeans.core.startup.CoreBridge; import org.netbeans.core.startup.MainLookup; import org.netbeans.core.startup.ManifestSection; import org.netbeans.swing.plaf.Startup; +import org.openide.nodes.NodeOp; import org.openide.util.NbBundle; import org.openide.util.RequestProcessor; import org.openide.util.lookup.ServiceProvider; @@ -173,20 +175,28 @@ private static final void doRegisterPropertyEditors() { //issue 31879 if (editorsRegistered) return; - String[] syspesp = PropertyEditorManager.getEditorSearchPath(); - String[] nbpesp = new String[] { - "org.netbeans.beaninfo.editors", // NOI18N - "org.openide.explorer.propertysheet.editors", // NOI18N - }; - String[] allpesp = new String[syspesp.length + nbpesp.length]; - System.arraycopy(nbpesp, 0, allpesp, 0, nbpesp.length); - System.arraycopy(syspesp, 0, allpesp, nbpesp.length, syspesp.length); - PropertyEditorManager.setEditorSearchPath(allpesp); - PropertyEditorManager.registerEditor (java.lang.Character.TYPE, org.netbeans.beaninfo.editors.CharEditor.class); - PropertyEditorManager.registerEditor(String[].class, org.netbeans.beaninfo.editors.StringArrayEditor.class); - // use replacement hintable/internationalizable primitive editors - issues 20376, 5278 - PropertyEditorManager.registerEditor (Integer.TYPE, org.netbeans.beaninfo.editors.IntEditor.class); - PropertyEditorManager.registerEditor (Boolean.TYPE, org.netbeans.beaninfo.editors.BoolEditor.class); +// String[] syspesp = PropertyEditorManager.getEditorSearchPath(); +// String[] nbpesp = new String[] { +// "org.netbeans.beaninfo.editors", // NOI18N +// "org.openide.explorer.propertysheet.editors", // NOI18N +// }; +// String[] allpesp = new String[syspesp.length + nbpesp.length]; +// System.arraycopy(nbpesp, 0, allpesp, 0, nbpesp.length); +// System.arraycopy(syspesp, 0, allpesp, nbpesp.length, syspesp.length); +// PropertyEditorManager.setEditorSearchPath(allpesp); +// PropertyEditorManager.registerEditor (java.lang.Character.TYPE, org.netbeans.beaninfo.editors.CharEditor.class); +// PropertyEditorManager.registerEditor(String[].class, org.netbeans.beaninfo.editors.StringArrayEditor.class); +// // use replacement hintable/internationalizable primitive editors - issues 20376, 5278 +// PropertyEditorManager.registerEditor (Integer.TYPE, org.netbeans.beaninfo.editors.IntEditor.class); +// PropertyEditorManager.registerEditor (Boolean.TYPE, org.netbeans.beaninfo.editors.BoolEditor.class); + + NodeOp.registerPropertyEditors(); + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + NodeOp.registerPropertyEditors(); + } + }); // install java.net.ProxySelector NbProxySelector.register(); diff --git a/openide.explorer/src/org/openide/explorer/propertysheet/editors/package-info.java b/openide.explorer/src/org/openide/explorer/propertysheet/editors/package-info.java new file mode 100644 --- /dev/null +++ b/openide.explorer/src/org/openide/explorer/propertysheet/editors/package-info.java @@ -0,0 +1,5 @@ +@PropertyEditorSearchPath +package org.openide.explorer.propertysheet.editors; + +import org.openide.nodes.PropertyEditorSearchPath; + diff --git a/openide.nodes/apichanges.xml b/openide.nodes/apichanges.xml --- a/openide.nodes/apichanges.xml +++ b/openide.nodes/apichanges.xml @@ -49,6 +49,24 @@ Nodes API + + + Adding @PropertyEditorRegistration and @PropertyEditorSearchPath annotations + + + + + +

+ Adding @PropertyEditorRegistration and @PropertyEditorSearchPath annotations + to allow convenient way of registering property editors. +

+
+ + + + +
ChildFactory.createKeys better supports incremental display diff --git a/openide.nodes/manifest.mf b/openide.nodes/manifest.mf --- a/openide.nodes/manifest.mf +++ b/openide.nodes/manifest.mf @@ -2,5 +2,5 @@ OpenIDE-Module: org.openide.nodes OpenIDE-Module-Localizing-Bundle: org/openide/nodes/Bundle.properties AutoUpdate-Essential-Module: true -OpenIDE-Module-Specification-Version: 7.29 +OpenIDE-Module-Specification-Version: 7.30 diff --git a/openide.nodes/nbproject/project.xml b/openide.nodes/nbproject/project.xml --- a/openide.nodes/nbproject/project.xml +++ b/openide.nodes/nbproject/project.xml @@ -66,6 +66,11 @@ + org.openide.filesystems + + + + org.openide.util diff --git a/openide.nodes/src/org/netbeans/modules/openide/nodes/PEAnnotationProcessor.java b/openide.nodes/src/org/netbeans/modules/openide/nodes/PEAnnotationProcessor.java new file mode 100644 --- /dev/null +++ b/openide.nodes/src/org/netbeans/modules/openide/nodes/PEAnnotationProcessor.java @@ -0,0 +1,158 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 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]" + * + * 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. + * + * Contributor(s): + * + * Portions Copyrighted 2012 Sun Microsystems, Inc. + */ +package org.netbeans.modules.openide.nodes; + +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Map.Entry; +import java.util.Set; +import javax.annotation.processing.Messager; +import javax.annotation.processing.Processor; +import javax.annotation.processing.RoundEnvironment; +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.AnnotationValue; +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.PackageElement; +import javax.lang.model.element.TypeElement; +import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.SimpleAnnotationValueVisitor6; +import javax.tools.Diagnostic.Kind; +import org.openide.filesystems.annotations.LayerBuilder; +import org.openide.filesystems.annotations.LayerGeneratingProcessor; +import org.openide.filesystems.annotations.LayerGenerationException; +import org.openide.nodes.PropertyEditorRegistration; +import org.openide.nodes.PropertyEditorSearchPath; +import org.openide.util.lookup.ServiceProvider; + +/** + * Processing annotation @PropertyEditorSearchPath + * and @PropertyEditorRegistration + * + * @author Jan Horvath + */ +@ServiceProvider(service=Processor.class) +public class PEAnnotationProcessor extends LayerGeneratingProcessor { + + public PEAnnotationProcessor() { + } + + @Override + public Set getSupportedAnnotationTypes() { + Set set = new HashSet(); + set.add(PropertyEditorSearchPath.class.getName()); + set.add(PropertyEditorRegistration.class.getName()); + return set; + } + + @Override + protected boolean handleProcess(Set annotations, RoundEnvironment roundEnv) + throws LayerGenerationException { + Messager messager = processingEnv.getMessager(); + for (Element e : roundEnv.getElementsAnnotatedWith(PropertyEditorSearchPath.class)) { + String pkg = findPackage(e); + String pkgFilename = pkg.replace(".", "-"); //NOI18N + LayerBuilder builder = layer(e); + LayerBuilder.File file = builder.file(PERegistrationSupport.LOOKUP_PATH + + "/Package-" + pkgFilename + ".instance"); //NOI18N + file.methodvalue("instanceCreate", PERegistrationSupport.class.getName(), + "createPackageRegistration"); //NOI18N + file.stringvalue(PERegistrationSupport.PACKAGE, pkg); + file.write(); + } + + for (Element e : roundEnv.getElementsAnnotatedWith(PropertyEditorRegistration.class)) { + if (e.getKind() == ElementKind.CLASS) { + String className = ((TypeElement) e).getQualifiedName().toString(); + Collection targetTypes = null; + List annotationMirrors = e.getAnnotationMirrors(); + for (AnnotationMirror am : annotationMirrors) { + for (Entry entry : am.getElementValues().entrySet()) { + if ("targetType".equals(entry.getKey().getSimpleName().toString())) { //NOI18N + targetTypes = (Collection) entry.getValue().getValue(); + } + } + } + if (targetTypes == null) { + messager.printMessage(Kind.ERROR, "No targetType is specified", e); //NOI18N + continue; + } + TypeElement typeElement = processingEnv.getElementUtils().getTypeElement("java.beans.PropertyEditor"); //NOI18N + if (!processingEnv.getTypeUtils().isSubtype(e.asType(), typeElement.asType())) { + messager.printMessage(Kind.ERROR, className + " is not subtype of PropertyEditor", e); //NOI18N + continue; + } + + LayerBuilder builder = layer(e); + String clsFileName = className.replace(".", "-"); //NOI18N + LayerBuilder.File file = builder.instanceFile(PERegistrationSupport.LOOKUP_PATH, "Class-" + clsFileName); //NOI18N + file.methodvalue("instanceCreate", PERegistrationSupport.class.getName(), "createClassRegistration"); //NOI18N + file.stringvalue(PERegistrationSupport.EDITOR_CLASS, className); //NOI18N + int i = 1; + for (AnnotationValue type : targetTypes) { + String clsName = type.accept(new SimpleAnnotationValueVisitor6() { + + @Override + public String visitType(TypeMirror t, Object p) { + return t.toString(); + } + }, null); + file.stringvalue("targetType." + i, clsName); //NOI18N + i++; + } + file.write(); + } + } + return true; + } + + private String findPackage(Element e) { + switch (e.getKind()) { + case PACKAGE: + return ((PackageElement) e).getQualifiedName().toString(); + default: + return findPackage(e.getEnclosingElement()); + } + } +} diff --git a/openide.nodes/src/org/netbeans/modules/openide/nodes/PERegistrationSupport.java b/openide.nodes/src/org/netbeans/modules/openide/nodes/PERegistrationSupport.java new file mode 100644 --- /dev/null +++ b/openide.nodes/src/org/netbeans/modules/openide/nodes/PERegistrationSupport.java @@ -0,0 +1,232 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 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]" + * + * 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. + * + * Contributor(s): + * + * Portions Copyrighted 2012 Sun Microsystems, Inc. + */ +package org.netbeans.modules.openide.nodes; + +import java.beans.PropertyEditorManager; +import java.lang.reflect.Array; +import java.util.Arrays; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.openide.util.Exceptions; +import org.openide.util.Lookup; +import org.openide.util.Lookup.Result; +import org.openide.util.LookupEvent; +import org.openide.util.LookupListener; + +/** + * Class for registering property editors. + * + * @author Jan Horvath + */ +public final class PERegistrationSupport { + + static final String LOOKUP_PATH = "Services/PropertyEditorManager"; //NOI18N + static final String PACKAGE = "packagePath"; //NOI18N + static final String EDITOR_CLASS = "propertyEditorClass"; //NOI18N + + static ClassReg clsReg = null; + static PkgReg pkgReg = null; + + public static synchronized void registerPropertyEditors() { + if (clsReg == null) { + clsReg = new ClassReg(); + } + if (pkgReg == null) { + pkgReg = new PkgReg(); + } + } + + /** + * Creates instance of PEPackageRegistration based on layer.xml + * attribute values + * + * @param attrs attributes loaded from layer.xml + * @return + */ + public static PEPackageRegistration createPackageRegistration(final Map attrs) { + String pkg = (String) attrs.get(PACKAGE); + return new PEPackageRegistration(pkg); + } + + /** + * Creates instance of PEClassRegistration based on layer.xml + * attribute values + * + * @param attrs attributes loaded from layer.xml + * @return + */ + public static PEClassRegistration createClassRegistration(final Map attrs) { + String editorClass = (String) attrs.get(EDITOR_CLASS); + Set targetTypes = new LinkedHashSet (); + for (int i = 1; ; i++) { + String targetType = (String) attrs.get("targetType." + i); //NOI18N + if (targetType == null) { + break; + } + targetTypes.add(targetType); + } + return new PEClassRegistration(editorClass, targetTypes); + } + + /** + * returns Class from canonical class name like java.lang.String[] + */ + protected static Class getClassFromCanonicalName(String name) throws ClassNotFoundException { + Class result; + String type = name; + int dimensions = 0; + while (type.endsWith("[]")) { //NOI18N + dimensions++; + type = type.substring(0, type.length() - 2); + } + if ("byte".equals(type)) { //NOI18N + result = byte.class; + } else if ("short".equals(type)) { //NOI18N + result = short.class; + } else if ("char".equals(type)) { //NOI18N + result = char.class; + } else if ("int".equals(type)) { //NOI18N + result = int.class; + } else if ("long".equals(type)) { //NOI18N + result = long.class; + } else if ("float".equals(type)) { //NOI18N + result = float.class; + } else if ("double".equals(type)) { //NOI18N + result = double.class; + } else if ("boolean".equals(type)) { //NOI18N + result = boolean.class; + } else { + ClassLoader clsLoader = Thread.currentThread().getContextClassLoader(); + result = Class.forName(type, true, clsLoader); + } + if (dimensions > 0) { + int d[] = new int[dimensions]; + for (int i = 0; i < d.length; i++) { + d[i] = 0; + } + result = Array.newInstance(result, d).getClass(); + } + return result; + } + + public static class PEPackageRegistration { + final String pkg; + + PEPackageRegistration(String pkg) { + this.pkg = pkg; + } + } + + public static class PEClassRegistration { + final Set targetTypes; + final String editorClass; + + PEClassRegistration(String editorClass, Set targetTypes) { + this.editorClass = editorClass; + this.targetTypes = targetTypes; + } + } + + private static final class ClassReg implements LookupListener { + Result lookupResult = null; + + ClassReg() { + lookupResult = Lookup.getDefault().lookupResult(PERegistrationSupport.PEClassRegistration.class); + register(); + lookupResult.addLookupListener(this); + } + + synchronized void register() { + lookupResult = Lookup.getDefault().lookupResult(PERegistrationSupport.PEClassRegistration.class); + ClassLoader clsLoader = Thread.currentThread().getContextClassLoader(); + + for (PEClassRegistration clsReg : lookupResult.allInstances()) { + for (String type : clsReg.targetTypes) { + try { + Class cls = getClassFromCanonicalName(type); + Class editorCls = Class.forName(clsReg.editorClass, true, clsLoader); + PropertyEditorManager.registerEditor(cls, editorCls); + } catch (ClassNotFoundException ex) { + Exceptions.printStackTrace(ex); + } + } + } + } + + @Override + public void resultChanged(LookupEvent ev) { + register(); + } + } + + static final class PkgReg implements LookupListener { + Result pkgResult; + private static List originalPath = null; + + PkgReg() { + if (originalPath == null) { + originalPath = Arrays.asList(PropertyEditorManager.getEditorSearchPath()); + } + pkgResult = Lookup.getDefault().lookupResult(PERegistrationSupport.PEPackageRegistration.class); + register(); + pkgResult.addLookupListener(this); + } + + synchronized void register() { + pkgResult = Lookup.getDefault().lookupResult(PERegistrationSupport.PEPackageRegistration.class); + Set newPath = new HashSet (); + for (PEPackageRegistration pkgReg : pkgResult.allInstances()) { + newPath.add(pkgReg.pkg); + } + newPath.addAll(originalPath); + PropertyEditorManager.setEditorSearchPath(newPath.toArray(new String[newPath.size()])); + } + + @Override + public void resultChanged(LookupEvent ev) { + register(); + } + } +} diff --git a/openide.nodes/src/org/openide/nodes/NodeOp.java b/openide.nodes/src/org/openide/nodes/NodeOp.java --- a/openide.nodes/src/org/openide/nodes/NodeOp.java +++ b/openide.nodes/src/org/openide/nodes/NodeOp.java @@ -56,6 +56,7 @@ import java.util.logging.Logger; import javax.swing.Action; import javax.swing.JPopupMenu; +import org.netbeans.modules.openide.nodes.PERegistrationSupport; import org.openide.util.Enumerations; import org.openide.util.Lookup; import org.openide.util.Utilities; @@ -458,6 +459,17 @@ public static NodeListener weakNodeListener(NodeListener l, Object source) { return WeakListeners.create(NodeListener.class, l, source); } + + /** Registers Property Editors and sets the Property Editors search path. + * + * @see PropertyEditorSearchPath + * @see PropertyEditorRegistration + * + * @since 7.30 + */ + public static void registerPropertyEditors() { + PERegistrationSupport.registerPropertyEditors(); + } /** more info in class javadoc. * @since 7.9 diff --git a/openide.nodes/src/org/openide/nodes/PropertyEditorRegistration.java b/openide.nodes/src/org/openide/nodes/PropertyEditorRegistration.java new file mode 100644 --- /dev/null +++ b/openide.nodes/src/org/openide/nodes/PropertyEditorRegistration.java @@ -0,0 +1,66 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 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]" + * + * 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. + * + * Contributor(s): + * + * Portions Copyrighted 2012 Sun Microsystems, Inc. + */ +package org.openide.nodes; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Register an editor class to be used to editor values of a given target class. + * Editor class must implement PropertyEditor interface. + * At runtime the editors are registered by {@link NodeOp#registerPropertyEditors() } + * + * @since 7.30 + * @author Jan Horvath + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface PropertyEditorRegistration { + + /** + * The Class object of the type to be edited + */ + Class[] targetType(); + +} diff --git a/openide.nodes/src/org/openide/nodes/PropertyEditorSearchPath.java b/openide.nodes/src/org/openide/nodes/PropertyEditorSearchPath.java new file mode 100644 --- /dev/null +++ b/openide.nodes/src/org/openide/nodes/PropertyEditorSearchPath.java @@ -0,0 +1,60 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 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]" + * + * 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. + * + * Contributor(s): + * + * Portions Copyrighted 2012 Sun Microsystems, Inc. + */ +package org.openide.nodes; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Add the annotated package to the list of package names that will be used for finding property editors. + * At runtime the path is registered by {@link NodeOp#registerPropertyEditors() } + * + * @since 7.30 + * @author Jan Horvath + */ +@Retention(RetentionPolicy.SOURCE) +@Target(ElementType.PACKAGE) +public @interface PropertyEditorSearchPath { + +} diff --git a/openide.nodes/test/unit/src/org/netbeans/modules/openide/nodes/PEAnnotationProcessorTest.java b/openide.nodes/test/unit/src/org/netbeans/modules/openide/nodes/PEAnnotationProcessorTest.java new file mode 100644 --- /dev/null +++ b/openide.nodes/test/unit/src/org/netbeans/modules/openide/nodes/PEAnnotationProcessorTest.java @@ -0,0 +1,151 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 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]" + * + * 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. + * + * Contributor(s): + * + * Portions Copyrighted 2012 Sun Microsystems, Inc. + */ +package org.netbeans.modules.openide.nodes; + +import java.beans.PropertyEditor; +import java.beans.PropertyEditorManager; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.Collection; +import org.netbeans.junit.NbTestCase; +import org.netbeans.modules.openide.nodes.PERegistrationSupport.PEClassRegistration; +import org.netbeans.modules.openide.nodes.PERegistrationSupport.PEPackageRegistration; +import org.openide.nodes.NodeOp; +import org.openide.util.Lookup; +import org.openide.util.test.AnnotationProcessorTestUtils; + +/** + * + * @author Jan Horvath + */ +public class PEAnnotationProcessorTest extends NbTestCase { + + static { + System.setProperty("org.openide.util.Lookup.paths", "Services"); + } + + public PEAnnotationProcessorTest(String name) { + super(name); + } + + @Override + protected void setUp() throws Exception { + clearWorkDir(); + } + + public void testDuplicateRegistration() { + NodeOp.registerPropertyEditors(); + NodeOp.registerPropertyEditors(); + + int count = 0; + String[] editorSearchPath = PropertyEditorManager.getEditorSearchPath(); + for (int i = 0; i < editorSearchPath.length; i++) { + if ("org.netbeans.modules.openide.nodes".equals(editorSearchPath[i])) { + count++; + } + } + assertEquals("Package path is registered multiple times", 1, count); + } + + public void testPERegistered() { + NodeOp.registerPropertyEditors(); + PropertyEditor pEditor = PropertyEditorManager.findEditor(Double[].class); + assertEquals("org.netbeans.modules.openide.nodes.TestPropertyEditor", pEditor.getClass().getName()); + pEditor = PropertyEditorManager.findEditor(Integer.class); + assertEquals("org.netbeans.modules.openide.nodes.TestPropertyEditor", pEditor.getClass().getName()); + pEditor = PropertyEditorManager.findEditor(char[][].class); + assertEquals("org.netbeans.modules.openide.nodes.TestPropertyEditor", pEditor.getClass().getName()); + pEditor = PropertyEditorManager.findEditor(short.class); + assertEquals("org.netbeans.modules.openide.nodes.TestPropertyEditor", pEditor.getClass().getName()); + } + + public void testClassRegistration() { + Collection lookup = Lookup.getDefault().lookupAll(PEClassRegistration.class); + assertTrue("failed to lookup class registrations", lookup.size() > 0); + PEClassRegistration classReg = lookup.iterator().next(); + assertEquals("org.netbeans.modules.openide.nodes.TestPropertyEditor", classReg.editorClass); + assertTrue(classReg.targetTypes.contains(Integer.class.getCanonicalName())); + assertTrue(classReg.targetTypes.contains(Double[].class.getCanonicalName())); + } + + public void testCheckForSubtype() throws IOException { + clearWorkDir(); + AnnotationProcessorTestUtils.makeSource(getWorkDir(), "test.A", + "import org.openide.nodes.PropertyEditorRegistration;\n" + + "@PropertyEditorRegistration(targetType={Integer.class})\n" + + "public class A {\n" + + "}\n" + ); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + boolean r = AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, getWorkDir(), null, os); + assertFalse("Compilation has to fail:\n" + os, r); + if (!os.toString().contains("is not subtype of PropertyEditor")) { + fail(os.toString()); + } + } + + public void testRegistrationOnMethod() throws IOException { + clearWorkDir(); + AnnotationProcessorTestUtils.makeSource(getWorkDir(), "test.A", + "import org.openide.nodes.PropertyEditorRegistration;\n" + + "public class A {\n" + + " @PropertyEditorRegistration(targetType={Integer.class})\n" + + " public void myMethod(String a) {\n" + + " }\n" + + "}\n" + ); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + boolean r = AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, getWorkDir(), null, os); + assertFalse("Compilation has to fail:\n" + os, r); + if (!os.toString().contains("not applicable")) { + fail(os.toString()); + } + } + + public void testPackageRegistration() { + Collection lookup = Lookup.getDefault().lookupAll(PEPackageRegistration.class); + assertTrue("failed to lookup class registrations", lookup.size() > 0); + PEPackageRegistration pkgReg = lookup.iterator().next(); + assertEquals("org.netbeans.modules.openide.nodes", pkgReg.pkg); + } + +} diff --git a/openide.nodes/test/unit/src/org/netbeans/modules/openide/nodes/PELookupTest.java b/openide.nodes/test/unit/src/org/netbeans/modules/openide/nodes/PELookupTest.java new file mode 100644 --- /dev/null +++ b/openide.nodes/test/unit/src/org/netbeans/modules/openide/nodes/PELookupTest.java @@ -0,0 +1,81 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 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]" + * + * 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. + * + * Contributor(s): + * + * Portions Copyrighted 2012 Sun Microsystems, Inc. + */ +package org.netbeans.modules.openide.nodes; + +import java.beans.PropertyEditorManager; +import org.netbeans.junit.NbTestCase; +import org.openide.nodes.NodeOp; +import org.openide.util.Exceptions; +import org.openide.util.test.MockLookup; + +/** + * + * @author Jan Horvath + */ +public class PELookupTest extends NbTestCase { + + public PELookupTest(String name) { + super(name); + } + + static { + System.setProperty("org.openide.util.Lookup.paths", "Services"); + } + + public void testPackageUnregistering() { + MockLookup.setInstances(new PERegistrationSupport.PEPackageRegistration("test1.pkg")); + NodeOp.registerPropertyEditors(); + MockLookup.setInstances(new PERegistrationSupport.PEPackageRegistration("test2.pkg")); + + String[] editorSearchPath = PropertyEditorManager.getEditorSearchPath(); + int count = 0; + for (int i = 0; i < editorSearchPath.length; i++) { + assertNotSame("test1.pkg", editorSearchPath[i]); + if ("test2.pkg".equals(editorSearchPath[i])) { + count++; + } + } + assertEquals(1, count); + + } + +} diff --git a/openide.nodes/test/unit/src/org/netbeans/modules/openide/nodes/PERegistrationSupportTest.java b/openide.nodes/test/unit/src/org/netbeans/modules/openide/nodes/PERegistrationSupportTest.java new file mode 100644 --- /dev/null +++ b/openide.nodes/test/unit/src/org/netbeans/modules/openide/nodes/PERegistrationSupportTest.java @@ -0,0 +1,83 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 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]" + * + * 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. + * + * Contributor(s): + * + * Portions Copyrighted 2012 Sun Microsystems, Inc. + */ +package org.netbeans.modules.openide.nodes; + +import org.netbeans.junit.NbTestCase; + +/** + * + * @author Jan Horvath + */ +public class PERegistrationSupportTest extends NbTestCase { + + public PERegistrationSupportTest(String name) { + super(name); + } + + public void doTest(String type) throws ClassNotFoundException { + Class cls = PERegistrationSupport.getClassFromCanonicalName(type); + assertEquals(type, cls.getCanonicalName()); + } + + public void testPrimitives() throws ClassNotFoundException { + String[] classNames = {"int", "boolean", "float", "short", "char"}; + for (int i = 0; i < classNames.length; i++) { + doTest(classNames[i]); + } + } + + public void testArrays() throws ClassNotFoundException { + String[] classNames = {"int[][][]", "boolean[]", "java.lang.String[]"}; + for (int i = 0; i < classNames.length; i++) { + doTest(classNames[i]); + } + } + + public void testTypes() throws ClassNotFoundException { + String[] classNames = {"java.lang.String", "java.lang.Integer"}; + for (int i = 0; i < classNames.length; i++) { + doTest(classNames[i]); + } + } + + +} diff --git a/openide.nodes/test/unit/src/org/netbeans/modules/openide/nodes/TestPropertyEditor.java b/openide.nodes/test/unit/src/org/netbeans/modules/openide/nodes/TestPropertyEditor.java new file mode 100644 --- /dev/null +++ b/openide.nodes/test/unit/src/org/netbeans/modules/openide/nodes/TestPropertyEditor.java @@ -0,0 +1,117 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 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]" + * + * 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. + * + * Contributor(s): + * + * Portions Copyrighted 2012 Sun Microsystems, Inc. + */ +package org.netbeans.modules.openide.nodes; + +import java.awt.Component; +import java.awt.Graphics; +import java.awt.Rectangle; +import java.beans.PropertyChangeListener; +import java.beans.PropertyEditor; +import org.openide.nodes.PropertyEditorRegistration; + +/** + * + * @author Jan Horvath + */ +@PropertyEditorRegistration(targetType = {Integer.class, Double[].class, byte.class, char[][].class, short.class}) +public final class TestPropertyEditor implements PropertyEditor { + + @Override + public void setValue(Object value) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Object getValue() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public boolean isPaintable() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void paintValue(Graphics gfx, Rectangle box) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public String getJavaInitializationString() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public String getAsText() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void setAsText(String text) throws IllegalArgumentException { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public String[] getTags() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Component getCustomEditor() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public boolean supportsCustomEditor() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void addPropertyChangeListener(PropertyChangeListener listener) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void removePropertyChangeListener(PropertyChangeListener listener) { + throw new UnsupportedOperationException("Not supported yet."); + } +} diff --git a/openide.nodes/test/unit/src/org/netbeans/modules/openide/nodes/package-info.java b/openide.nodes/test/unit/src/org/netbeans/modules/openide/nodes/package-info.java new file mode 100644 --- /dev/null +++ b/openide.nodes/test/unit/src/org/netbeans/modules/openide/nodes/package-info.java @@ -0,0 +1,5 @@ +@PropertyEditorSearchPath +package org.netbeans.modules.openide.nodes; + +import org.openide.nodes.PropertyEditorSearchPath; + diff --git a/xml.tax/manifest.mf b/xml.tax/manifest.mf --- a/xml.tax/manifest.mf +++ b/xml.tax/manifest.mf @@ -1,6 +1,5 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.xml.tax/2 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/xml/tax/resources/Bundle.properties -OpenIDE-Module-Install: org/netbeans/modules/xml/tax/TAXModuleInstall.class OpenIDE-Module-Requires: org.openide.modules.InstalledFileLocator diff --git a/xml.tax/src/org/netbeans/modules/xml/tax/TAXModuleInstall.java b/xml.tax/src/org/netbeans/modules/xml/tax/TAXModuleInstall.java --- a/xml.tax/src/org/netbeans/modules/xml/tax/TAXModuleInstall.java +++ b/xml.tax/src/org/netbeans/modules/xml/tax/TAXModuleInstall.java @@ -45,67 +45,41 @@ import java.beans.*; import java.util.Arrays; +import java.util.LinkedList; import java.util.List; -import java.util.LinkedList; - -import org.openide.modules.ModuleInstall; +import org.openide.modules.OnStart; +import org.openide.modules.OnStop; /** * Module installation class for tax module. * * @author Libor Kramolis */ -public class TAXModuleInstall extends ModuleInstall { +@OnStart +public class TAXModuleInstall implements Runnable { private static final String BEANINFO_PATH = "org.netbeans.modules.xml.tax.beans.beaninfo"; // NOI18N - private static final String EDITOR_PATH = "org.netbeans.modules.xml.tax.beans.editor"; - - /** - */ - public void restored () { - installBeans(); - } - - /** - */ - public void uninstalled () { - uninstallBeans(); - } - - - // - // beans - // - - /** - */ - private void installBeans () { + @Override + public void run () { String[] sp = Introspector.getBeanInfoSearchPath(); String[] newSP = new String[sp.length + 1]; System.arraycopy(sp, 0, newSP, 0, sp.length); newSP[newSP.length - 1] = BEANINFO_PATH; Introspector.setBeanInfoSearchPath(newSP); - - sp = PropertyEditorManager.getEditorSearchPath(); - newSP = new String[sp.length + 1]; - System.arraycopy(sp, 0, newSP, 0, sp.length); - newSP[newSP.length - 1] = EDITOR_PATH; - PropertyEditorManager.setEditorSearchPath(newSP); } - /** - */ - private void uninstallBeans () { - List searchPath; + @OnStop + public static final class Down implements Runnable{ + + @Override + public void run () { + List searchPath; - searchPath = new LinkedList (Arrays.asList (Introspector.getBeanInfoSearchPath())); - searchPath.remove (BEANINFO_PATH); - Introspector.setBeanInfoSearchPath ((String[])searchPath.toArray (new String[0])); - - searchPath = new LinkedList (Arrays.asList (PropertyEditorManager.getEditorSearchPath())); - searchPath.remove (EDITOR_PATH); - PropertyEditorManager.setEditorSearchPath ((String[])searchPath.toArray (new String[0])); + searchPath = new LinkedList (Arrays.asList (Introspector.getBeanInfoSearchPath())); + searchPath.remove (BEANINFO_PATH); + Introspector.setBeanInfoSearchPath ((String[])searchPath.toArray (new String[0])); + } } - + } diff --git a/xml.tax/src/org/netbeans/modules/xml/tax/beans/editor/package-info.java b/xml.tax/src/org/netbeans/modules/xml/tax/beans/editor/package-info.java new file mode 100644 --- /dev/null +++ b/xml.tax/src/org/netbeans/modules/xml/tax/beans/editor/package-info.java @@ -0,0 +1,5 @@ +@PropertyEditorSearchPath +package org.netbeans.modules.xml.tax.beans.editor; + +import org.openide.nodes.PropertyEditorSearchPath; +