Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » How to correctly save the workspace..
How to correctly save the workspace.. [message #335867] Wed, 06 May 2009 22:38 Go to next message
Dan O'Connor is currently offline Dan O'ConnorFriend
Messages: 2
Registered: July 2009
Junior Member
Hello..

I am working on an RCP project where by we have created our own
WorkbenchWindowAdvisor.

During startup the following gets printed to our log:

The workspace exited with unsaved changes in the previous session;
refreshing workspace to recover changes.

It seems no matter what I do during workbench shutdown I receive this
error during subsequent start-up operations?

My shutdown code is as follows:


@Override
public void postWindowClose() {
super.postWindowClose();
saveWorkspaceInfo();
}

private void saveWorkspaceInfo(){


final MultiStatus status = new MultiStatus(
Activator.PLUGIN_ID, 1,
"Error encountered saving workspace information", null);

WorkspaceModifyOperation operation = new
WorkspaceModifyOperation() {

@Override
protected void execute(IProgressMonitor monitor)
throws CoreException, InvocationTargetException,
InterruptedException {


IWorkspaceRoot root =
ResourcesPlugin.getWorkspace().getRoot();
IProject[] projects = root.getProjects();
if(projects != null && projects.length > 0){
monitor.beginTask(StringUtil.format("Exiting {0}",
ProductUtil.getProductShortName()), (projects.length * 5));
for(int i = 0; i < projects.length; i++){
monitor.setTaskName(StringUtil.format("Exiting {0}
- Saving application data for {1}", ProductUtil.getProductShortName(),
projects[i].getName()));
if(projects[i].isOpen()){
try {
projects[i].close(monitor);

} catch (CoreException ce) {
//log
}
}
monitor.worked(5);
}
try {

status.merge(ResourcesPlugin.getWorkspace().save(true,
SubMonitor.convert(monitor)));

} catch (CoreException e) {
status.merge(e.getStatus());
}
monitor.done();
}

}

};
try {
PlatformUI.getWorkbench().getProgressService().run(true,
false, operation);
} catch (InvocationTargetException e) {
status.merge(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 1,
"An internal error occurred while saving the workspace
state",e.getTargetException()));

} catch (InterruptedException e) {
//Should not happen as the operation is not cancellable - but
just in case.
status.merge(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 1,
"An internal error occurred while saving the workspace
state. The operation was interrupted by the user.", e));
}
if (!status.isOK()) {
ErrorDialog.openError(null, "An error was encountered when
saving the workspace state", null, status,
IStatus.ERROR | IStatus.WARNING);
Activator.getDefault().getLog().log(status); //Log to Eclipse
log also!

}
}


I added a breakpoint at:
org.eclipse.core.internal.resources.Workspace.beginOperation (boolean) and
I enable my breakpoint after the above code has executed.
The breakpoint is hit another 3 or 4 times after the above code has
executed suggesting that other workspace jobs are executing. It seems that
the following are the jobs that are not complete by the time the
workspace.save occurs:

org.eclipse.core.internal.resources.Workspace.close(IProgres sMonitor)

org.eclipse.core.internal.resources.ContentDescriptionManage r.getDescriptionFor(File,
ResourceInfo)

a long with one or two others.

Is there a way to save and close the workspace gracefully? Is there a
point in the lifecycle where I can latch in and perform the save
successfully?

Any help here would be greatly appreciated. This has me stumped!

Thanks,
-Dan
Re: How to correctly save the workspace.. [message #335873 is a reply to message #335867] Thu, 07 May 2009 15:55 Go to previous messageGo to next message
Alexander Karnstedt is currently offline Alexander KarnstedtFriend
Messages: 68
Registered: July 2009
Member
Dan O'Connor schrieb am 07.05.2009 00:38:
> Hello..
>
> I am working on an RCP project where by we have created our own
> WorkbenchWindowAdvisor.
>
> During startup the following gets printed to our log:
>
> The workspace exited with unsaved changes in the previous session;
> refreshing workspace to recover changes.
>
> It seems no matter what I do during workbench shutdown I receive this
> error during subsequent start-up operations?
> My shutdown code is as follows:
>
>

For my RCP application I just copied
IDEWorkbenchAdvisor#disconnectFromWorkspace() - which I call from
#postShutdown() ... works well for me.

Alex
Re: How to correctly save the workspace.. [message #335886 is a reply to message #335873] Thu, 07 May 2009 20:10 Go to previous message
Dan O'Connor is currently offline Dan O'ConnorFriend
Messages: 2
Registered: July 2009
Junior Member
Thanks... but unfortunately we do not extend IDEWorkbenchAdvisor so
calling disconnect... is not an option.
I actually copied the code from disconnect... into my own shutdown method,
but still have this issue - is there any other step that I am missing?
Previous Topic:Core expression, adapt to inner class
Next Topic:Single Checkable CheckboxTableViewer
Goto Forum:
  


Current Time: Fri Mar 29 08:48:13 GMT 2024

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

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

Back to the top