Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Save reference of input of a Part(Eclipse 4)
Save reference of input of a Part [message #896766] Thu, 19 July 2012 16:25 Go to next message
Valerio Santinelli is currently offline Valerio SantinelliFriend
Messages: 39
Registered: January 2012
Member
Hello,

I'm slowly trying to port an existing RCP application to the 4.2 framework and I can't understand one important thing.

I have a handler that is being called to open a new part. Before showing the part, I inject the input needed by that part in the application context and then i show the part and it works fine.

I then close the application and reopen it. When the application reopens the part that whose state was saved by the workbench, I get an error saying that it can't inject the input property because it can't be found in the context. How am I supposed to persist it?

Thanks in advance!
Re: Save reference of input of a Part [message #896812 is a reply to message #896766] Thu, 19 July 2012 21:45 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
All context informations are temporary and not saved (most of them could
be saved at all).

You store informations directly in the MPart associated with your part
by creating something like this in your class

class MyPart {
@Inject
public MyPart(MPart p) {
....
}

@PersistState
void persist(MPart part) {
part.getPersistedState()
}
}

So when you create you part using the handler before showing it I'd also
set the informations instead of using the IEclipseContext.

The other option you have is to create an MInputPart which has a url field.

You better ask e4 questions on the e4 newsgroup.

Tom

Am 19.07.12 18:26, schrieb Valerio Santinelli:
> Hello,
>
> I'm slowly trying to port an existing RCP application to the 4.2
> framework and I can't understand one important thing.
>
> I have a handler that is being called to open a new part. Before showing
> the part, I inject the input needed by that part in the application
> context and then i show the part and it works fine.
>
> I then close the application and reopen it. When the application reopens
> the part that whose state was saved by the workbench, I get an error
> saying that it can't inject the input property because it can't be found
> in the context. How am I supposed to persist it?
> Thanks in advance!
>
Re: Save reference of input of a Part [message #896813 is a reply to message #896812] Thu, 19 July 2012 22:01 Go to previous messageGo to next message
Valerio Santinelli is currently offline Valerio SantinelliFriend
Messages: 39
Registered: January 2012
Member
Thanks for the reply Tom.

I actually went for the MInputPart route from the beginning, following a tutorial by Lars Vogel but after I set the URI of my input, I don't have a clue of what to o with that URI because I'm still using the old InputAdapter I used with 3.x and I'm not accessing the real input object directly.

Is it possible to store generic objects in the Map returne by getPersistedState?
Re: Save reference of input of a Part [message #896815 is a reply to message #896813] Thu, 19 July 2012 22:41 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
No the problem is that we need to persits this and so you need to deal
with the serialization and deserialization.

Tom

Am 20.07.12 00:01, schrieb Valerio Santinelli:
> Thanks for the reply Tom.
>
> I actually went for the MInputPart route from the beginning, following a
> tutorial by Lars Vogel but after I set the URI of my input, I don't have
> a clue of what to o with that URI because I'm still using the old
> InputAdapter I used with 3.x and I'm not accessing the real input object
> directly.
>
> Is it possible to store generic objects in the Map returne by
> getPersistedState?
>
Re: Save reference of input of a Part [message #896846 is a reply to message #896815] Fri, 20 July 2012 06:40 Go to previous messageGo to next message
Valerio Santinelli is currently offline Valerio SantinelliFriend
Messages: 39
Registered: January 2012
Member
Ok so there isn't a standard serialization way like there was with IMemento.

If I just move to the InputURI way and use that URI as the path to the serialized object, then I could put the URI in the getPersistedState map.
But then I'd have to deserialize it in the part itself. Wouldn't that break the DI pattern as I'd have to instantiate my real input object from within the part? How does Eclipse IDE accomplish that with its text editor?
Re: Save reference of input of a Part [message #896853 is a reply to message #896846] Fri, 20 July 2012 07:08 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
No there's none but frankly I think IMemento was a horrible way of
storing structure data IMHO. If you have beans to store I'd use
something like JAXB or xstream.

The uri-field is restored so there's no need to put that URI in the map,
although MInputPart's main idea is to be used for file based editors.

I don't see how restoring the state is breaking the DI pattern - you are
simply transforming the input you get from the map - the framework can't
know how to deserialize your object. The only thing I currently don't
really like is that one gets a dependency on MPart to access the
persitedState map - because this ties your code to e4 framework.

I'd more like to see something like this in 4.3:

public class MyPart {
@PostConstruct
void init(@StateMap Map<String,String> map) {
// restore state from map
}

@PersistState
void persist(@StateMap Map<String,String> map) {
// store state in map
}
}


If you think that there's a *general* solution to the problem we are
happy to integrate it into the framework.

We are working on editor stuff in 4.3 which will bring similar stuff
like IEditorInput for MInputParts hopefully.

Tom

Am 20.07.12 08:40, schrieb Valerio Santinelli:
> Ok so there isn't a standard serialization way like there was with
> IMemento.
>
> If I just move to the InputURI way and use that URI as the path to the
> serialized object, then I could put the URI in the getPersistedState map.
> But then I'd have to deserialize it in the part itself. Wouldn't that
> break the DI pattern as I'd have to instantiate my real input object
> from within the part? How does Eclipse IDE accomplish that with its text
> editor?
>
Re: Save reference of input of a Part [message #896859 is a reply to message #896853] Fri, 20 July 2012 07:40 Go to previous message
Valerio Santinelli is currently offline Valerio SantinelliFriend
Messages: 39
Registered: January 2012
Member
I agree with you when you say that IMemento was horrible for storing structured data. My editor is file based and I've just tried deserializing the content in an init() function that gets injected and it works a charm.

On the other hand I had to rely on my old singleton object that manages all of the open projects (files) as I haven't yet moved to an OSGi service pattern all of those classes. I guess I'll have to do that at some point in order to decouple everything. But at least now I've got something partially working.

As you say, it'd be nice to get the persisted state as a parameter of the method called by @PostConstruct.

Thanks for all the help in getting me going in the right direction.


Previous Topic:Save reference of input of a Part
Next Topic:Running a 3.x RCP application with Eclipse 4.2
Goto Forum:
  


Current Time: Sat Oct 05 00:22:45 GMT 2024

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

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

Back to the top