You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@netbeans.apache.org by Peter Nabbefeld <pe...@gmx.de> on 2020/11/30 19:10:32 UTC

How to save data from a MultiViewElement?

Hello,

after creating a MultiViewElement for some web-related data, now I have
problems to persist the relevant data (link). I couldn't manage to use
@ConvertAsProperties; it seems, the History tab does not implement
Serializable, but MultiViewPeer tries to store every MultiViewElement or
sth. like that.

I've even tried to use Preferences to probably build my own persistant
storage logic, but there's no event "componentClosed" when I close NetBeans.

So, how can I save my data from a MultiViewElement?

Kind regards

Peter

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@netbeans.apache.org
For additional commands, e-mail: dev-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists




Re: How to save data from a MultiViewElement?

Posted by Oliver Rettig <Ol...@orat.de>.
Hi Peter,
very thanks for your detailed and interesting explainations. Can you put it in the FAQ. It 
motivates me to have a look at some of my very old MultiViewElements to think about to 
make them persistance.
best regards
Oliver
> Hello,
> 
> in the meantime I've found out what to do:
> 
> 1. Besides registering the MultiViewElement with PERSISTENCE_ONLY_OPENED
> (or PERSISTENCE_ALWAYS, if You need to), the JPanel (or probably other
> type of component) implementing MultiViewElement must be serializable.
> But be aware of the pitfalls!
> 
> 2. If Your component has a GroupLayout (i.e. created with "Free
> design"), this will fail, at least if You're using Java 8: The layout
> does not implement Serializable. I don't see any sense in persisting the
> component, either, so better implement Externalizable and do the
> serialization on Your own.
> 
> 3. You save every state of Your MultiViewElements separately; probably
> it'd be possible to make one of them the "master" and look for it using
> TopComponent.getSubComponents().
> 
> 4. Also, the MultiViewTopComponent tries to save the provided Lookup, at
> least if You create Your views from mime. So be careful what You put
> into Your lookup, it has to be serializable (You can implement
> Externalizable on its elements, of course, so You have full control)!
> 
> 5. If You don't want a "History" tab, it's probably better to not use
> mime, as the tab is appended then automatically. I've done some strange
> coding to just create my MultiViewElements from mime-type, though this
> type is already "synthetic", as I'm using some un-typed web resource
> (i.e. it isn't usually stored anywhere in the file-system). I'll change
> it to an interface definition, so I can use my own lookup, or I'll use
> an XML layer - there're many better possibilities.
> 
> Kind regards
> 
> Peter
> 
> Am 01.12.20 um 06:47 schrieb P.N.:
> > Thank You, Ernie. Yes, the VM bulldozer might be an option, but only as a
> > last resort, as the IDE registers its own shutdown hooks, AFAIK, and
> > these may probably interfere. But this took me to some other possibility:
> > using @OnStop is NetBeans' way to register such hooks - and that will
> > probably fit perfectly.
> > 
> > However, some better support for persistence would be very nice ...
> > probably some methods could be added to MultiViewCallback?
> > 
> > Kind regards
> > Peter
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@netbeans.apache.org
> > For additional commands, e-mail: dev-help@netbeans.apache.org
> > 
> > For further information about the NetBeans mailing lists, visit:
> > https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@netbeans.apache.org
> For additional commands, e-mail: dev-help@netbeans.apache.org
> 
> For further information about the NetBeans mailing lists, visit:
> https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists



Re: How to save data from a MultiViewElement?

Posted by Peter Nabbefeld <pe...@gmx.de>.
Hello,

in the meantime I've found out what to do:

1. Besides registering the MultiViewElement with PERSISTENCE_ONLY_OPENED
(or PERSISTENCE_ALWAYS, if You need to), the JPanel (or probably other
type of component) implementing MultiViewElement must be serializable.
But be aware of the pitfalls!

2. If Your component has a GroupLayout (i.e. created with "Free
design"), this will fail, at least if You're using Java 8: The layout
does not implement Serializable. I don't see any sense in persisting the
component, either, so better implement Externalizable and do the
serialization on Your own.

3. You save every state of Your MultiViewElements separately; probably
it'd be possible to make one of them the "master" and look for it using
TopComponent.getSubComponents().

4. Also, the MultiViewTopComponent tries to save the provided Lookup, at
least if You create Your views from mime. So be careful what You put
into Your lookup, it has to be serializable (You can implement
Externalizable on its elements, of course, so You have full control)!

5. If You don't want a "History" tab, it's probably better to not use
mime, as the tab is appended then automatically. I've done some strange
coding to just create my MultiViewElements from mime-type, though this
type is already "synthetic", as I'm using some un-typed web resource
(i.e. it isn't usually stored anywhere in the file-system). I'll change
it to an interface definition, so I can use my own lookup, or I'll use
an XML layer - there're many better possibilities.

Kind regards

Peter




Am 01.12.20 um 06:47 schrieb P.N.:
> Thank You, Ernie. Yes, the VM bulldozer might be an option, but only as a last resort, as the IDE registers its own shutdown hooks, AFAIK, and these may probably interfere. But this took me to some other possibility: using @OnStop is NetBeans' way to register such hooks - and that will probably fit perfectly.
>
> However, some better support for persistence would be very nice ... probably some methods could be added to MultiViewCallback?
>
> Kind regards
> Peter
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@netbeans.apache.org
> For additional commands, e-mail: dev-help@netbeans.apache.org
>
> For further information about the NetBeans mailing lists, visit:
> https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@netbeans.apache.org
For additional commands, e-mail: dev-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists




Re: How to save data from a MultiViewElement?

Posted by "P.N." <pe...@gmx.de>.
Thank You, Ernie. Yes, the VM bulldozer might be an option, but only as a last resort, as the IDE registers its own shutdown hooks, AFAIK, and these may probably interfere. But this took me to some other possibility: using @OnStop is NetBeans' way to register such hooks - and that will probably fit perfectly.

However, some better support for persistence would be very nice ... probably some methods could be added to MultiViewCallback?

Kind regards
Peter

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@netbeans.apache.org
For additional commands, e-mail: dev-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists




Re: How to save data from a MultiViewElement?

Posted by Ernie Rael <er...@raelity.com>.
On 11/30/2020 11:10 AM, Peter Nabbefeld wrote:
>
> Hello,
>
> after creating a MultiViewElement for some web-related data, now I have
> problems to persist the relevant data (link). I couldn't manage to use
> @ConvertAsProperties; it seems, the History tab does not implement
> Serializable, but MultiViewPeer tries to store every MultiViewElement or
> sth. like that.
>
> I've even tried to use Preferences to probably build my own persistant
> storage logic, but there's no event "componentClosed" when I close 
> NetBeans.
>
> So, how can I save my data from a MultiViewElement?
Can you use "Runtime.getRuntime().addShutdownHook(...)"?||
>
> Kind regards
>
> Peter
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@netbeans.apache.org
> For additional commands, e-mail: dev-help@netbeans.apache.org
>
> For further information about the NetBeans mailing lists, visit:
> https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
>
>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@netbeans.apache.org
For additional commands, e-mail: dev-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists