diff --git a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/files/ui/resources/SystemEditableRemoteFile.java b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/files/ui/resources/SystemEditableRemoteFile.java index c5eb03fa59d..e7a8cf45805 100644 --- a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/files/ui/resources/SystemEditableRemoteFile.java +++ b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/files/ui/resources/SystemEditableRemoteFile.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2012 IBM Corporation and others. + * Copyright (c) 2002, 2013 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 available at @@ -49,6 +49,7 @@ * David McKnight (IBM) - [385420] double-click to open System editor from Remote Systems view not working * David McKnight (IBM) - [385416] NPE during shutdown with remote editor open * David McKnight (IBM) - [390609] Cached file opened twice in case of eclipse linked resource.. + * Xuan Chen (IBM) - [399101] RSE edit actions on local files that map to actually workspace resources should not use temp files *******************************************************************************/ package org.eclipse.rse.files.ui.resources; @@ -1009,6 +1010,16 @@ public class SystemEditableRemoteFile implements ISystemEditableRemoteObject, IP */ private String getDownloadPath() { + //If this remote file is actually local, and it is part of a project in this workspace, just return the absolute path of the remote file. + IFile file = null; + if (remoteFile.getHost().getSystemType().isLocal()) + { + String absolutePath = remoteFile.getAbsolutePath(); + file = getProjectFileForLocation(absolutePath); + } + if (file != null) { + return remotePath; + } IPath path = new Path(root); @@ -2174,4 +2185,11 @@ public class SystemEditableRemoteFile implements ISystemEditableRemoteObject, IP _editorDescriptor = descriptor; } + private static IFile getProjectFileForLocation(String absolutePath) + { + IPath workspacePath = new Path(absolutePath); + IFile file = SystemBasePlugin.getWorkspaceRoot().getFileForLocation(workspacePath); + return file; + } + } diff --git a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SystemEditFilesAction.java b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SystemEditFilesAction.java index c988382e988..124cfb5b60d 100644 --- a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SystemEditFilesAction.java +++ b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SystemEditFilesAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2010 IBM Corporation and others. + * Copyright (c) 2002, 2013 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 available at @@ -19,6 +19,7 @@ * David McKnight (IBM) - [276103] Files with names in different cases are not handled properly * David McKnight (IBM) - [309813] RSE permits opening of file after access removed * David McKnight (IBM) - [312362] Editing Unix file after it changes on host edits old data + * Xuan Chen (IBM) - [399101] RSE edit actions on local files that map to actually workspace resources should not use temp files *******************************************************************************/ package org.eclipse.rse.internal.files.ui.actions; @@ -26,6 +27,8 @@ package org.eclipse.rse.internal.files.ui.actions; import java.util.Iterator; import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.rse.files.ui.resources.SystemEditableRemoteFile; @@ -35,6 +38,7 @@ import org.eclipse.rse.internal.files.ui.view.DownloadAndOpenJob; import org.eclipse.rse.subsystems.files.core.SystemIFileProperties; import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem; +import org.eclipse.rse.ui.SystemBasePlugin; import org.eclipse.rse.ui.actions.SystemBaseAction; import org.eclipse.rse.ui.view.ISystemEditableRemoteObject; import org.eclipse.swt.widgets.Shell; @@ -188,6 +192,31 @@ public class SystemEditFilesAction extends SystemBaseAction { editorId = "org.eclipse.ui.DefaultTextEditor"; //$NON-NLS-1$ } + //If this is a local file in the workspace projects, just open it up. + String absolutePath = remoteFile.getAbsolutePath(); + IFile localFile = null; + if (remoteFile.getHost().getSystemType().isLocal()) + { + localFile = SystemFileActionUtility.getProjectFileForLocation(absolutePath); + } + if (localFile != null) { + if (!localFile.exists()) { + try { + localFile.refreshLocal(IResource.DEPTH_ZERO, null); + } catch (CoreException e) { + SystemBasePlugin.logError(e.getLocalizedMessage(), e); + } + } + try { + SystemFileActionUtility.openEditor(localFile, !remoteFile.canWrite()); + } + catch (Exception e) { + SystemBasePlugin.logError(e.getLocalizedMessage(), e); + return; + } + return; + } + SystemEditableRemoteFile editable = SystemRemoteEditManager.getEditableRemoteObject(remoteFile, des); if (editable == null){ // case for cancelled operation when user was prompted to save file of different case @@ -231,6 +260,4 @@ public class SystemEditFilesAction extends SystemBaseAction { } } - - } diff --git a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SystemFileActionUtility.java b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SystemFileActionUtility.java new file mode 100644 index 00000000000..031205f40e4 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SystemFileActionUtility.java @@ -0,0 +1,172 @@ +/******************************************************************************** + * Copyright (c) 2013 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 + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xuan Chen (IBM) - [399101] RSE edit actions on local files that map to actually workspace resources should not use temp files + ********************************************************************************/ + +package org.eclipse.rse.internal.files.ui.actions; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.ResourceAttributes; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.rse.ui.SystemBasePlugin; +import org.eclipse.ui.IEditorDescriptor; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IEditorRegistry; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.ide.IDE; +import org.eclipse.ui.internal.WorkbenchPage; +import org.eclipse.ui.part.FileEditorInput; + +public class SystemFileActionUtility { + + static void openEditor(IFile localFile, boolean readOnly) throws PartInitException { + IEditorDescriptor editorDescriptor = null; + + try { + editorDescriptor = IDE.getEditorDescriptor(localFile); + } catch (PartInitException e) { + SystemBasePlugin.logError(e.getLocalizedMessage(), e); + } + + if (editorDescriptor == null) { + if (PlatformUI.isWorkbenchRunning()) + { + IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry(); + editorDescriptor = registry.findEditor("org.eclipse.ui.DefaultTextEditor"); //$NON-NLS-1$ + } + } + + //This file is from local connection, and it is inside a project in the work + IWorkbenchPage activePage = SystemBasePlugin.getActiveWorkbenchWindow().getActivePage(); + + ResourceAttributes attr = localFile.getResourceAttributes(); + if (attr!=null) { + attr.setReadOnly(readOnly); + try + { + localFile.setResourceAttributes(attr); + } + catch (Exception e) + { + SystemBasePlugin.logError(e.getLocalizedMessage(), e); + } + } + + // set editor as preferred editor for this file + String editorId = null; + if (editorDescriptor != null) { + editorId = editorDescriptor.getId(); + } + + IDE.setDefaultEditor(localFile, editorId); + if (editorDescriptor.isOpenExternal()){ + SystemFileActionUtility.openSystemEditor(localFile); // opening regular way doesn't work anymore + } + else { + FileEditorInput finput = new FileEditorInput(localFile); + IEditorPart editor = null; + // check for files already open + if (editorDescriptor != null && editorDescriptor.isOpenExternal()){ + editor = ((WorkbenchPage)activePage).openEditorFromDescriptor(new FileEditorInput(localFile), editorDescriptor, true, null); + } + else { + editor = activePage.openEditor(finput, editorDescriptor.getId()); + } + + return; + } + } + + static void openSystemEditor(IFile localFile) throws PartInitException { + IEditorDescriptor editorDescriptor = null; + + try { + editorDescriptor = IDE.getEditorDescriptor(localFile); + } catch (PartInitException e) { + SystemBasePlugin.logError(e.getLocalizedMessage(), e); + } + + if (editorDescriptor == null) { + if (PlatformUI.isWorkbenchRunning()) + { + IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry(); + editorDescriptor = registry.findEditor("org.eclipse.ui.DefaultTextEditor"); //$NON-NLS-1$ + } + } + + //This file is from local connection, and it is inside a project in the work + IWorkbenchPage activePage = SystemBasePlugin.getActiveWorkbenchWindow().getActivePage(); + + // set editor as preferred editor for this file + String editorId = null; + if (editorDescriptor != null) { + editorId = editorDescriptor.getId(); + } + + IDE.setDefaultEditor(localFile, editorId); + + FileEditorInput fileInput = new FileEditorInput(localFile); + activePage.openEditor(fileInput, IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID); + + return; + + } + + /** + * Open the in place editor + */ + public static void openInPlaceEditor(IFile localFile) throws PartInitException + { + IWorkbenchPage activePage = SystemBasePlugin.getActiveWorkbenchWindow().getActivePage(); + FileEditorInput fileInput = new FileEditorInput(localFile); + activePage.openEditor(fileInput, IEditorRegistry.SYSTEM_INPLACE_EDITOR_ID); + } + + public static void hackOpenEditor(IFile localFile, IEditorDescriptor descriptor, boolean readOnly) throws PartInitException + { + //This file is from local connection, and it is inside a project in the work + IWorkbenchPage activePage = SystemBasePlugin.getActiveWorkbenchWindow().getActivePage(); + ResourceAttributes attr = localFile.getResourceAttributes(); + if (attr!=null) { + attr.setReadOnly(readOnly); + try { + localFile.setResourceAttributes(attr); + } + catch (Exception e) + { + SystemBasePlugin.logError(e.getLocalizedMessage(), e); + } + } + + // set editor as preferred editor for this file + String editorId = descriptor.getId(); + IDE.setDefaultEditor(localFile, editorId); + + FileEditorInput finput = new FileEditorInput(localFile); + + IEditorPart editor = null; + if (descriptor.isOpenExternal()){ + editor = ((WorkbenchPage)activePage).openEditorFromDescriptor(new FileEditorInput(localFile), descriptor, true, null); + } + else { + editor = activePage.openEditor(finput, descriptor.getId()); + } + } + + static IFile getProjectFileForLocation(String absolutePath) + { + IPath workspacePath = new Path(absolutePath); + IFile file = SystemBasePlugin.getWorkspaceRoot().getFileForLocation(workspacePath); + return file; + } + + +} diff --git a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SystemMoveRemoteFileAction.java b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SystemMoveRemoteFileAction.java index 2cc156688fd..93d63e71476 100644 --- a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SystemMoveRemoteFileAction.java +++ b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SystemMoveRemoteFileAction.java @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2002, 2011 IBM Corporation and others. All rights reserved. + * Copyright (c) 2002, 2013 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 * available at http://www.eclipse.org/legal/epl-v10.html @@ -27,6 +27,7 @@ * David Dykstal (IBM) [230821] fix IRemoteFileSubSystem API to be consistent with IFileService * David McKnight (IBM) - [240699] Problem with moving a file which has been opened in an editor * David McKnight (IBM) - [191132] Incorrect error message when trying to edit a file that has been moved + * Xuan Chen (IBM) - [399101] RSE edit actions on local files that map to actually workspace resources should not use temp files ********************************************************************************/ package org.eclipse.rse.internal.files.ui.actions; @@ -64,6 +65,7 @@ import org.eclipse.rse.subsystems.files.core.SystemIFileProperties; import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem; import org.eclipse.rse.ui.RSEUIPlugin; +import org.eclipse.rse.ui.SystemBasePlugin; import org.eclipse.rse.ui.actions.SystemBaseCopyAction; import org.eclipse.rse.ui.messages.SystemMessageDialog; import org.eclipse.rse.ui.validators.IValidatorRemoteSelection; @@ -454,14 +456,50 @@ public class SystemMoveRemoteFileAction extends SystemCopyRemoteFileAction // TODO Auto-generated catch block e.printStackTrace(); } - IResource oldLocalResource = null; - if (SystemRemoteEditManager.getInstance().doesRemoteEditProjectExist()){ - oldLocalResource = UniversalFileTransferUtility.getTempFileFor(oldRemoteFile); + IResource oldLocalTempResource = null; + IResource newLocalTempResource = null; + IResource resourceInProjectForOldRemoteFile = null; + IResource resourceInProjectForNewRemoteFile = null; + if (oldRemoteFile.getHost().getSystemType().isLocal()) { + String absolutePath = oldRemoteFile.getAbsolutePath(); + resourceInProjectForOldRemoteFile = SystemFileActionUtility.getProjectFileForLocation(absolutePath); + } + + if (resourceInProjectForOldRemoteFile == null) { + //The source file is not one of the file inside an eclipse project + oldLocalTempResource = UniversalFileTransferUtility.getTempFileFor(oldRemoteFile); + + if (newRemoteFile.getHost().getSystemType().isLocal()) { + String absolutePath = newRemoteFile.getAbsolutePath(); + resourceInProjectForNewRemoteFile = SystemFileActionUtility.getProjectFileForLocation(absolutePath); + } + if (resourceInProjectForNewRemoteFile == null) { + //The destination file is not one of the files inside an eclipse project. + //We need to do regular moving of temp file. + if (SystemRemoteEditManager.getInstance().doesRemoteEditProjectExist()){ + newLocalTempResource = UniversalFileTransferUtility.getTempFileFor(newRemoteFile); + } + } } - if (oldLocalResource != null){ - IResource newLocalResource = UniversalFileTransferUtility.getTempFileFor(newRemoteFile); - moveTempResource(oldLocalResource, newLocalResource, newRemoteFile, ss); + if (oldLocalTempResource != null && oldLocalTempResource.exists()) { + if (newLocalTempResource != null) { + moveTempResource(oldLocalTempResource, newLocalTempResource, newRemoteFile, ss); + } + else { + //Source file is not inside an eclipse project, but destination file is. So we need to delete the temp file for source file only. + try + { + oldLocalTempResource.delete(false, null); + // get rid of associated editable if there was one before + SystemIFileProperties properties = new SystemIFileProperties(oldLocalTempResource); + properties.setRemoteFileObject(null); + } + catch (Exception e) + { + SystemBasePlugin.logError(e.getLocalizedMessage(), e); + } + } } } diff --git a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SystemRemoteFileOpenWithMenu.java b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SystemRemoteFileOpenWithMenu.java index c348472cbed..053d5b9143b 100644 --- a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SystemRemoteFileOpenWithMenu.java +++ b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SystemRemoteFileOpenWithMenu.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2012 IBM Corporation and others. + * Copyright (c) 2005, 2013 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 available at @@ -21,6 +21,7 @@ * David McKnight (IBM) - [309755] SystemRemoteFileOpenWithMenu.getPreferredEditor(), the listed default editor is not always correct * David McKnight (IBM) - [312362] Editing Unix file after it changes on host edits old data * Rick Sawyer (IBM) - [376535] RSE does not respect editor overrides + * Xuan Chen (IBM) - [399101] RSE edit actions on local files that map to actually workspace resources should not use temp files *******************************************************************************/ package org.eclipse.rse.internal.files.ui.actions; import java.lang.reflect.Method; @@ -32,7 +33,9 @@ import java.util.Comparator; import java.util.Hashtable; import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ResourceAttributes; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.content.IContentType; import org.eclipse.jface.action.ContributionItem; @@ -243,14 +246,49 @@ protected void openEditor(IRemoteFile remoteFile, IEditorDescriptor descriptor) catch (Exception e){ } + boolean systemEditor = descriptor != null && descriptor.getId().equals(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID); + + String absolutePath = remoteFile.getAbsolutePath(); + IFile localFile = null; + if (remoteFile.getHost().getSystemType().isLocal()) + { + localFile = SystemFileActionUtility.getProjectFileForLocation(absolutePath); + } + if (localFile != null) { + //It is a local file which inside an eclipse project. + try { + if (!localFile.exists()) { + try { + localFile.refreshLocal(IResource.DEPTH_ZERO, null); + } catch (CoreException e) { + SystemBasePlugin.logError(e.getLocalizedMessage(), e); + } + } + if (systemEditor) { + SystemFileActionUtility.openSystemEditor(localFile); + } + else if (descriptor != null){ + SystemFileActionUtility.hackOpenEditor(localFile, descriptor, !remoteFile.canWrite()); + } + else { + SystemFileActionUtility.openEditor(localFile, !remoteFile.canWrite()); + } + } + catch (Exception e) { + SystemBasePlugin.logError(e.getLocalizedMessage(), e); + return; + } + return; + } + SystemEditableRemoteFile editable = SystemRemoteEditManager.getEditableRemoteObject(remoteFile, descriptor); if (editable == null){ // case for cancelled operation when user was prompted to save file of different case return; } - boolean systemEditor = descriptor != null && descriptor.getId().equals(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID); - + + if (isFileCached(editable, remoteFile)) { try { diff --git a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/view/SystemViewRemoteFileAdapter.java b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/view/SystemViewRemoteFileAdapter.java index 063280bd2d6..efc314afbe0 100644 --- a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/view/SystemViewRemoteFileAdapter.java +++ b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/view/SystemViewRemoteFileAdapter.java @@ -80,6 +80,7 @@ * David McKnight (IBM) - [389838] Fast folder transfer does not account for code page * David Mcknight (IBM) - [374681] Incorrect number of children on the properties page of a directory * Samuel Wu (IBM) - [398988] [ftp] FTP Only support to zVM + * Xuan Chen (IBM) - [399101] RSE edit actions on local files that map to actually workspace resources should not use temp files *******************************************************************************/ package org.eclipse.rse.internal.files.ui.view; @@ -96,12 +97,14 @@ import java.util.StringTokenizer; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourceAttributes; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubProgressMonitor; @@ -215,8 +218,11 @@ import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IEditorRegistry; import org.eclipse.ui.ISharedImages; import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.ide.IDE; +import org.eclipse.ui.internal.WorkbenchPage; import org.eclipse.ui.part.FileEditorInput; import org.eclipse.ui.progress.IElementCollector; import org.eclipse.ui.views.properties.IPropertyDescriptor; @@ -630,7 +636,16 @@ public class SystemViewRemoteFileAdapter */ private IFile getLocalResource(IRemoteFile remoteFile) { - return (IFile)UniversalFileTransferUtility.getTempFileFor(remoteFile); + IFile file = null; + if (remoteFile.getHost().getSystemType().isLocal()) + { + String absolutePath = remoteFile.getAbsolutePath(); + file = getProjectFileForLocation(absolutePath); + } + if (file == null) { + file = (IFile)UniversalFileTransferUtility.getTempFileFor(remoteFile); + } + return file; } /** @@ -3043,6 +3058,7 @@ public class SystemViewRemoteFileAdapter } catch (Exception e) { + SystemBasePlugin.logError(e.getLocalizedMessage(), e); } } @@ -3106,6 +3122,22 @@ public class SystemViewRemoteFileAdapter String newRemotePath = file.getParentPath() + "/" + newName; //$NON-NLS-1$ IResource localResource = null; + IResource localProjectResource = null; + if (file.getHost().getSystemType().isLocal()) + { + if (file.isFile()) { + localProjectResource = getProjectFileForLocation(file.getAbsolutePath()); + } + else { + localProjectResource = getProjectFolderForLocation(file.getAbsolutePath()); + } + } + if (localProjectResource != null) { + //This is a local project file. So we will rename it directly in the workbench. + IPath newLocalPath = localProjectResource.getParent().getFullPath().append(newName); + localProjectResource.move(newLocalPath, true, null); + return true; + } if (SystemRemoteEditManager.getInstance().doesRemoteEditProjectExist()) { localResource = UniversalFileTransferUtility.getTempFileFor(file); @@ -3433,6 +3465,26 @@ public class SystemViewRemoteFileAdapter } // only handle double click if object is a file + String absolutePath = remoteFile.getAbsolutePath(); + IFile localFile = null; + if (remoteFile.getHost().getSystemType().isLocal()) + { + localFile = getProjectFileForLocation(absolutePath); + } + if (localFile != null) { + try { + if (!localFile.exists()) { + + localFile.refreshLocal(IResource.DEPTH_ZERO, null); + } + openEditor(localFile, !remoteFile.canWrite()); + } + catch (Exception e) { + SystemBasePlugin.logError(e.getLocalizedMessage(), e); + return false; + } + return true; + } ISystemEditableRemoteObject editable = getEditableRemoteObject(remoteFile); if (editable != null) { @@ -3471,6 +3523,7 @@ public class SystemViewRemoteFileAdapter editable = getEditableRemoteObject(remoteFile); } + /* Commenting out - no longer needed with fix to bug #376535 if (editable instanceof SystemEditableRemoteFile){ SystemEditableRemoteFile edit = (SystemEditableRemoteFile)editable; @@ -3540,6 +3593,12 @@ public class SystemViewRemoteFileAdapter // in the system editor) IFile file = editable.getLocalResource(); SystemIFileProperties properties = new SystemIFileProperties(file); + try { + // refresh workspace with just added resource + file.refreshLocal(IResource.DEPTH_ZERO, null); + } catch (CoreException e) { + SystemBasePlugin.logError(e.getLocalizedMessage(), e); + } boolean newFile = !file.exists(); // detect whether there exists a temp copy already @@ -3611,9 +3670,21 @@ public class SystemViewRemoteFileAdapter RemoteFile remoteFile = (RemoteFile) element; if (remoteFile.isFile()) { + String absolutePath = remoteFile.getAbsolutePath(); + IFile localProjectFile = null; + if (remoteFile.getHost().getSystemType().isLocal()) + { + localProjectFile = getProjectFileForLocation(absolutePath); + } try { - IFile file = getCachedCopy(remoteFile); // Note that this is a case-sensitive check + IFile file = null; + if (localProjectFile == null) { + file = getCachedCopy(remoteFile); // Note that this is a case-sensitive check + } + else { + file = localProjectFile; + } if (file != null) { SystemIFileProperties properties = new SystemIFileProperties(file); @@ -3898,4 +3969,111 @@ public class SystemViewRemoteFileAdapter { return new SystemFetchOperation(null, o, this, collector, true); } + + private static IFile getProjectFileForLocation(String absolutePath) + { + IPath workspacePath = new Path(absolutePath); + IFile file = SystemBasePlugin.getWorkspaceRoot().getFileForLocation(workspacePath); + return file; + } + + private static IContainer getProjectFolderForLocation(String absolutePath) + { + IPath workspacePath = new Path(absolutePath); + IContainer container = SystemBasePlugin.getWorkspaceRoot().getContainerForLocation(workspacePath); + return container; + } + + private static void openEditor(IFile localFile, boolean readOnly) throws PartInitException { + IEditorDescriptor editorDescriptor = null; + + try { + editorDescriptor = IDE.getEditorDescriptor(localFile); + } catch (PartInitException e) { + SystemBasePlugin.logError(e.getLocalizedMessage(), e); + } + + if (editorDescriptor == null) { + if (PlatformUI.isWorkbenchRunning()) + { + IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry(); + editorDescriptor = registry.findEditor("org.eclipse.ui.DefaultTextEditor"); //$NON-NLS-1$ + } + } + + //This file is from local connection, and it is inside a project in the work + IWorkbenchPage activePage = SystemBasePlugin.getActiveWorkbenchWindow().getActivePage(); + + ResourceAttributes attr = localFile.getResourceAttributes(); + if (attr!=null) { + attr.setReadOnly(readOnly); + try + { + localFile.setResourceAttributes(attr); + } + catch (Exception e) + { + SystemBasePlugin.logError(e.getLocalizedMessage(), e); + } + } + + // set editor as preferred editor for this file + String editorId = null; + if (editorDescriptor != null) { + editorId = editorDescriptor.getId(); + } + + IDE.setDefaultEditor(localFile, editorId); + if (editorDescriptor.isOpenExternal()){ + openSystemEditor(localFile); // opening regular way doesn't work anymore + } + else { + FileEditorInput finput = new FileEditorInput(localFile); + // check for files already open + if (editorDescriptor != null && editorDescriptor.isOpenExternal()){ + ((WorkbenchPage)activePage).openEditorFromDescriptor(new FileEditorInput(localFile), editorDescriptor, true, null); + } + else { + activePage.openEditor(finput, editorDescriptor.getId()); + } + + return; + } + } + + private static void openSystemEditor(IFile localFile) throws PartInitException { + IEditorDescriptor editorDescriptor = null; + + try { + editorDescriptor = IDE.getEditorDescriptor(localFile); + } catch (PartInitException e) { + SystemBasePlugin.logError(e.getLocalizedMessage(), e); + } + + if (editorDescriptor == null) { + if (PlatformUI.isWorkbenchRunning()) + { + IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry(); + editorDescriptor = registry.findEditor("org.eclipse.ui.DefaultTextEditor"); //$NON-NLS-1$ + } + } + + //This file is from local connection, and it is inside a project in the work + IWorkbenchPage activePage = SystemBasePlugin.getActiveWorkbenchWindow().getActivePage(); + + // set editor as preferred editor for this file + String editorId = null; + if (editorDescriptor != null) { + editorId = editorDescriptor.getId(); + } + + IDE.setDefaultEditor(localFile, editorId); + + FileEditorInput fileInput = new FileEditorInput(localFile); + activePage.openEditor(fileInput, IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID); + + return; + + } + }