mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-28 18:53:20 +02:00
[241316] [efs] Cannot restore editors for RSE/EFS-backed resources
This commit is contained in:
parent
57a8af478f
commit
9eeca07175
2 changed files with 57 additions and 57 deletions
|
@ -1,15 +1,15 @@
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* Copyright (c) 2006, 2009 IBM Corporation and others. All rights reserved.
|
* Copyright (c) 2006, 2009 IBM Corporation and others. All rights reserved.
|
||||||
* This program and the accompanying materials are made available under the terms
|
* 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
|
* available at http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Initial Contributors:
|
* Initial Contributors:
|
||||||
* The following IBM employees contributed to the Remote System Explorer
|
* The following IBM employees contributed to the Remote System Explorer
|
||||||
* component that contains this file: David McKnight, Kushal Munir,
|
* component that contains this file: David McKnight, Kushal Munir,
|
||||||
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
|
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
|
||||||
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
|
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Kushal Munir (IBM) - moved to internal package
|
* Kushal Munir (IBM) - moved to internal package
|
||||||
* Martin Oberhuber (Wind River) - [181917] EFS Improvements: Avoid unclosed Streams,
|
* Martin Oberhuber (Wind River) - [181917] EFS Improvements: Avoid unclosed Streams,
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
* - Improve performance by RSEFileStore instance factory and caching IRemoteFile.
|
* - Improve performance by RSEFileStore instance factory and caching IRemoteFile.
|
||||||
* - Also remove unnecessary class RSEFileCache and obsolete branding files.
|
* - Also remove unnecessary class RSEFileCache and obsolete branding files.
|
||||||
* Martin Oberhuber (Wind River) - [188360] renamed from plugin org.eclipse.rse.eclipse.filesystem
|
* 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;
|
package org.eclipse.rse.internal.efs;
|
||||||
|
@ -40,10 +40,10 @@ public class Activator extends Plugin {
|
||||||
|
|
||||||
//The shared instance.
|
//The shared instance.
|
||||||
private static Activator plugin;
|
private static Activator plugin;
|
||||||
|
|
||||||
public static final String PLUGIN_ID = "org.eclipse.rse.efs"; //$NON-NLS-1$
|
public static final String PLUGIN_ID = "org.eclipse.rse.efs"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The constructor.
|
* The constructor.
|
||||||
*/
|
*/
|
||||||
|
@ -57,10 +57,10 @@ public class Activator extends Plugin {
|
||||||
final RemoteEditorManager mgr = RemoteEditorManager.getDefault();
|
final RemoteEditorManager mgr = RemoteEditorManager.getDefault();
|
||||||
ResourcesPlugin.getWorkspace().addSaveParticipant(this, mgr);
|
ResourcesPlugin.getWorkspace().addSaveParticipant(this, mgr);
|
||||||
ResourcesPlugin.getWorkspace().addResourceChangeListener(mgr, IResourceChangeEvent.POST_CHANGE);
|
ResourcesPlugin.getWorkspace().addResourceChangeListener(mgr, IResourceChangeEvent.POST_CHANGE);
|
||||||
|
|
||||||
Job job = new Job("Add Listener"){ //$NON-NLS-1$
|
Job job = new Job("Add Listener"){ //$NON-NLS-1$
|
||||||
protected IStatus run(IProgressMonitor monitor) {
|
protected IStatus run(IProgressMonitor monitor) {
|
||||||
|
|
||||||
while (!PlatformUI.isWorkbenchRunning()){
|
while (!PlatformUI.isWorkbenchRunning()){
|
||||||
try {
|
try {
|
||||||
//Checks in the loop are fast enough so we can poll often
|
//Checks in the loop are fast enough so we can poll often
|
||||||
|
@ -68,13 +68,13 @@ public class Activator extends Plugin {
|
||||||
}
|
}
|
||||||
catch (InterruptedException e){}
|
catch (InterruptedException e){}
|
||||||
}
|
}
|
||||||
IWorkbench wb = PlatformUI.getWorkbench();
|
IWorkbench wb = PlatformUI.getWorkbench();
|
||||||
wb.addWorkbenchListener(mgr);
|
wb.addWorkbenchListener(mgr);
|
||||||
return Status.OK_STATUS;
|
return Status.OK_STATUS;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
job.schedule();
|
job.schedule();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop(BundleContext context) throws Exception {
|
public void stop(BundleContext context) throws Exception {
|
||||||
|
@ -94,7 +94,7 @@ public class Activator extends Plugin {
|
||||||
public static Activator getDefault() {
|
public static Activator getDefault() {
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IStatus errorStatus(Throwable e) {
|
public static IStatus errorStatus(Throwable e) {
|
||||||
return new Status(IStatus.ERROR, PLUGIN_ID, e.getMessage(), e);
|
return new Status(IStatus.ERROR, PLUGIN_ID, e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* Copyright (c) 2009 IBM Corporation. All rights reserved.
|
* Copyright (c) 2009 IBM Corporation. All rights reserved.
|
||||||
* This program and the accompanying materials are made available under the terms
|
* 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
|
* available at http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Initial Contributors:
|
* Initial Contributors:
|
||||||
* The following IBM employees contributed to the Remote System Explorer
|
* The following IBM employees contributed to the Remote System Explorer
|
||||||
* component that contains this file: David McKnight, Mike Kucera.
|
* component that contains this file: David McKnight, Mike Kucera.
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Mike Kucera (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) - [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;
|
package org.eclipse.rse.internal.efs;
|
||||||
|
|
||||||
|
@ -53,20 +53,20 @@ import org.eclipse.ui.progress.UIJob;
|
||||||
|
|
||||||
public class RemoteEditorManager implements ISaveParticipant, IResourceChangeListener, IWorkbenchListener {
|
public class RemoteEditorManager implements ISaveParticipant, IResourceChangeListener, IWorkbenchListener {
|
||||||
public static final String PREFERENCE_EDITOR_LIST = "org.eclipse.rse.internal.efs.EditorSaver.preferenceEditorList"; //$NON-NLS-1$
|
public static final String PREFERENCE_EDITOR_LIST = "org.eclipse.rse.internal.efs.EditorSaver.preferenceEditorList"; //$NON-NLS-1$
|
||||||
|
|
||||||
private static RemoteEditorManager defaultInstance;
|
private static RemoteEditorManager defaultInstance;
|
||||||
|
|
||||||
private Map projectNameToUriMap = null;
|
private Map projectNameToUriMap = null;
|
||||||
|
|
||||||
private RemoteEditorManager() {}
|
private RemoteEditorManager() {}
|
||||||
|
|
||||||
public static synchronized RemoteEditorManager getDefault() {
|
public static synchronized RemoteEditorManager getDefault() {
|
||||||
if(defaultInstance == null)
|
if(defaultInstance == null)
|
||||||
defaultInstance = new RemoteEditorManager();
|
defaultInstance = new RemoteEditorManager();
|
||||||
return defaultInstance;
|
return defaultInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Restores remote editors when a remote project is opened.
|
* Restores remote editors when a remote project is opened.
|
||||||
*/
|
*/
|
||||||
|
@ -75,11 +75,11 @@ public class RemoteEditorManager implements ISaveParticipant, IResourceChangeLis
|
||||||
Map projectNameToUriMap = getProjectNameToUriMap(pref);
|
Map projectNameToUriMap = getProjectNameToUriMap(pref);
|
||||||
if(projectNameToUriMap.isEmpty())
|
if(projectNameToUriMap.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
IResourceDelta[] children = event.getDelta().getAffectedChildren();
|
IResourceDelta[] children = event.getDelta().getAffectedChildren();
|
||||||
for(int i = 0; i < children.length; i++) {
|
for(int i = 0; i < children.length; i++) {
|
||||||
IResourceDelta delta = children[i];
|
IResourceDelta delta = children[i];
|
||||||
|
|
||||||
// if a project has just been opened
|
// if a project has just been opened
|
||||||
if((delta.getFlags() & IResourceDelta.OPEN) != 0) {
|
if((delta.getFlags() & IResourceDelta.OPEN) != 0) {
|
||||||
IProject project = delta.getResource().getProject();
|
IProject project = delta.getResource().getProject();
|
||||||
|
@ -90,14 +90,14 @@ public class RemoteEditorManager implements ISaveParticipant, IResourceChangeLis
|
||||||
if(uris != null) {
|
if(uris != null) {
|
||||||
for(Iterator iter = uris.iterator(); iter.hasNext();) {
|
for(Iterator iter = uris.iterator(); iter.hasNext();) {
|
||||||
final String uriString = (String) iter.next();
|
final String uriString = (String) iter.next();
|
||||||
|
|
||||||
Job job = new UIJob("Restore Remote Editor") { //$NON-NLS-1$
|
Job job = new UIJob("Restore Remote Editor") { //$NON-NLS-1$
|
||||||
public IStatus runInUIThread(IProgressMonitor monitor) {
|
public IStatus runInUIThread(IProgressMonitor monitor) {
|
||||||
if(monitor.isCanceled())
|
if(monitor.isCanceled())
|
||||||
return Status.OK_STATUS;
|
return Status.OK_STATUS;
|
||||||
|
|
||||||
try {
|
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();
|
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
|
||||||
IFileStore fileStore = EFS.getStore(new URI(uriString));
|
IFileStore fileStore = EFS.getStore(new URI(uriString));
|
||||||
IDE.openEditorOnFileStore(page, fileStore);
|
IDE.openEditorOnFileStore(page, fileStore);
|
||||||
|
@ -112,15 +112,15 @@ public class RemoteEditorManager implements ISaveParticipant, IResourceChangeLis
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
job.schedule();
|
job.schedule();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the URIs of remote resources that are open in editors into the
|
* Saves the URIs of remote resources that are open in editors into the
|
||||||
* plugin's preference store.
|
* plugin's preference store.
|
||||||
|
@ -134,11 +134,11 @@ public class RemoteEditorManager implements ISaveParticipant, IResourceChangeLis
|
||||||
}
|
}
|
||||||
projectNameToUriMap = null;
|
projectNameToUriMap = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map getProjectNameToUriMap(String raw) {
|
private Map getProjectNameToUriMap(String raw) {
|
||||||
if(projectNameToUriMap == null) {
|
if(projectNameToUriMap == null) {
|
||||||
projectNameToUriMap = new HashMap();
|
projectNameToUriMap = new HashMap();
|
||||||
|
|
||||||
if(raw == null || raw.length() == 0)
|
if(raw == null || raw.length() == 0)
|
||||||
return projectNameToUriMap;
|
return projectNameToUriMap;
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ public class RemoteEditorManager implements ISaveParticipant, IResourceChangeLis
|
||||||
if(i < 0) break;
|
if(i < 0) break;
|
||||||
String uriString = raw.substring(index, i);
|
String uriString = raw.substring(index, i);
|
||||||
index = i + 1;
|
index = i + 1;
|
||||||
|
|
||||||
List uris = (List) projectNameToUriMap.get(projectName);
|
List uris = (List) projectNameToUriMap.get(projectName);
|
||||||
if(uris == null) {
|
if(uris == null) {
|
||||||
uris = new LinkedList();
|
uris = new LinkedList();
|
||||||
|
@ -163,11 +163,11 @@ public class RemoteEditorManager implements ISaveParticipant, IResourceChangeLis
|
||||||
}
|
}
|
||||||
return projectNameToUriMap;
|
return projectNameToUriMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private String generateEditorList() {
|
private String generateEditorList() {
|
||||||
final StringBuffer sb = new StringBuffer();
|
final StringBuffer sb = new StringBuffer();
|
||||||
|
|
||||||
forEachOpenRemoteEditor(new IEditorCallback() {
|
forEachOpenRemoteEditor(new IEditorCallback() {
|
||||||
public void apply(IWorkbenchPage page, IEditorPart editor, IFile file) {
|
public void apply(IWorkbenchPage page, IEditorPart editor, IFile file) {
|
||||||
IProject project = file.getProject();
|
IProject project = file.getProject();
|
||||||
|
@ -178,15 +178,15 @@ public class RemoteEditorManager implements ISaveParticipant, IResourceChangeLis
|
||||||
sb.append(' '); // not allowed in URIs
|
sb.append(' '); // not allowed in URIs
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static interface IEditorCallback {
|
private static interface IEditorCallback {
|
||||||
public void apply(IWorkbenchPage page, IEditorPart editor, IFile file);
|
public void apply(IWorkbenchPage page, IEditorPart editor, IFile file);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void forEachOpenRemoteEditor(IEditorCallback callback) {
|
private static void forEachOpenRemoteEditor(IEditorCallback callback) {
|
||||||
IWorkbench wb = PlatformUI.getWorkbench();
|
IWorkbench wb = PlatformUI.getWorkbench();
|
||||||
IWorkbenchWindow[] windows = wb.getWorkbenchWindows();
|
IWorkbenchWindow[] windows = wb.getWorkbenchWindows();
|
||||||
|
@ -198,7 +198,7 @@ public class RemoteEditorManager implements ISaveParticipant, IResourceChangeLis
|
||||||
IEditorReference[] activeReferences = page.getEditorReferences();
|
IEditorReference[] activeReferences = page.getEditorReferences();
|
||||||
for (int er = 0; er < activeReferences.length; er++){
|
for (int er = 0; er < activeReferences.length; er++){
|
||||||
IEditorReference editorReference = activeReferences[er];
|
IEditorReference editorReference = activeReferences[er];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
IEditorInput input = editorReference.getEditorInput();
|
IEditorInput input = editorReference.getEditorInput();
|
||||||
if (input instanceof FileEditorInput){
|
if (input instanceof FileEditorInput){
|
||||||
|
@ -206,7 +206,7 @@ public class RemoteEditorManager implements ISaveParticipant, IResourceChangeLis
|
||||||
URI uri = file.getLocationURI();
|
URI uri = file.getLocationURI();
|
||||||
if ("rse".equals(uri.getScheme())) { //$NON-NLS-1$
|
if ("rse".equals(uri.getScheme())) { //$NON-NLS-1$
|
||||||
IEditorPart editor = editorReference.getEditor(false);
|
IEditorPart editor = editorReference.getEditor(false);
|
||||||
callback.apply(page, editor, file);
|
callback.apply(page, editor, file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (PartInitException e){
|
} 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
|
* Close each editor that is open for any file that uses "rse" as it's uri scheme
|
||||||
* @return true if successful, false otherwise
|
* @return true if successful, false otherwise
|
||||||
|
@ -233,17 +233,17 @@ public class RemoteEditorManager implements ISaveParticipant, IResourceChangeLis
|
||||||
IEditorReference[] activeReferences = page.getEditorReferences();
|
IEditorReference[] activeReferences = page.getEditorReferences();
|
||||||
for (int er = 0; er < activeReferences.length; er++){
|
for (int er = 0; er < activeReferences.length; er++){
|
||||||
IEditorReference editorReference = activeReferences[er];
|
IEditorReference editorReference = activeReferences[er];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
IEditorInput input = editorReference.getEditorInput();
|
IEditorInput input = editorReference.getEditorInput();
|
||||||
if (input instanceof FileEditorInput){
|
if (input instanceof FileEditorInput){
|
||||||
IFile file = ((FileEditorInput)input).getFile();
|
IFile file = ((FileEditorInput)input).getFile();
|
||||||
URI uri = file.getLocationURI();
|
URI uri = file.getLocationURI();
|
||||||
if ("rse".equals(uri.getScheme())) { //$NON-NLS-1$
|
if ("rse".equals(uri.getScheme())) { //$NON-NLS-1$
|
||||||
IEditorPart editor = editorReference.getEditor(false);
|
IEditorPart editor = editorReference.getEditor(false);
|
||||||
|
|
||||||
// close the editor
|
// close the editor
|
||||||
result = page.closeEditor(editor, true);
|
result = page.closeEditor(editor, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (PartInitException e){
|
} catch (PartInitException e){
|
||||||
|
@ -255,12 +255,12 @@ public class RemoteEditorManager implements ISaveParticipant, IResourceChangeLis
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void saving(ISaveContext context) throws CoreException {
|
public void saving(ISaveContext context) throws CoreException {
|
||||||
saveRemoteEditors();
|
saveRemoteEditors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void doneSaving(ISaveContext context) {
|
public void doneSaving(ISaveContext context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,16 +269,16 @@ public class RemoteEditorManager implements ISaveParticipant, IResourceChangeLis
|
||||||
|
|
||||||
public void rollback(ISaveContext context) {
|
public void rollback(ISaveContext context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// for IWorkbenchListener
|
// for IWorkbenchListener
|
||||||
public void postShutdown(IWorkbench workbench) {
|
public void postShutdown(IWorkbench workbench) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// for IWorkbenchListener
|
// for IWorkbenchListener
|
||||||
public boolean preShutdown(IWorkbench workbench, boolean forced) {
|
public boolean preShutdown(IWorkbench workbench, boolean forced) {
|
||||||
saveRemoteEditors();
|
saveRemoteEditors();
|
||||||
return closeRemoteEditors();
|
return closeRemoteEditors();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue