1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-25 01:45:33 +02:00

[241316] [efs] Cannot restore editors for RSE/EFS-backed resources

This commit is contained in:
Martin Oberhuber 2009-05-13 21:05:04 +00:00
parent 57a8af478f
commit 9eeca07175
2 changed files with 57 additions and 57 deletions

View file

@ -1,15 +1,15 @@
/********************************************************************************
* Copyright (c) 2006, 2009 IBM Corporation and others. All rights reserved.
* This program and the accompanying materials are made available under the terms
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
*
*
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
*
*
* Contributors:
* Kushal Munir (IBM) - moved to internal package
* Martin Oberhuber (Wind River) - [181917] EFS Improvements: Avoid unclosed Streams,
@ -17,7 +17,7 @@
* - Improve performance by RSEFileStore instance factory and caching IRemoteFile.
* - Also remove unnecessary class RSEFileCache and obsolete branding files.
* Martin Oberhuber (Wind River) - [188360] renamed from plugin org.eclipse.rse.eclipse.filesystem
* David McKnight (IBM) -[241315] [efs] Cannot restore editors for RSE/EFS-backed resources
* David McKnight (IBM) - [241316] [efs] Cannot restore editors for RSE/EFS-backed resources
********************************************************************************/
package org.eclipse.rse.internal.efs;
@ -40,10 +40,10 @@ public class Activator extends Plugin {
//The shared instance.
private static Activator plugin;
public static final String PLUGIN_ID = "org.eclipse.rse.efs"; //$NON-NLS-1$
/**
* The constructor.
*/
@ -57,10 +57,10 @@ public class Activator extends Plugin {
final RemoteEditorManager mgr = RemoteEditorManager.getDefault();
ResourcesPlugin.getWorkspace().addSaveParticipant(this, mgr);
ResourcesPlugin.getWorkspace().addResourceChangeListener(mgr, IResourceChangeEvent.POST_CHANGE);
Job job = new Job("Add Listener"){ //$NON-NLS-1$
protected IStatus run(IProgressMonitor monitor) {
while (!PlatformUI.isWorkbenchRunning()){
try {
//Checks in the loop are fast enough so we can poll often
@ -68,13 +68,13 @@ public class Activator extends Plugin {
}
catch (InterruptedException e){}
}
IWorkbench wb = PlatformUI.getWorkbench();
wb.addWorkbenchListener(mgr);
IWorkbench wb = PlatformUI.getWorkbench();
wb.addWorkbenchListener(mgr);
return Status.OK_STATUS;
}
}
};
job.schedule();
}
public void stop(BundleContext context) throws Exception {
@ -94,7 +94,7 @@ public class Activator extends Plugin {
public static Activator getDefault() {
return plugin;
}
public static IStatus errorStatus(Throwable e) {
return new Status(IStatus.ERROR, PLUGIN_ID, e.getMessage(), e);
}

View file

@ -1,16 +1,16 @@
/********************************************************************************
* Copyright (c) 2009 IBM Corporation. All rights reserved.
* This program and the accompanying materials are made available under the terms
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
*
*
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight, Mike Kucera.
*
*
* Contributors:
* Mike Kucera (IBM) - [241315] [efs] Cannot restore editors for RSE/EFS-backed resources
* David McKnight (IBM) - [241315] [efs] Cannot restore editors for RSE/EFS-backed resources
* Mike Kucera (IBM) - [241316] [efs] Cannot restore editors for RSE/EFS-backed resources
* David McKnight (IBM) - [241316] [efs] Cannot restore editors for RSE/EFS-backed resources
********************************************************************************/
package org.eclipse.rse.internal.efs;
@ -53,20 +53,20 @@ import org.eclipse.ui.progress.UIJob;
public class RemoteEditorManager implements ISaveParticipant, IResourceChangeListener, IWorkbenchListener {
public static final String PREFERENCE_EDITOR_LIST = "org.eclipse.rse.internal.efs.EditorSaver.preferenceEditorList"; //$NON-NLS-1$
private static RemoteEditorManager defaultInstance;
private Map projectNameToUriMap = null;
private RemoteEditorManager() {}
public static synchronized RemoteEditorManager getDefault() {
if(defaultInstance == null)
defaultInstance = new RemoteEditorManager();
return defaultInstance;
}
/**
* Restores remote editors when a remote project is opened.
*/
@ -75,11 +75,11 @@ public class RemoteEditorManager implements ISaveParticipant, IResourceChangeLis
Map projectNameToUriMap = getProjectNameToUriMap(pref);
if(projectNameToUriMap.isEmpty())
return;
IResourceDelta[] children = event.getDelta().getAffectedChildren();
for(int i = 0; i < children.length; i++) {
IResourceDelta delta = children[i];
// if a project has just been opened
if((delta.getFlags() & IResourceDelta.OPEN) != 0) {
IProject project = delta.getResource().getProject();
@ -90,14 +90,14 @@ public class RemoteEditorManager implements ISaveParticipant, IResourceChangeLis
if(uris != null) {
for(Iterator iter = uris.iterator(); iter.hasNext();) {
final String uriString = (String) iter.next();
Job job = new UIJob("Restore Remote Editor") { //$NON-NLS-1$
public IStatus runInUIThread(IProgressMonitor monitor) {
if(monitor.isCanceled())
return Status.OK_STATUS;
try {
// got this code from http://wiki.eclipse.org/FAQ_How_do_I_open_an_editor_programmatically%3F
// got this code from http://wiki.eclipse.org/FAQ_How_do_I_open_an_editor_programmatically%3F
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IFileStore fileStore = EFS.getStore(new URI(uriString));
IDE.openEditorOnFileStore(page, fileStore);
@ -112,15 +112,15 @@ public class RemoteEditorManager implements ISaveParticipant, IResourceChangeLis
}
};
job.schedule();
}
}
}
}
}
}
/**
* Saves the URIs of remote resources that are open in editors into the
* plugin's preference store.
@ -134,11 +134,11 @@ public class RemoteEditorManager implements ISaveParticipant, IResourceChangeLis
}
projectNameToUriMap = null;
}
private Map getProjectNameToUriMap(String raw) {
if(projectNameToUriMap == null) {
projectNameToUriMap = new HashMap();
if(raw == null || raw.length() == 0)
return projectNameToUriMap;
@ -152,7 +152,7 @@ public class RemoteEditorManager implements ISaveParticipant, IResourceChangeLis
if(i < 0) break;
String uriString = raw.substring(index, i);
index = i + 1;
List uris = (List) projectNameToUriMap.get(projectName);
if(uris == null) {
uris = new LinkedList();
@ -163,11 +163,11 @@ public class RemoteEditorManager implements ISaveParticipant, IResourceChangeLis
}
return projectNameToUriMap;
}
private String generateEditorList() {
final StringBuffer sb = new StringBuffer();
forEachOpenRemoteEditor(new IEditorCallback() {
public void apply(IWorkbenchPage page, IEditorPart editor, IFile file) {
IProject project = file.getProject();
@ -178,15 +178,15 @@ public class RemoteEditorManager implements ISaveParticipant, IResourceChangeLis
sb.append(' '); // not allowed in URIs
}
});
return sb.toString();
}
private static interface IEditorCallback {
public void apply(IWorkbenchPage page, IEditorPart editor, IFile file);
}
private static void forEachOpenRemoteEditor(IEditorCallback callback) {
IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow[] windows = wb.getWorkbenchWindows();
@ -198,7 +198,7 @@ public class RemoteEditorManager implements ISaveParticipant, IResourceChangeLis
IEditorReference[] activeReferences = page.getEditorReferences();
for (int er = 0; er < activeReferences.length; er++){
IEditorReference editorReference = activeReferences[er];
try {
IEditorInput input = editorReference.getEditorInput();
if (input instanceof FileEditorInput){
@ -206,7 +206,7 @@ public class RemoteEditorManager implements ISaveParticipant, IResourceChangeLis
URI uri = file.getLocationURI();
if ("rse".equals(uri.getScheme())) { //$NON-NLS-1$
IEditorPart editor = editorReference.getEditor(false);
callback.apply(page, editor, file);
callback.apply(page, editor, file);
}
}
} catch (PartInitException e){
@ -216,7 +216,7 @@ public class RemoteEditorManager implements ISaveParticipant, IResourceChangeLis
}
}
}
/**
* Close each editor that is open for any file that uses "rse" as it's uri scheme
* @return true if successful, false otherwise
@ -233,17 +233,17 @@ public class RemoteEditorManager implements ISaveParticipant, IResourceChangeLis
IEditorReference[] activeReferences = page.getEditorReferences();
for (int er = 0; er < activeReferences.length; er++){
IEditorReference editorReference = activeReferences[er];
try {
IEditorInput input = editorReference.getEditorInput();
if (input instanceof FileEditorInput){
IFile file = ((FileEditorInput)input).getFile();
URI uri = file.getLocationURI();
if ("rse".equals(uri.getScheme())) { //$NON-NLS-1$
IEditorPart editor = editorReference.getEditor(false);
IEditorPart editor = editorReference.getEditor(false);
// close the editor
result = page.closeEditor(editor, true);
result = page.closeEditor(editor, true);
}
}
} catch (PartInitException e){
@ -255,12 +255,12 @@ public class RemoteEditorManager implements ISaveParticipant, IResourceChangeLis
return result;
}
public void saving(ISaveContext context) throws CoreException {
saveRemoteEditors();
}
public void doneSaving(ISaveContext context) {
}
@ -269,16 +269,16 @@ public class RemoteEditorManager implements ISaveParticipant, IResourceChangeLis
public void rollback(ISaveContext context) {
}
// for IWorkbenchListener
public void postShutdown(IWorkbench workbench) {
}
// for IWorkbenchListener
public boolean preShutdown(IWorkbench workbench, boolean forced) {
public boolean preShutdown(IWorkbench workbench, boolean forced) {
saveRemoteEditors();
return closeRemoteEditors();
}
}