Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » How to correctly setup run config or plugin.xml or ... to make use of persistedState in (custom) Men
How to correctly setup run config or plugin.xml or ... to make use of persistedState in (custom) Men [message #1405476] Thu, 07 August 2014 12:43 Go to next message
Marina Knieling is currently offline Marina KnielingFriend
Messages: 83
Registered: February 2013
Member
Hey guys,

I'd like to use the persistedState of model elements in order to reset
some custom arranged elements on startup.

I wrote my own renderer for some elements (especially MMenu and
MMenuItems) and I also have a Snippet (Part) that holds those
Menu(Items). The user can change the order of these MenuItems via drag
and drop and I want to persist this custom order.

In my Part Snippet I added a method annotated with @PersistState and
iterate through all Children of the part and set the persistedState in
the corresponding MenuItems. When I look at the persisted Model
(workbench.xmi) after closing the application I can see that the values
are correctly stored.

However, when I now restart my application and have a look into the
loaded model (via live model editor) those values are gone. I've read
about bug 389663 (as I also have some menus in fragments) and it says it
is fixed in Luna M7. I updated my target platform to Luna (IDE is still
Kepler) in order to find out whether this will fix my problem, but it
didn't. I added the "apply" attribute to my fragment but that didn't
help either. None of my persistedStates are restored (not even those
from the main Application.e4xmi).

Am I missing anything or did I do anything wrong? Please help.

Thanks
Marina Knieling
Re: How to correctly setup run config or plugin.xml or ... to make use of persistedState in (custom) [message #1405822 is a reply to message #1405476] Fri, 08 August 2014 08:58 Go to previous messageGo to next message
Marina Knieling is currently offline Marina KnielingFriend
Messages: 83
Registered: February 2013
Member
Ok, I narrowed it down a bit (thanks to this thread:
http://www.eclipse.org/forums/index.php/t/441499/)

Step #1: removing -clearPersistedState from the arguments in the
runconfig isn't enough, you have to explicitly set -persistState

Step #2: uncheck "Clear workspace" on the Main tab in the runconfig.
Otherwise the folder with your persisted workbench.xmi is deleted before
the ResourceHandler can do his work

Step #3: If you use your own renderer, make sure you don't add things to
the model that have already bean reloaded from the persisted model. Here
I'm not quite sure which elements tend to get added each and every time
and which not.

For example: I added a part for a MMenu which sits directly under the
MainMenu. Without checking whether this part already exists, I got a new
one each time I started my application.
My MenuItems (which are added as child widgets to the Composite of the
Menupart) didn't get newly added, but the MenuContribution that had the
MMenu as parent, still is added every time I start the application.

I will further investigate this and report back when I find a solution.

Cheers,
Marina


On 07.08.2014 14:43, Marina Knieling wrote:
> Hey guys,
>
> I'd like to use the persistedState of model elements in order to reset
> some custom arranged elements on startup.
>
> I wrote my own renderer for some elements (especially MMenu and
> MMenuItems) and I also have a Snippet (Part) that holds those
> Menu(Items). The user can change the order of these MenuItems via drag
> and drop and I want to persist this custom order.
>
> In my Part Snippet I added a method annotated with @PersistState and
> iterate through all Children of the part and set the persistedState in
> the corresponding MenuItems. When I look at the persisted Model
> (workbench.xmi) after closing the application I can see that the values
> are correctly stored.
>
> However, when I now restart my application and have a look into the
> loaded model (via live model editor) those values are gone. I've read
> about bug 389663 (as I also have some menus in fragments) and it says it
> is fixed in Luna M7. I updated my target platform to Luna (IDE is still
> Kepler) in order to find out whether this will fix my problem, but it
> didn't. I added the "apply" attribute to my fragment but that didn't
> help either. None of my persistedStates are restored (not even those
> from the main Application.e4xmi).
>
> Am I missing anything or did I do anything wrong? Please help.
>
> Thanks
> Marina Knieling
>
Re: How to correctly setup run config or plugin.xml or ... to make use of persistedState in (custom) [message #1405848 is a reply to message #1405822] Fri, 08 August 2014 09:42 Go to previous message
Marina Knieling is currently offline Marina KnielingFriend
Messages: 83
Registered: February 2013
Member
Last part of the riddle solved:

It wasn't a problem with my specific renderer, but appeared also with
the default renderer.

In the ContributionsAnalyzer.processAdditions(MMenu ...) method, there
are only checks on existing MMenu and MMenuSeperator, but not on
MMenuItems. As it is valid to put a MHandledMenuItem directly under a
MenuContribution, my menu entry was added each time. I copied that
method in my MenuRenderer, added the check for existing MenuItem Ids and
now it works.

BTW: the same problem will probably appear with ToolBarItems and
TrimBarItems (as there is no check either). I'm not sure whether this
check is left out intentionally or if it was just forgotten.
Maybe I file a bug and see what happens ;-)

Cheers, Marina

On 08.08.2014 10:58, Marina Knieling wrote:
> Ok, I narrowed it down a bit (thanks to this thread:
> http://www.eclipse.org/forums/index.php/t/441499/)
>
> Step #1: removing -clearPersistedState from the arguments in the
> runconfig isn't enough, you have to explicitly set -persistState
>
> Step #2: uncheck "Clear workspace" on the Main tab in the runconfig.
> Otherwise the folder with your persisted workbench.xmi is deleted before
> the ResourceHandler can do his work
>
> Step #3: If you use your own renderer, make sure you don't add things to
> the model that have already bean reloaded from the persisted model. Here
> I'm not quite sure which elements tend to get added each and every time
> and which not.
>
> For example: I added a part for a MMenu which sits directly under the
> MainMenu. Without checking whether this part already exists, I got a new
> one each time I started my application.
> My MenuItems (which are added as child widgets to the Composite of the
> Menupart) didn't get newly added, but the MenuContribution that had the
> MMenu as parent, still is added every time I start the application.
>
> I will further investigate this and report back when I find a solution.
>
> Cheers,
> Marina
>
>
> On 07.08.2014 14:43, Marina Knieling wrote:
>> Hey guys,
>>
>> I'd like to use the persistedState of model elements in order to reset
>> some custom arranged elements on startup.
>>
>> I wrote my own renderer for some elements (especially MMenu and
>> MMenuItems) and I also have a Snippet (Part) that holds those
>> Menu(Items). The user can change the order of these MenuItems via drag
>> and drop and I want to persist this custom order.
>>
>> In my Part Snippet I added a method annotated with @PersistState and
>> iterate through all Children of the part and set the persistedState in
>> the corresponding MenuItems. When I look at the persisted Model
>> (workbench.xmi) after closing the application I can see that the values
>> are correctly stored.
>>
>> However, when I now restart my application and have a look into the
>> loaded model (via live model editor) those values are gone. I've read
>> about bug 389663 (as I also have some menus in fragments) and it says it
>> is fixed in Luna M7. I updated my target platform to Luna (IDE is still
>> Kepler) in order to find out whether this will fix my problem, but it
>> didn't. I added the "apply" attribute to my fragment but that didn't
>> help either. None of my persistedStates are restored (not even those
>> from the main Application.e4xmi).
>>
>> Am I missing anything or did I do anything wrong? Please help.
>>
>> Thanks
>> Marina Knieling
>>
>
Previous Topic:@PreDestroy for singletons
Next Topic:eclipse luna maven src attachment not working unless I specify the src location
Goto Forum:
  


Current Time: Fri Jun 25 05:22:29 GMT 2021

Powered by FUDForum. Page generated in 0.02023 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top