Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » persist or retain view state (persist or retain view state )
persist or retain view state [message #1263650] Tue, 04 March 2014 17:08 Go to next message
manu m is currently offline manu mFriend
Messages: 19
Registered: February 2014
Junior Member
I use savestate method to persist view when closed. Ie init (site,memento).the view is restored when I call user defined method from create part control. Which access the memento and restore the tree view. Now I close and reopen the view, again the view is restored to the state it was previously closed. I don't want this othis happen. Once the view is restored and then for subsequent close and open it should not restore from memento. The problem is whenever the init method is called the memento is always there and it always tries to restore from memento.the view must be restored only once.I don't want to use static variable or session variable to remember whether it has restored. Once view is restored on further close and reopen of view it should go for default implementation.
Re: persist or retain view state [message #1263840 is a reply to message #1263650] Tue, 04 March 2014 20:39 Go to previous messageGo to next message
Marco Lopes is currently offline Marco LopesFriend
Messages: 56
Registered: September 2010
Member
manu m wrote on Tue, 04 March 2014 12:08
I use savestate method to persist view when closed. Ie init (site,memento).the view is restored when I call user defined method from create part control. Which access the memento and restore the tree view. Now I close and reopen the view, again the view is restored to the state it was previously closed. I don't want this othis happen. Once the view is restored and then for subsequent close and open it should not restore from memento. The problem is whenever the init method is called the memento is always there and it always tries to restore from memento.the view must be restored only once.I don't want to use static variable or session variable to remember whether it has restored. Once view is restored on further close and reopen of view it should go for default implementation.


Strangely, i have the exact OPPOSITE behavior! I want to access MEMENTO every time the view is opened, but the memento comes NULL!!!

The only time i can restore a view with memento data is when the workbench launches, and the view init is called.

I would like to know how to get your behavior!

NOTE: using Eclipse 3.8
Re: persist or retain view state [message #1264435 is a reply to message #1263840] Wed, 05 March 2014 08:18 Go to previous messageGo to next message
Hussein MHANNA is currently offline Hussein MHANNAFriend
Messages: 45
Registered: February 2014
Location: LAVAL
Member
Hi Manu and Marco,

The saveState method is called only if your view is open when the workbench shuts down and will not be called when the view is closed by the user.

The IMemento instance can be null if the view state was not saved from a previous session.

I recommend you tu use IDialogSettings to save/restore data of views between sessions.

The advantage of IDialogSettings over the view save/init mechanism is that you can control whenever you want to save/ restore persisted data of your view.

For more information see here

Kind Regards,

Hussein


ALL4TEC
Re: persist or retain view state [message #1265228 is a reply to message #1264435] Wed, 05 March 2014 21:03 Go to previous messageGo to next message
Marco Lopes is currently offline Marco LopesFriend
Messages: 56
Registered: September 2010
Member
Hussein MHANNA wrote on Wed, 05 March 2014 03:18
Hi Manu and Marco,

The saveState method is called only if your view is open when the workbench shuts down and will not be called when the view is closed by the user.

The IMemento instance can be null if the view state was not saved from a previous session.

I recommend you tu use IDialogSettings to save/restore data of views between sessions.

The advantage of IDialogSettings over the view save/init mechanism is that you can control whenever you want to save/ restore persisted data of your view.

For more information see here

Kind Regards,

Hussein


Thanks for your reply! I will look into it.

By the way, the correct link is: https://wiki.eclipse.org/FAQ_How_does_a_view_persist_its_state_between_sessions%3F
(had to google it)

IDialogSettings example is here: https://wiki.eclipse.org/FAQ_How_do_I_save_settings_for_a_dialog_or_a_wizard%3F

I still don't understand how manu is getting that behavior, has is not expected.

[Updated on: Wed, 05 March 2014 21:11]

Report message to a moderator

Re: persist or retain view state [message #1270105 is a reply to message #1265228] Wed, 12 March 2014 13:56 Go to previous messageGo to next message
manu m is currently offline manu mFriend
Messages: 19
Registered: February 2014
Junior Member
Hi Marco,

The life cycle of view begins this way
1.init (site,memento)
2.create part control


In init method I save memento to a variable
In create part control I check if memento is not null then i call user defined method to restore certain things

Now if view is closed and re opened then again same life cycle is followed

In init method memento gets initialized and in create part control because memento is not null it tries to restore things

I am using Kepler eclipse 4.3 version

May I know how are you doing it.if once restored later it should not restore or memento has to be null
Re: persist or retain view state [message #1270107 is a reply to message #1270105] Wed, 12 March 2014 13:58 Go to previous messageGo to next message
manu m is currently offline manu mFriend
Messages: 19
Registered: February 2014
Junior Member
manu m wrote on Wed, 12 March 2014 09:56
Hi Marco,

The life cycle of view begins this way
1.init (site,memento)
2.create part control


In init method I save memento to a variable
In create part control I check if memento is not null then i call user defined method to restore certain things

Now if view is closed and re opened then again same life cycle is followed

In init method memento gets initialized and in create part control because memento is not null it tries to restore things

I am using Kepler eclipse 4.3 version

May I know how are you doing it.if once restored later it should not restore or memento has to be null

Re: persist or retain view state [message #1270331 is a reply to message #1270105] Wed, 12 March 2014 21:55 Go to previous messageGo to next message
Marco Lopes is currently offline Marco LopesFriend
Messages: 56
Registered: September 2010
Member
manu m wrote on Wed, 12 March 2014 09:56
Hi Marco,

The life cycle of view begins this way
1.init (site,memento)
2.create part control


In init method I save memento to a variable
In create part control I check if memento is not null then i call user defined method to restore certain things

Now if view is closed and re opened then again same life cycle is followed

In init method memento gets initialized and in create part control because memento is not null it tries to restore things

I am using Kepler eclipse 4.3 version

May I know how are you doing it.if once restored later it should not restore or memento has to be null


Well, there are differences between eclipse 3.x and 4.x! Under 3.x the MEMENTO is passed to the Init method only when the workbench is initialized and views are RESTORED (if any!).

When a view is closed and opened, memento is lost and passed as null.
Re: persist or retain view state [message #1270397 is a reply to message #1270331] Thu, 13 March 2014 00:15 Go to previous messageGo to next message
manu m is currently offline manu mFriend
Messages: 19
Registered: February 2014
Junior Member
How could I solve my problem then??
I don't want it to restore when view is closed and reopened
Re: persist or retain view state [message #1270398 is a reply to message #1270397] Thu, 13 March 2014 00:15 Go to previous messageGo to next message
manu m is currently offline manu mFriend
Messages: 19
Registered: February 2014
Junior Member
manu m wrote on Wed, 12 March 2014 20:15
How could I solve my problem then??
I don't want it to restore when view is closed and reopened

Re: persist or retain view state [message #1270405 is a reply to message #1270397] Thu, 13 March 2014 00:25 Go to previous messageGo to next message
Marco Lopes is currently offline Marco LopesFriend
Messages: 56
Registered: September 2010
Member
manu m wrote on Wed, 12 March 2014 20:15
How could I solve my problem then??
I don't want it to restore when view is closed and reopened


That is the least of your problems!

A view is not really CLOSED by the workbench... it's HIDED, so, you can maintain an object initialized indicating that the view is already initialized and bypass the RESTORE code.
Re: persist or retain view state [message #1270408 is a reply to message #1270405] Thu, 13 March 2014 00:32 Go to previous messageGo to next message
manu m is currently offline manu mFriend
Messages: 19
Registered: February 2014
Junior Member
Thanks for the quick reply
But when the view is closed I have dispose method called.can you please help me by giving sample raw code on
How I could achieve this.

Because when my view is re opened I create all the widget in view in create part control
Re: persist or retain view state [message #1270409 is a reply to message #1270408] Thu, 13 March 2014 00:32 Go to previous messageGo to next message
manu m is currently offline manu mFriend
Messages: 19
Registered: February 2014
Junior Member
manu m wrote on Wed, 12 March 2014 20:32
Thanks for the quick reply
But when the view is closed I have dispose method called.can you please help me by giving sample raw code on
How I could achieve this.

Because when my view is re opened I create all the widget in view in create part control

Re: persist or retain view state [message #1270425 is a reply to message #1270408] Thu, 13 March 2014 01:04 Go to previous message
Marco Lopes is currently offline Marco LopesFriend
Messages: 56
Registered: September 2010
Member
manu m wrote on Wed, 12 March 2014 20:32
Thanks for the quick reply
But when the view is closed I have dispose method called.can you please help me by giving sample raw code on
How I could achieve this.

Because when my view is re opened I create all the widget in view in create part control


Well, i wrote a GLOBAL OpenView class, that manages the view PARAMETERS that are passed to the view.

in this class, i have many parameters that are not disposed between closing (hiding) and opening (showing) the view!

//finds view reference (it will be null if view is not opened)
IViewReference viewReference=PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findViewReference(parameters.getId(), parameters.getSecondaryId());

//shows the view
IViewPart view=PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(parameters.getId(), parameters.getSecondaryId(), IWorkbenchPage.VIEW_ACTIVATE);

//view was not opened
if(viewReference==null){

	//passes existing parameters
	if (view instanceof ICustomView){
		ICustomView customView=(ICustomView)view;
		customView.initialize(parameters);
		customView.setIcon();
		customView.setTitle();
		customView.setFocus();
	}else{
		view.setFocus();
	}

}

Previous Topic:Duplication occured
Next Topic:Eclipse Modeling Juno 3.8.2 download link
Goto Forum:
  


Current Time: Sat Dec 20 12:59:50 GMT 2014

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

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