Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Persisted state not persisted from a fragment?
Persisted state not persisted from a fragment? [message #1258797] Thu, 27 February 2014 19:23 Go to next message
Tamar Cohen is currently offline Tamar CohenFriend
Messages: 103
Registered: July 2009
Senior Member
My next E4 question -- I have a part defined in a separate plugin and contributed by a fragment.e4xmi. It's rendering fine. I have a @PersistState method that gets called correctly:

@PersistState
public void persistState(MPart part){
part.getPersistedState().put(SELECTED_FOLDERS, m_fileList.toString());
}

Problem is, when I reinvoke my part on the next @PostConstruct, the persisted data is empty:

@PostConstruct
public void createControls(Composite parent, EMenuService menuService, MPart part) {
initializeFileList(part);
//etc
}

private void initializeFileList(MPart part){
String persistedFiles = part.getPersistedState().get(SELECTED_FOLDERS);

}

very simple code here. Is the problem because this is in a fragment? Do I have to set something in my application to keep the contents of the persisted state?

Thanks

Tamar Cohen
Intelligent Robotics Group
NASA Ames Research Center
Re: Persisted state not persisted from a fragment? [message #1259357 is a reply to message #1258797] Fri, 28 February 2014 09:41 Go to previous messageGo to next message
Eclipse UserFriend
Are you starting with -clearPersistedState in the program arguments?
Re: Persisted state not persisted from a fragment? [message #1262447 is a reply to message #1259357] Mon, 03 March 2014 16:49 Go to previous messageGo to next message
Tamar Cohen is currently offline Tamar CohenFriend
Messages: 103
Registered: July 2009
Senior Member
no, that would have been too obvious. Smile I am not.
Re: Persisted state not persisted from a fragment? [message #1262645 is a reply to message #1262447] Mon, 03 March 2014 21:34 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
This is a bug with fragments - the problem is that fragments are merged
back in on each and every restart.

See https://bugs.eclipse.org/bugs/show_bug.cgi?id=389663

Tom

On 03.03.14 17:49, Tamar Cohen wrote:
> no, that would have been too obvious. :) I am not.
Re: Persisted state not persisted from a fragment? [message #1263675 is a reply to message #1262645] Tue, 04 March 2014 17:32 Go to previous messageGo to next message
Tamar Cohen is currently offline Tamar CohenFriend
Messages: 103
Registered: July 2009
Senior Member
Thanks Tom.

I've read through that bug and I think I understand the issues that are being discussed in the bug.
In our case, it's not a layout or e4xmi issue, it is simply a list of files that I want to persist, though down the road I'm quite sure that our users would want to persist their workbench state. We need this working in April (2014).

I'm working on an older 4.3 build from last May, I will update to 4.4M5 but from your comments on the bug you have not fixed this issue yet.

What would you suggest as a workaround? I'm pretty much the main Eclipse promoter in a few NASA groups these days and I want to migrate to E4 (finally) ...

thanks

Tamar
Re: Persisted state not persisted from a fragment? [message #1263720 is a reply to message #1263675] Tue, 04 March 2014 18:24 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Yes your problem is that same, the persistedState is stored in the e4xmi
(which is one big file on shutdown you'll find the information you store
in the workbench.e4xmi store in your workspace).

It looks something like this:

<children type="MPartStack" elementId="contributed">
<!-- You fragment contribution -->
<children type="MPart" ....>
<persistedState>
.....
</persistedState>
</children>
</children>

When the loading model we first deserialize the above but then we
overwrite the the contributed element with the one from the fragment (=>
the persisted state is gone).

Solutions in 4.3:
-----------------
a) don't use fragments use processors where you do everything
programmatically

b) roll your own custom model loading

I really hope to get this in M7 which would be too late for your either
and requires 4.4.

If I'd be you I'd go with b) its extremly easy to make the framework use
your own resource loading strategy.

a) copy the current loader to your custom bundle

b) copy the current assembled to your custom bundle
do something similar I do in the above patch - most easy solution is
to skip merging when you don't come from a persisted-state

c) add property to your product extension point
name=modelResourceHandler
value=bundleclass://YOUR_BUNDLE/YOUR_HANDLER


Tom

On 04.03.14 18:32, Tamar Cohen wrote:
> Thanks Tom.
> I've read through that bug and I think I understand the issues that are
> being discussed in the bug. In our case, it's not a layout or e4xmi
> issue, it is simply a list of files that I want to persist, though down
> the road I'm quite sure that our users would want to persist their
> workbench state. We need this working in April (2014).
> I'm working on an older 4.3 build from last May, I will update to 4.4M5
> but from your comments on the bug you have not fixed this issue yet.
>
> What would you suggest as a workaround? I'm pretty much the main Eclipse
> promoter in a few NASA groups these days and I want to migrate to E4
> (finally) ...
>
> thanks
> Tamar
Re: Persisted state not persisted from a fragment? [message #1263795 is a reply to message #1263720] Tue, 04 March 2014 19:48 Go to previous messageGo to next message
Tamar Cohen is currently offline Tamar CohenFriend
Messages: 103
Registered: July 2009
Senior Member
Thanks so much Tom. I've updated to Luna M5 and will try rolling my own custom model loading.

Tamar
Re: Persisted state not persisted from a fragment? [message #1264480 is a reply to message #1263795] Wed, 05 March 2014 08:56 Go to previous messageGo to next message
Eclipse UserFriend
I already did this for our tutorial in Boston so you have a project which shows precisely this here: https://github.com/tomsontom/eclipsecon-tutorial/blob/master/testMA

You can see the declaration in the plugin.xml file which tells the framework to swap the model assembler. I guess you can start from there.
Re: Persisted state not persisted from a fragment? [message #1715591 is a reply to message #1258797] Tue, 24 November 2015 14:36 Go to previous message
Gordon Da is currently offline Gordon DaFriend
Messages: 1
Registered: November 2015
Junior Member
Hello,

thanks to all for the contributions. But i think, that the problem is not solved with https://bugs.eclipse.org/bugs/show_bug.cgi?id=389663 as Thomas wrote.

I'm using eclipse Mars (4.5) and still have the same problem as Tamar. After the merge of the fragment.e4xmi all my persisted states are cleared. I took the suggestion to register my own modelResourceHandler which references a copy of the original org.eclipse.e4.ui.internal.workbenchResourceHandler. The only thing i changed was in the copy of org.eclipse.e4.ui.internal.workbench.ModelAssembler before line 176 in processFragment(...):

if (checkExist && applicationResource.getIDToEObjectMap().containsKey(r.getID(o))) {
	continue;
}

// NEW: copy persisted state into new object before replacing
MApplicationElement orig = (MApplicationElement) applicationResource.getIDToEObjectMap().get(r.getID(o));
for (Entry<String, String> entry : orig.getPersistedState().entrySet())
	((MApplicationElement) o).getPersistedState().put(entry.getKey(), entry.getValue());

applicationResource.setID(o, r.getID(o));


This workaround works for me. But i don't like this solution because its based on duplicated code. Also see https://bugs.eclipse.org/bugs/show_bug.cgi?id=482909
Previous Topic:container data stopped working
Next Topic:Validate plug-ins: Missing Constraint on bundle
Goto Forum:
  


Current Time: Tue Apr 16 16:23:24 GMT 2024

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

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

Back to the top