SafeRunner.run(new SafeRunnable() {
public void run() {
// Get the input.
IEditorInput input = editor.getEditorInput();
IPersistableElement persistable = input.getPersistable();
if (persistable == null) {
return;
}
// Save editor.
IMemento editorMem = memento
.createChild(IWorkbenchConstants.TAG_EDITOR);
editorMem.putString(IWorkbenchConstants.TAG_TITLE, editorRef
.getTitle());
editorMem.putString(IWorkbenchConstants.TAG_NAME, editorRef
.getName());
editorMem.putString(IWorkbenchConstants.TAG_ID, editorRef
.getId());
editorMem.putString(IWorkbenchConstants.TAG_TOOLTIP, editorRef
.getTitleToolTip());
editorMem.putString(IWorkbenchConstants.TAG_PART_NAME,
editorRef.getPartName());
if (editor instanceof IWorkbenchPart3) {
Map properties = ((IWorkbenchPart3) editor)
.getPartProperties();
if (!properties.isEmpty()) {
IMemento propBag = editorMem
.createChild(IWorkbenchConstants.TAG_PROPERTIES);
Iterator i = properties.entrySet().iterator();
while (i.hasNext()) {
Map.Entry entry = (Map.Entry) i.next();
IMemento p = propBag.createChild(
IWorkbenchConstants.TAG_PROPERTY,
(String) entry.getKey());
p.putTextData((String) entry.getValue());
}
}
}
if (editorRef.isPinned()) {
editorMem.putString(IWorkbenchConstants.TAG_PINNED, "true"); //$NON-NLS-1$
}
EditorPane editorPane = (EditorPane) ((EditorSite) editor
.getEditorSite()).getPane();
editorMem.putString(IWorkbenchConstants.TAG_WORKBOOK,
editorPane.getWorkbook().getID());
if (editor == page.getActivePart()) {
editorMem.putString(IWorkbenchConstants.TAG_ACTIVE_PART,
"true"); //$NON-NLS-1$
}
if (editorPane == editorPane.getWorkbook().getSelection()) {
editorMem.putString(IWorkbenchConstants.TAG_FOCUS, "true"); //$NON-NLS-1$
}
if (input instanceof IPathEditorInput) {
IPath path = ((IPathEditorInput) input).getPath();
if (path != null) {
editorMem.putString(IWorkbenchConstants.TAG_PATH, path
.toString());
}
}
// Save input.
IMemento inputMem = editorMem
.createChild(IWorkbenchConstants.TAG_INPUT);
inputMem.putString(IWorkbenchConstants.TAG_FACTORY_ID,
persistable.getFactoryId());
persistable.saveState(inputMem);
// any editors that want to persist state
if (editor instanceof IPersistableEditor) {
IMemento editorState = editorMem
.createChild(IWorkbenchConstants.TAG_EDITOR_STATE);