diff --git a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/files/ui/actions/SystemEditFileAction.java b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/files/ui/actions/SystemEditFileAction.java index 140f5cdea6a..304d27c7416 100644 --- a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/files/ui/actions/SystemEditFileAction.java +++ b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/files/ui/actions/SystemEditFileAction.java @@ -16,13 +16,18 @@ package org.eclipse.rse.files.ui.actions; +import org.eclipse.core.resources.IFile; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.rse.core.SystemBasePlugin; import org.eclipse.rse.files.ui.resources.ISystemRemoteEditConstants; import org.eclipse.rse.files.ui.resources.SystemEditableRemoteFile; +import org.eclipse.rse.files.ui.resources.SystemIFileProperties; +import org.eclipse.rse.files.ui.view.DownloadJob; import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem; import org.eclipse.rse.ui.actions.SystemBaseAction; +import org.eclipse.rse.ui.view.ISystemEditableRemoteObject; import org.eclipse.swt.widgets.Shell; @@ -77,13 +82,83 @@ public class SystemEditFileAction extends SystemBaseAction implements ISystemRem process((IRemoteFile)element); } + private boolean isFileCached(ISystemEditableRemoteObject editable, IRemoteFile remoteFile) + { + // DY: check if the file exists and is read-only (because it was previously opened + // in the system editor) + IFile file = editable.getLocalResource(); + SystemIFileProperties properties = new SystemIFileProperties(file); + boolean newFile = !file.exists(); + + // detect whether there exists a temp copy already + if (!newFile && file.exists()) + { + // we have a local copy of this file, so we need to compare timestamps + + // get stored modification stamp + long storedModifiedStamp = properties.getRemoteFileTimeStamp(); + + // get updated remoteFile so we get the current remote timestamp + //remoteFile.markStale(true); + IRemoteFileSubSystem subsystem = remoteFile.getParentRemoteFileSubSystem(); + try + { + remoteFile = subsystem.getRemoteFileObject(remoteFile.getAbsolutePath()); + } + catch (Exception e) + { + + } + + // get the remote modified stamp + long remoteModifiedStamp = remoteFile.getLastModified(); + + // get dirty flag + boolean dirty = properties.getDirty(); + + boolean remoteNewer = (storedModifiedStamp != remoteModifiedStamp); + return (!dirty && !remoteNewer); + } + return false; + } /** * Process the object: download file, open in editor, etc. */ protected void process(IRemoteFile remoteFile) { - + + /* SystemEditableRemoteFile editableFile = new SystemEditableRemoteFile(remoteFile, _editorId); editableFile.open(SystemBasePlugin.getActiveWorkbenchShell()); + */ + SystemEditableRemoteFile editable = new SystemEditableRemoteFile(remoteFile, _editorId); + if (editable != null) + { + try + { + if (editable.checkOpenInEditor() != ISystemEditableRemoteObject.OPEN_IN_SAME_PERSPECTIVE) + { + if (isFileCached(editable, remoteFile)) + { + editable.openEditor(); + } + else + { + DownloadJob oJob = new DownloadJob(editable, false); + oJob.schedule(); + } + } + else + { + editable.setLocalResourceProperties(); + editable.openEditor(); + } + } + catch (Exception e) + { + } + + + } } } \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/files/ui/actions/SystemEditFilesAction.java b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/files/ui/actions/SystemEditFilesAction.java index 8ee95c13696..4d82885c4e3 100644 --- a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/files/ui/actions/SystemEditFilesAction.java +++ b/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/files/ui/actions/SystemEditFilesAction.java @@ -20,12 +20,15 @@ import java.util.Iterator; import org.eclipse.core.resources.IFile; import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.rse.core.SystemBasePlugin; import org.eclipse.rse.files.ui.resources.ISystemRemoteEditConstants; import org.eclipse.rse.files.ui.resources.SystemEditableRemoteFile; +import org.eclipse.rse.files.ui.resources.SystemIFileProperties; import org.eclipse.rse.files.ui.resources.UniversalFileTransferUtility; +import org.eclipse.rse.files.ui.view.DownloadJob; import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem; import org.eclipse.rse.ui.actions.SystemBaseAction; +import org.eclipse.rse.ui.view.ISystemEditableRemoteObject; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IEditorDescriptor; import org.eclipse.ui.IEditorRegistry; @@ -98,21 +101,89 @@ public class SystemEditFilesAction extends SystemBaseAction implements ISystemRe } } - + private boolean isFileCached(ISystemEditableRemoteObject editable, IRemoteFile remoteFile) + { + // DY: check if the file exists and is read-only (because it was previously opened + // in the system editor) + IFile file = editable.getLocalResource(); + SystemIFileProperties properties = new SystemIFileProperties(file); + boolean newFile = !file.exists(); + + // detect whether there exists a temp copy already + if (!newFile && file.exists()) + { + // we have a local copy of this file, so we need to compare timestamps + + // get stored modification stamp + long storedModifiedStamp = properties.getRemoteFileTimeStamp(); + + // get updated remoteFile so we get the current remote timestamp + //remoteFile.markStale(true); + IRemoteFileSubSystem subsystem = remoteFile.getParentRemoteFileSubSystem(); + try + { + remoteFile = subsystem.getRemoteFileObject(remoteFile.getAbsolutePath()); + } + catch (Exception e) + { + + } + + // get the remote modified stamp + long remoteModifiedStamp = remoteFile.getLastModified(); + + // get dirty flag + boolean dirty = properties.getDirty(); + + boolean remoteNewer = (storedModifiedStamp != remoteModifiedStamp); + return (!dirty && !remoteNewer); + } + return false; + } /** * Process the object: download file, open in editor, etc. */ - protected void process(IRemoteFile remoteFile) - { + protected void process(IRemoteFile remoteFile) { + String editorId = null; IEditorDescriptor des = getDefaultEditor(remoteFile); if (des != null) { editorId = des.getId(); } + else + { + editorId = "org.eclipse.ui.DefaultTextEditor"; //$NON-NLS-1$ + } - SystemEditableRemoteFile editableFile = new SystemEditableRemoteFile(remoteFile, editorId); - editableFile.open(SystemBasePlugin.getActiveWorkbenchShell()); + SystemEditableRemoteFile editable = new SystemEditableRemoteFile(remoteFile, editorId); + { + try + { + if (editable.checkOpenInEditor() != ISystemEditableRemoteObject.OPEN_IN_SAME_PERSPECTIVE) + { + if (isFileCached(editable, remoteFile)) + { + editable.openEditor(); + } + else + { + DownloadJob oJob = new DownloadJob(editable, false); + oJob.schedule(); + } + } + else + { + editable.setLocalResourceProperties(); + editable.openEditor(); + } + } + catch (Exception e) + { + } + + } } + } \ No newline at end of file