| 
| How to correctly save the workspace.. [message #335867] | Wed, 06 May 2009 18:38  |  | 
| Eclipse User  |  |  |  |  | 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 #335886 is a reply to message #335873] | Thu, 07 May 2009 16:10  |  | 
| Eclipse User  |  |  |  |  | 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?
 |  |  |  | 
Powered by 
FUDForum. Page generated in 0.05253 seconds