Reputation: 149
Hey guys I'd like to deal with persisted data in order to save my Application Status before quitting. Well in order to give it a try I created a dirtyable object in an MPART then added a saving handler linked to a menu entry.
Here it's: MPART:
txtInput.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
dirty.setDirty(true);
}
});
Handler:
@Execute
public void execute(EPartService partService) {
partService.saveAll(false);
}
At the end I also removed the -clearpersistedstate argument from the running configuration but every time I launch my app, it doesn't save changes inside the MPART but only changes at perspective level E.g: If an MPART has been closed in the following execution it will be kept closed.
Any hints?
Upvotes: 1
Views: 803
Reputation: 111142
EPartService.saveAll
just calls any method annotated with @Persist
in the parts. This will be done automatically when the workspace is shutdown anyway.
Note: The part must be marked as dirty for the @Persist method to be called.
So to save any details in your part you need a method:
@Persist
void save()
{
... save your data somewhere
}
when your part is created again you have to load your data from your saved data.
One place to save data is the MPart
persisted state - access this with:
Map<String, String> persistedState = part.getPersistedState();
You can save string values in this map.
So:
@Persist
void save(MPart part)
{
Map<String, String> persistedState = part.getPersistedState();
persistedState.put("key for my value", "my value");
}
and retrieve it with:
@PostConstruct
void createPart(MPart part)
{
Map<String, String> persistedState = part.getPersistedState();
String myValue = persistedState.get("key for my value");
}
Upvotes: 1
Reputation: 149
Greg, well I have understood how to use the Map type but I didn't catch how my Map variable becomes "persistent". My implementation as follows:
persistedState = part.getPersistedState();
System.out.println(persistedState.get("1"));
...
@Persist
public void save() {
dirty.setDirty(false);
persistedState.put("1", "test1");
}
Obviously doesn't work when I exit the app, I stil miss the last piece of the puzzle. Has it something to do with Preference Store/ writing a file with my stuff in it?
Upvotes: 0