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.

Bug 80095 - Form Editor cannot load property editors registered globally
Summary: Form Editor cannot load property editors registered globally
Status: RESOLVED FIXED
Alias: None
Product: guibuilder
Classification: Unclassified
Component: Code (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker with 1 vote (vote)
Assignee: issues@guibuilder
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-07-12 19:14 UTC by vieiro
Modified: 2006-10-23 16:40 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
A simple NBM file (around 4Kb) that installs a custom property editor for colors (4.76 KB, application/octet-stream)
2006-07-12 22:09 UTC, vieiro
Details
Source code for previous NBM file (around 7Kb) (7.26 KB, application/octet-stream)
2006-07-12 22:11 UTC, vieiro
Details
Source code for tests, with a working getCustomEditor (10.53 KB, application/octet-stream)
2006-08-11 18:46 UTC, vieiro
Details

Note You need to log in before you can comment on or make changes to this bug.
Description vieiro 2006-07-12 19:14:28 UTC
The Form Editor cannot load Property Editors that, being bundled within a
module, are registered globally using PropertyEditorManager.registerEditor(...)
or FormPropertyEditorManager.registerEditor(...)

To reproduce this:

a) Build a custom property editor for, say, colors
(MyCustomColorPropertyEditor). Bundle it within a module and register it
globally following the guidelines at
http://platform.netbeans.org/tutorials/nbm-property-editors.html

b) Install that module.

c) Create a new JPanel in form editor. Modify the background color of the
JPanel. MyCustomColorPropertyEditor is correctly loaded and used to choose the
color.

d) Close the Form Editor.

e) Open the JPanel into the Form Editor again. The Form Editor is unable to load
 MyCustomColorPropertyEditor (ClassNotFoundException)



Evaluation:

GandalfPersistenceManager.getPropertyEditor (that seems to use
PersistentObjectRegistry.loadClass( String, FormFile ) ) does not look for
Property Editors in other modules, but in the Form Editor itself and in the
project classpath.

Could GandalfPersistenceManager use FormPropertyEditorManager to find
PropertyEditors by PropertyEditor class types?


Impact:

If the issue is not solved then
http://platform.netbeans.org/tutorials/nbm-property-editors.html should not be
used for Swing component properties (Colors, Strings, Borders, Icons, Booleans,
Integers, etc.). Otherwise the Form Editor won't be able to load ".form" files
again.
Comment 1 vieiro 2006-07-12 22:09:39 UTC
Created attachment 31789 [details]
A simple NBM file (around 4Kb) that installs a custom property editor for colors
Comment 2 vieiro 2006-07-12 22:11:36 UTC
Created attachment 31790 [details]
Source code for previous NBM file (around 7Kb)
Comment 3 vieiro 2006-07-12 22:24:31 UTC
I've attached a simple NBM that registers globally a PropertyEditor for Colors.
You can reproduce the issue by opening a form, selecting the background color
(use the text field for setting the color: I've not extended ExPropertyEditor,
so the ColorChooser does not set the color). Then close the form and open it
again: the PropertyEditor cannot be loaded.
Comment 4 vieiro 2006-07-14 20:48:24 UTC
Updated version to current, as this happens in NB6.0M1 too.

By the way, NB 6.0 M1 does not correctly report the exception, and the form
editor is not properly initialized.
Comment 5 Tomas Pavek 2006-08-08 18:12:17 UTC
Yes, we should fix this and load the globally registered property editors.

However you can make it work already now (in 5.0/5.5). You need to include the 
following snippet in the layer.xml file (enter your concrete package name where 
your property editor resides):

  <folder name="org-netbeans-modules-form">
    <folder name="classloader">
        <folder name="system">
            <file name="MyModuleClasses.txt">
            com.me.mypackage.**
            </file>
        </folder>
    </folder>
  </folder>


Note you should not register the property editor for common types like Color 
for which NetBeans have its own editors registered. You override the original 
property editor and break it for the whole IDE.
Comment 6 Tomas Pavek 2006-08-08 18:43:02 UTC
Fixed in trunk.

