Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "FAQ How and when do I save the workspace?"

 
(4 intermediate revisions by one other user not shown)
Line 1: Line 1:
If you're using the Eclipse IDE workbench, you don't. When it shuts down, the workbench will automatically save the workspace. The workspace will also perform its own periodic workspace saves, called ''snapshots'', every once in a while. Note that the most essential information in the workspace—the files and folders that the user is working with—are always
+
:''Please note that this state information is '''not''' related to the list of currently opened editors, views, and perspectives in the workbench windows.''
stored on disk immediately.  Saving the workspace simply involves storing
+
away metadata, such as markers, and its in-memory picture of the projects.
+
The workspace is designed so that if a user pulls the computer power
+
cord from the wall at any moment, the workspace will be able to restart in a
+
consistent state with minimal loss of information.
+
  
 +
If you're using the Eclipse IDE workbench, you don't. When it shuts down, the workbench will automatically save the workspace. The workspace will also perform its own periodic workspace saves, called ''snapshots'', every once in a while. Note that the most essential information in the workspace—such as newly created files and folders within Eclipse—are always stored on disk immediately. Saving the workspace simply involves storing away metadata, such as markers, and its in-memory picture of the projects. The workspace is designed so that if a user pulls the computer power cord from the wall at any moment, the resource tree will still be in a good state so that the workspace will be able to restart in a consistent state with minimal loss of information.
 +
 +
Nonetheless, it is possible for your plug-in to explicitly request a workspace save or snapshot.  If you are writing an RCP Application, you are responsible for minimally invoking save before shutdown.
  
Nonetheless, it is possible for your plug-in to explicitly request a
 
workspace save or snapshot.  If you are writing an RCP Application,
 
you are responsible for minimally invoking save before shutdown.
 
 
The following example saves the workspace:
 
The following example saves the workspace:
  
Line 25: Line 20:
 
};
 
};
 
new ProgressMonitorDialog(null).run(false, false, runnable);
 
new ProgressMonitorDialog(null).run(false, false, runnable);
if (!status.isOK())
+
if (!status.isOK()) {
 
   ErrorDialog.openError(...);
 
   ErrorDialog.openError(...);
 +
}
 
</source>
 
</source>
Note that the <tt>save</tt> method can indicate minor problems
 
by returning an <tt>IStatus</tt> object, or major problems by throwing
 
an exception.  You should check both of these results and react accordingly.
 
To request a workspace snapshot, the code is almost identical:
 
pass <tt>false</tt> as the first parameter to the <tt>save</tt>
 
method.
 
  
 +
Note that the <tt>save</tt> method can indicate minor problems by returning an <tt>IStatus</tt> object, or major problems by throwing an exception. You should check both of these results and react accordingly. To request a workspace snapshot, the code is almost identical: pass <tt>false</tt> as the first parameter to the <tt>save</tt> method.
  
 
== See Also: ==
 
== See Also: ==
Line 41: Line 32:
  
 
[[FAQ_How_can_I_be_notified_when_the_workspace_is_being_saved%3F]]
 
[[FAQ_How_can_I_be_notified_when_the_workspace_is_being_saved%3F]]
 +
 +
[https://bugs.eclipse.org/bugs/show_bug.cgi?id=337593 Bug 337593] has a plug-in attached which saves the workbench state after every change.
  
 
<hr><font size=-2>This FAQ was originally published in [http://www.eclipsefaq.org Official Eclipse 3.0 FAQs]. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the [http://www.eclipse.org/legal/epl-v10.html Eclipse Public License v1.0].</font>
 
<hr><font size=-2>This FAQ was originally published in [http://www.eclipsefaq.org Official Eclipse 3.0 FAQs]. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the [http://www.eclipse.org/legal/epl-v10.html Eclipse Public License v1.0].</font>

Latest revision as of 09:25, 2 September 2011

Please note that this state information is not related to the list of currently opened editors, views, and perspectives in the workbench windows.

If you're using the Eclipse IDE workbench, you don't. When it shuts down, the workbench will automatically save the workspace. The workspace will also perform its own periodic workspace saves, called snapshots, every once in a while. Note that the most essential information in the workspace&#151;such as newly created files and folders within Eclipse&#151;are always stored on disk immediately. Saving the workspace simply involves storing away metadata, such as markers, and its in-memory picture of the projects. The workspace is designed so that if a user pulls the computer power cord from the wall at any moment, the resource tree will still be in a good state so that the workspace will be able to restart in a consistent state with minimal loss of information.

Nonetheless, it is possible for your plug-in to explicitly request a workspace save or snapshot. If you are writing an RCP Application, you are responsible for minimally invoking save before shutdown.

The following example saves the workspace:

final MultiStatus status = new MultiStatus(...);
IRunnableWithProgress runnable = new IRunnableWithProgress() {
  public void run(IProgressMonitor monitor) {
    try {
      IWorkspace ws = ResourcesPlugin.getWorkspace();
      status.merge(ws.save(true, monitor));
    } catch (CoreException e) {
      status.merge(e.getStatus());
    }
  }
};
new ProgressMonitorDialog(null).run(false, false, runnable);
if (!status.isOK()) {
  ErrorDialog.openError(...);
}

Note that the save method can indicate minor problems by returning an IStatus object, or major problems by throwing an exception. You should check both of these results and react accordingly. To request a workspace snapshot, the code is almost identical: pass false as the first parameter to the save method.

See Also:

FAQ_How_do_I_make_the_workbench_shutdown?

FAQ_How_can_I_be_notified_when_the_workspace_is_being_saved?

Bug 337593 has a plug-in attached which saves the workbench state after every change.


This FAQ was originally published in Official Eclipse 3.0 FAQs. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the Eclipse Public License v1.0.

Back to the top