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 158603 - Failure to serialize multiviews
Summary: Failure to serialize multiviews
Status: RESOLVED INCOMPLETE
Alias: None
Product: platform
Classification: Unclassified
Component: Window System (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker (vote)
Assignee: Stanislav Aubrecht
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-02-16 11:24 UTC by kitfox
Modified: 2012-04-26 07:31 UTC (History)
2 users (show)

See Also:
Issue Type: TASK
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description kitfox 2009-02-16 11:24:37 UTC
I have spent three weeks pulling my hair out trying to figure out how to serialize DataEditorSupport.  The mailing list
didn't even bother responding to my posts.

I have been following the ManifestEditor example presented in the Rich Client Programming book from Sun Microsystems. 
The sample code on the CD Rom for this example has bugs in it and will not compile - however, they are fairly obvious
and easy to fix.  Unfortunately, the example makes absolutely no attempt to make the ManifestEditor serializable.  This
means that whenever I close a netbeans session where my ManifestEditor is open, I will get an error when it attempts to
save the editor state to an object stream.  It also makes it impossible to clone views of the editor.

The problems seems to be the DataEditorSupport object itself.  It has no no-arg constructor, so I can't make my subclass
of it Serializable.  But I have to put a CloneableEditorSupport in my DataObject's lookup, so I can't proxy it with a
serializable object either.  I can find no examples on the web that help.  

I am quite angry that such an important feature has been left out of what I presumed was the official book on developing
plugins for Netbeans.  I am also angry that there has been absolutely no response to any of my queries on the developer
mailing list.  The entire Rich Client Programming book is full of omissions and never answers the core question I (and I
image most others) bought it for - creating a rich GUI editor for custom XML and Java files.
Comment 1 Jesse Glick 2009-02-18 03:11:06 UTC
You normally just use DataEditorSupport.create. It is the Env which is serializable, not the DES itself. (Not that lack
of a no-arg constructor prevents serialization anyway.) The default environment should be safely serializable with no
special steps, so I don't know why that would fail for a particular file type. Just to be sure, I just tried running
main/misc/platform/samples/ManifestSupport against a NB 7.0 dev build, and it worked fine - I could create a manifest
file, which was opened in the editor, and after restarting the IDE it was still there.

main/misc/platform/samples/ManifestEditor/src/org/netbeans/modules/manifesteditor/ManifestDataLoader.java is however
wrong - ManifestDataObject in that module is in a different package. After fixing that, I get

java.lang.AssertionError: MultiViewElement class org.netbeans.modules.manifesteditor.editor.ManifestSourceEditor returns
null as toolbar component.
        at org.netbeans.core.multiview.MultiViewPeer.peerComponentShowing(MultiViewPeer.java:203)

After also fixing that to return new JPanel(), I can confirm that open editor windows from this module are not saved.
Probably something to do with the use of the Multiview API.

I have no idea how and where issues with samples for the book are tracked, but as far as I know it isn't in the
product's IZ. CCing Geertjan who might be able to point you to an appropriate forum and issue errata. At least:

diff --git a/platform/samples/ManifestEditor/src/org/netbeans/modules/manifesteditor/ManifestDataLoader.java
b/platform/samples/ManifestEditor/src/org/netbeans/modules/manifesteditor/ManifestDataLoader.java
--- a/platform/samples/ManifestEditor/src/org/netbeans/modules/manifesteditor/ManifestDataLoader.java
+++ b/platform/samples/ManifestEditor/src/org/netbeans/modules/manifesteditor/ManifestDataLoader.java
@@ -54,7 +54,7 @@
     private static final long serialVersionUID = 1L;
 
     public ManifestDataLoader() {
-        super("org.netbeans.modules.manifesteditor.ManifestDataObject");
+        super("org.netbeans.modules.manifesteditor.editor.ManifestDataObject");
     }
 
     protected String defaultDisplayName() {
diff --git a/platform/samples/ManifestEditor/src/org/netbeans/modules/manifesteditor/editor/ManifestSourceEditor.java
b/platform/samples/ManifestEditor/src/org/netbeans/modules/manifesteditor/editor/ManifestSourceEditor.java
--- a/platform/samples/ManifestEditor/src/org/netbeans/modules/manifesteditor/editor/ManifestSourceEditor.java
+++ b/platform/samples/ManifestEditor/src/org/netbeans/modules/manifesteditor/editor/ManifestSourceEditor.java
@@ -59,7 +59,7 @@
 //            }
 //        }
 //        return toolbar;
-        return null;
+        return new JPanel();
     }
     
     public void setMultiViewCallback(MultiViewElementCallback callback) {
Comment 2 kitfox 2009-02-18 08:30:06 UTC
I think I've found a solution.  It involves making the ManifestEditorSupport member of ManifestVisualView transient.

I've also found a lot of problems with the way the SaveCookie was implemented and how the TopComponent name is updated.
 I've fixed them, and would be willing to contribute my changes back.  Is there some project somewhere that I could send
them?
Comment 3 Stanislav Aubrecht 2009-03-26 08:52:54 UTC
kitfox, attach your fixes as a patch to this issue (preferably with unit tests) and i'll push them into netbeans repository
Comment 4 David Simonek 2009-04-17 12:57:23 UTC
Any news here? kitfox could you give us your patches as announced, or are there any problems left? thanks.
Comment 5 kitfox 2009-04-18 00:58:33 UTC
It looks like I should have said that I was able to fix my version that was derived from the ManifestEditor example.  I
tried backporting my changes onto the Manifest example, but am getting a lot of problems with serialization.  I'll let
you know when I'm able to get something working going.
Comment 6 Marian Mirilovic 2009-07-17 10:29:22 UTC
kitfox, any updates ?
Comment 7 kitfox 2009-07-20 22:23:40 UTC
Sorry, I've gotten busy with other things and not gotten back to it.  I found that there were things specific to the
Manifest example object itself which were stopping me from porting my changes.  (I'm using a more generic JAXB derived
structure for my stuff).  So I might be able to produce a closely related example, but I don't think I'll be able to
shoehorn the Manifest object into it.