|
|
|
Re: Save and Restore View Layout [message #524584 is a reply to message #524539] |
Thu, 01 April 2010 14:06 |
Uwe Kopf 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 |
|
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
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03443 seconds