Save and Restore View Layout [message #524539] |
Thu, 01 April 2010 06:44  |
Eclipse User |
|
|
|
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 #524584 is a reply to message #524539] |
Thu, 01 April 2010 10:06   |
Eclipse User |
|
|
|
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 10:45   |
Eclipse User |
|
|
|
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 #525710 is a reply to message #524596] |
Wed, 07 April 2010 10:25  |
Eclipse User |
|
|
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.05622 seconds