Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Save and Restore View Layout
Save and Restore View Layout [message #524539] Thu, 01 April 2010 10:44 Go to next message
Uwe Kopf is currently offline Uwe KopfFriend
Messages: 3
Registered: April 2010
Junior Member
I have following problem.

I have created a TableView in a RCP application and want to save and restore the layout of the table if the view is closed and opend again.
This works fine for closing the whole workbench.
Here I used IMemento in
public void init(IViewSite site, IMemento memento) {...}
and in
public void saveState(IMemento memento) { ... }

But it is not working for closing and opening only the view itself.
The workbench does not call saveState if the view is closed.

If I compare to the standard eclipse "problems view" or "Error Log" here it works. But I can not find out how.

Can please somebody show me how this works?

With best regards Uwe
Re: Save and Restore View Layout [message #524562 is a reply to message #524539] Thu, 01 April 2010 12:06 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
On 01.04.2010 12:44, Uwe Kopf wrote:
> I have following problem.
>
> I have created a TableView in a RCP application and want to save and
> restore the layout of the table if the view is closed and opend again.
> This works fine for closing the whole workbench.
> Here I used IMemento in
> public void init(IViewSite site, IMemento memento) {...}
> and in
> public void saveState(IMemento memento) { ... }
>
> But it is not working for closing and opening only the view itself.
> The workbench does not call saveState if the view is closed.
>
> If I compare to the standard eclipse "problems view" or "Error Log" here
> it works. But I can not find out how.
>
> Can please somebody show me how this works?

I suggest that you register as IPartListener(2) during the init call
and observe the partClosed event method where you perform your
persistency, if the correct view becomes closed. It is really
astonishing, that a view has no own member function that allows a
direct overriding to reach the same effect, but so it is...

HTH & Greetings from Bremen,

Daniel Krügler
Re: Save and Restore View Layout [message #524569 is a reply to message #524539] Thu, 01 April 2010 13:02 Go to previous messageGo to next message
Ralf Ebert is currently offline Ralf EbertFriend
Messages: 168
Registered: July 2009
Senior Member
Hi Uwe,

> The workbench does not call saveState if the view is closed.

see https://bugs.eclipse.org/bugs/show_bug.cgi?id=307319#c1 . You can build a workaround
by saving the state using static variables in the view class or by listening to the close
events yourself, but it's all a bit messy.

Greetings,

Ralf


--
http://www.ralfebert.de/blog/
http://twitter.com/ralfebert/
Re: Save and Restore View Layout [message #524584 is a reply to message #524539] Thu, 01 April 2010 14:06 Go to previous messageGo to next message
Uwe Kopf is currently offline Uwe KopfFriend
Messages: 3
Registered: April 2010
Junior Member
Thanks Daniel, Ralf
for the fast reply.

>I suggest that you register as IPartListener(2) during the init call
>and observe the partClosed event method where you perform your
>persistency, if the correct view becomes closed. It is really
>astonishing, that a view has no own member function that allows a
>direct overriding to reach the same effect, but so it is...

I tried this, but it does not work in my use case.
I want to store the width of the columns in my table view in

partClosed(IWorkbenchPartReference partRef) {
....
for( int i = 0; i < viewer.getTable().getColumnCount(); i++) {
memento.putInteger("columnSize"+i, viewer.getTable().getColumn(i).getWidth());
}
}
But if the wokbench calls partClosed the widgets are allready disposed and I get an excetion.

So I tried to implement my view as ISaveablePart and Listener and to register it to the resize and move events of the columns.

column.addListener(SWT.Resize, this);
column.addListener(SWT.Move, this);

// Methods for ISaveablePart
@Override
public void doSave(IProgressMonitor monitor) {
....
memento.putInteger("columnCount", viewer.getTable().getColumnCount());
for( int i = 0; i < viewer.getTable().getColumnCount(); i++) {
memento.putInteger("columnSize"+i, viewer.getTable().getColumn(i).getWidth());
}
}

@Override
public boolean isDirty() {
// TODO Auto-generated method stub
return isDirty;
}

@Override
public boolean isSaveOnCloseNeeded() {
return true;
}

// Method for Listener
@Override
public void handleEvent(Event event) {
if( event.type == SWT.Resize || event.type == SWT.Move ) {
isDirty = true;
}

}

I think this is not the best solution but it works.
I wondering how it works in the Eclipse standard views "problems view" or "Error Log view".

Greetings Uwe
Re: Save and Restore View Layout [message #524596 is a reply to message #524584] Thu, 01 April 2010 14:45 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

There's 2 kinds of state involved in views, and depending one what you
are doing you might have to separate them.

1) your view's state ... its model, some field values, or something like
"I'm displaying information about ClassXA"

Over a session (shutdown and re-open) saveState(IMemento)/init(site,
IMemento) is called. For the general "close"/"open" case you can use
XMLMemento to save/restore the same state ... generally saving it to a
file in your plugin state location and then use the same code path in
your view.

2) your view's presentation: Columns are in the order (A, C, X), widths
are (100, 100, 320), etc. If you subclass AbstractUIPlugin we provide
org.eclipse.ui.plugin.AbstractUIPlugin.getDialogSettings() These can be
requested from your plugin and your plugin can request they are saved at
any time. They will also be saved for you when your plugin is stopped.

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Save and Restore View Layout [message #524610 is a reply to message #524539] Thu, 01 April 2010 15:16 Go to previous messageGo to next message
Andreas Schmid is currently offline Andreas SchmidFriend
Messages: 17
Registered: July 2009
Junior Member
try to insert following code to your ApplicationWorkbenchAdvisor

@Override
public void initialize(IWorkbenchConfigurer configurer) {
...
super.initialize(configurer);
configurer.setSaveAndRestore(true);
...
}

HTH

Andreas


Am 01.04.2010 12:44, schrieb Uwe Kopf:
> I have following problem.
>
> I have created a TableView in a RCP application and want to save and
> restore the layout of the table if the view is closed and opend again.
> This works fine for closing the whole workbench.
> Here I used IMemento in
> public void init(IViewSite site, IMemento memento) {...}
> and in
> public void saveState(IMemento memento) { ... }
>
> But it is not working for closing and opening only the view itself.
> The workbench does not call saveState if the view is closed.
>
> If I compare to the standard eclipse "problems view" or "Error Log" here
> it works. But I can not find out how.
>
> Can please somebody show me how this works?
>
> With best regards Uwe
Re: Save and Restore View Layout [message #525710 is a reply to message #524596] Wed, 07 April 2010 14:25 Go to previous message
Uwe Kopf is currently offline Uwe KopfFriend
Messages: 3
Registered: April 2010
Junior Member
Hello,

thank you this may help.

> 2) your view's presentation: Columns are in the order (A, C, X), widths
> are (100, 100, 320), etc. If you subclass AbstractUIPlugin we provide
> org.eclipse.ui.plugin.AbstractUIPlugin.getDialogSettings() These can be
> requested from your plugin and your plugin can request they are saved at
> any time. They will also be saved for you when your plugin is stopped.

I am writing a RCP application and my "Activator" class is a subclass of AbstractUIPlugin.
So I think I can use this feature.
As I have understood until now, I can use saveDialogSettings(); getDialogSettings()
to save and restore the layout settings of my tableView.
But there is no trigger for me if the view is closed before displosing the widgets.
And it is not done automaticaly if the view is closed.
I have to handle this in my own code.
Right?
So I have to listen for move and resize events of the table and to store the settings
after each event.
Does somebody know a code example for correct usage of saveDialogSettings(); getDialogSettings()?

With best regards
Uwe.
Previous Topic:changes to plugin.xml requires a clean start
Next Topic:Get the current active wizard page
Goto Forum:
  


Current Time: Thu Apr 25 00:37:03 GMT 2024

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

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

Back to the top