/cvs/form/src/org/netbeans/modules/form/GandalfPersistenceManager.java
new revision: 1.168; previous revision: 1.167
Comment 7 Tomas Pavek 2006-08-08 18:47:17 UTC
Note if you wanted an _additional_ editor for Color or other common type, you 
could make it available via the editor search path (in PropertyEditorManager).
Comment 8 vieiro 2006-08-08 19:53:01 UTC
Regarding...
  <folder name="org-netbeans-modules-form">
    <folder name="classloader">
        <folder name="system">
            <file name="MyModuleClasses.txt">
            com.me.mypackage.**
            </file>
        </folder>
    </folder>
  </folder>

Seems to work correctly, but if I extend ExPropertyEditor then
   public void attachEnv(PropertyEnv propertyEnv)
is never invoked :-(, so I think the change to GandalfPersistenceManager is the
way to go. I'll try that as soon as possible (1/2 weeks)

Regarding overriding NetBeans' property editors... I'm registering through
FormPropertyEditorManager (I'm cheating, I know) so the user can choose which
editor to use (from the combobox). That way I avoid overriding NetBeans'
built-in editors.

Thanks for the change,
Antonio



Comment 9 Tomas Pavek 2006-08-09 09:48:31 UTC
If you use FormPropertyEditorManager then you definitely need to register your 
name space in the xml. My fix is related only to use of 
java.beans.PropertyEditorManager (which is independent on form module).

I see no reason why your ExPropertyEditor should not work. Please double-check, 
or send us a test case. We also use ExPropertyEditor impls and they work fine. 
If your class is correctly loaded and the property editor displayed, then 
attachEnv should be called.
Comment 10 Tomas Pavek 2006-08-11 14:25:41 UTC
Just note that attachEnv might be called _after_ getCustumEditor, which might 
be confusing.
Comment 11 vieiro 2006-08-11 16:25:24 UTC
Hi,

My fault: attachEnv is being called, but if I invoke
FormPropertyEditorManager.registerEditor then the property is not modified when
using the custom editor.

The solution seems to be registering the editor through the XML snippet in
layer.xml. I don't seem to need to invoke neither
FormPropertyEditorManager.registerEditor *nor*
PropertyEditorManager.registerEditor. The XML snippet itself registers the
editor properly.

So, to summarize:
  - For common types just register the PropertyEditor using the XML snippet. Do
not use either FormPropertyEditorManager *nor* PropertyEditorManager to register
the Property Editor. The Form Editor will include the new PropertyEditor and
will *not* override existing editors. The user may still use any other older
(previously registered) editor.

So I assume this is the preferred way to enhance the Form Editor with new
PropertyEditors for common types.

I may be able to attach some simple module with a custom color editor. Shall I
do so? Just for the records?

Thanks,
Antonio
Comment 12 Tomas Pavek 2006-08-11 16:39:45 UTC
Yes please - if you can. Thanks
Comment 13 vieiro 2006-08-11 18:44:29 UTC
I was too fast stating that things were solved for me. The fact is that I was
opening a pre-existing project, with a form file that was referencing the
property editor. This is issue seems to be somewhat difficult to test. I suggest
following the next steps:

a) Clean & build the module. Cleaning is important!
b) Run the module. 
c) Create a *new* Java project (do not open a previous one as I was doing, since
the .form files may alter the test).
d) Create a new Form, and change the background color by pressing the [...]
button in the property.
e) Select the MyCustomColorEditor from the drop down box.
   e.1.) If the module Installer registers the editor using
PropertyEditorManager.registerEditor then a single MyCustomColorEditor is shown,
that works, and all the rest of editors are gone.
   e.2.) If the module Installer register the editor using
FormPropertyEditorManager.registerEditor then MyCustomColorEditor is shown
*twice*, and all the rest of editors are still there. None of the
MyCustomColorEditors (two of them) seems to work. The editor appears twice
depending on the XML snippet in layer.xml
f) Close the form. (The form is saved to a .form file)
g) Open the form again. The form is read from the .form file. 
    g.1) If the editor was registered from step e.1) then everything works.
    g.2.) If the editor was registered from step e.2) then the form may be
loaded only if the XML snippet is in place in layer.xml


I'll be attaching the source code for the test in a minute. Please contact me if
 I've not explained myself correctly.

Cheers,
Antonio
Comment 14 vieiro 2006-08-11 18:46:15 UTC
Created attachment 32847 [details]
Source code for tests, with a working getCustomEditor