View | Details | Raw Unified | Return to bug 399101 | Differences between
and this patch

Collapse All | Expand All

(-)a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/files/ui/resources/SystemEditableRemoteFile.java (-1 / +19 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2002, 2012 IBM Corporation and others.
2
 * Copyright (c) 2002, 2013 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 49-54 Link Here
49
 * David McKnight   (IBM)        - [385420] double-click to open System editor from Remote Systems view not working
49
 * David McKnight   (IBM)        - [385420] double-click to open System editor from Remote Systems view not working
50
 * David McKnight   (IBM)        - [385416] NPE during shutdown with remote editor open
50
 * David McKnight   (IBM)        - [385416] NPE during shutdown with remote editor open
51
 * David McKnight   (IBM)        - [390609] Cached file opened twice in case of eclipse linked resource..
51
 * David McKnight   (IBM)        - [390609] Cached file opened twice in case of eclipse linked resource..
52
 * Xuan Chen        (IBM)        - [399101] RSE edit actions on local files that map to actually workspace resources should not use temp files
52
 *******************************************************************************/
53
 *******************************************************************************/
53
54
54
package org.eclipse.rse.files.ui.resources;
55
package org.eclipse.rse.files.ui.resources;
Lines 1009-1014 Link Here
1009
	 */
1010
	 */
1010
	private String getDownloadPath()
1011
	private String getDownloadPath()
1011
	{
1012
	{
1013
		//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.
1014
		IFile file = null;
1015
		if (remoteFile.getHost().getSystemType().isLocal())
1016
		{
1017
			String absolutePath = remoteFile.getAbsolutePath();
1018
			file = getProjectFileForLocation(absolutePath);
1019
		}
1020
		if (file != null) {
1021
			return remotePath;
1022
		}
1012
1023
1013
		IPath path = new Path(root);
1024
		IPath path = new Path(root);
1014
1025
Lines 2174-2177 Link Here
2174
		_editorDescriptor = descriptor;
2185
		_editorDescriptor = descriptor;
2175
	}
2186
	}
2176
	
2187
	
2188
	private static IFile getProjectFileForLocation(String absolutePath)
2189
	{
2190
		IPath workspacePath = new Path(absolutePath);
2191
		IFile file = SystemBasePlugin.getWorkspaceRoot().getFileForLocation(workspacePath);
2192
		return file;
2193
	}
2194
	
2177
}
2195
}
(-)a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SystemEditFilesAction.java (-3 / +27 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2002, 2010 IBM Corporation and others.
2
 * Copyright (c) 2002, 2013 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 19-24 Link Here
19
 * David McKnight   (IBM)        - [276103] Files with names in different cases are not handled properly
19
 * David McKnight   (IBM)        - [276103] Files with names in different cases are not handled properly
20
 * David McKnight   (IBM)        - [309813] RSE permits opening of file after access removed
20
 * David McKnight   (IBM)        - [309813] RSE permits opening of file after access removed
21
 * David McKnight   (IBM)        - [312362] Editing Unix file after it changes on host edits old data
21
 * David McKnight   (IBM)        - [312362] Editing Unix file after it changes on host edits old data
22
 * Xuan Chen        (IBM)        - [399101] RSE edit actions on local files that map to actually workspace resources should not use temp files
22
 *******************************************************************************/
23
 *******************************************************************************/
23
24
24
package org.eclipse.rse.internal.files.ui.actions;
25
package org.eclipse.rse.internal.files.ui.actions;
Lines 26-31 Link Here
26
import java.util.Iterator;
27
import java.util.Iterator;
27
28
28
import org.eclipse.core.resources.IFile;
29
import org.eclipse.core.resources.IFile;
30
import org.eclipse.core.resources.IResource;
31
import org.eclipse.core.runtime.CoreException;
29
import org.eclipse.core.runtime.NullProgressMonitor;
32
import org.eclipse.core.runtime.NullProgressMonitor;
30
import org.eclipse.jface.viewers.IStructuredSelection;
33
import org.eclipse.jface.viewers.IStructuredSelection;
31
import org.eclipse.rse.files.ui.resources.SystemEditableRemoteFile;
34
import org.eclipse.rse.files.ui.resources.SystemEditableRemoteFile;
Lines 188-193 Link Here
188
			editorId = "org.eclipse.ui.DefaultTextEditor"; //$NON-NLS-1$
191
			editorId = "org.eclipse.ui.DefaultTextEditor"; //$NON-NLS-1$
189
		}
192
		}
190
		
193
		
194
		//If this is a local file in the workspace projects, just open it up.
195
		String absolutePath = remoteFile.getAbsolutePath();
196
		IFile localFile = null;
197
		if (remoteFile.getHost().getSystemType().isLocal())
198
		{
199
			localFile = SystemFileActionUtility.getProjectFileForLocation(absolutePath);
200
		}
201
		if (localFile != null) {
202
			if (!localFile.exists()) {
203
				try {
204
					localFile.refreshLocal(IResource.DEPTH_ZERO, null);
205
				} catch (CoreException e) {
206
				}
207
			}
208
			try {
209
				SystemFileActionUtility.openEditor(localFile, !remoteFile.canWrite());
210
			}
211
			catch (Exception e) {
212
				return;
213
			}
214
			return;
215
		}
216
		
191
		SystemEditableRemoteFile editable = SystemRemoteEditManager.getEditableRemoteObject(remoteFile, des);
217
		SystemEditableRemoteFile editable = SystemRemoteEditManager.getEditableRemoteObject(remoteFile, des);
192
		if (editable == null){
218
		if (editable == null){
193
			// case for cancelled operation when user was prompted to save file of different case
219
			// case for cancelled operation when user was prompted to save file of different case
Lines 230-236 Link Here
230
					
256
					
231
		}
257
		}
232
	}
258
	}
233
234
235
259
236
}
260
}
(-)a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SystemFileActionUtility.java (+173 lines)
Added Link Here
1
/********************************************************************************
2
 * Copyright (c) 2013 IBM Corporation and others. All rights reserved.
3
 * This program and the accompanying materials are made available under the terms
4
 * of the Eclipse Public License v1.0 which accompanies this distribution, and is 
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors:
8
 * Xuan Chen        (IBM)        - [399101] RSE edit actions on local files that map to actually workspace resources should not use temp files
9
 ********************************************************************************/
10
11
package org.eclipse.rse.internal.files.ui.actions;
12
13
import org.eclipse.core.resources.IFile;
14
import org.eclipse.core.resources.ResourceAttributes;
15
import org.eclipse.core.runtime.IPath;
16
import org.eclipse.core.runtime.Path;
17
import org.eclipse.rse.ui.SystemBasePlugin;
18
import org.eclipse.ui.IEditorDescriptor;
19
import org.eclipse.ui.IEditorPart;
20
import org.eclipse.ui.IEditorRegistry;
21
import org.eclipse.ui.IWorkbenchPage;
22
import org.eclipse.ui.PartInitException;
23
import org.eclipse.ui.PlatformUI;
24
import org.eclipse.ui.ide.IDE;
25
import org.eclipse.ui.internal.WorkbenchPage;
26
import org.eclipse.ui.part.FileEditorInput;
27
28
public class SystemFileActionUtility {
29
	
30
	static void openEditor(IFile localFile, boolean readOnly) throws PartInitException {
31
		IEditorDescriptor editorDescriptor = null;
32
		
33
		try {
34
			editorDescriptor = IDE.getEditorDescriptor(localFile);
35
		} catch (PartInitException e) {
36
			
37
		}
38
		
39
		if (editorDescriptor == null) {
40
			if (PlatformUI.isWorkbenchRunning())
41
			{
42
				IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry();
43
				editorDescriptor = registry.findEditor("org.eclipse.ui.DefaultTextEditor"); //$NON-NLS-1$
44
			}
45
		}
46
		
47
		//This file is from local connection, and it is inside a project in the work
48
		IWorkbenchPage activePage = SystemBasePlugin.getActiveWorkbenchWindow().getActivePage();
49
		
50
		ResourceAttributes attr = localFile.getResourceAttributes();
51
		if (attr!=null) {
52
			attr.setReadOnly(readOnly);
53
			try
54
			{
55
				localFile.setResourceAttributes(attr);
56
			}
57
			catch (Exception e)
58
			{
59
60
			}
61
		}
62
63
		// set editor as preferred editor for this file
64
		String editorId = null;
65
		if (editorDescriptor != null) {
66
				editorId = editorDescriptor.getId();
67
		}
68
69
		IDE.setDefaultEditor(localFile, editorId);
70
		if (editorDescriptor.isOpenExternal()){
71
			SystemFileActionUtility.openSystemEditor(localFile); // opening regular way doesn't work anymore
72
		}
73
		else {
74
			FileEditorInput finput = new FileEditorInput(localFile);
75
			IEditorPart editor = null;
76
			// check for files already open
77
			if (editorDescriptor != null && editorDescriptor.isOpenExternal()){
78
				editor = ((WorkbenchPage)activePage).openEditorFromDescriptor(new FileEditorInput(localFile), editorDescriptor, true, null);
79
			}
80
			else {
81
				editor =  activePage.openEditor(finput, editorDescriptor.getId());
82
			}
83
	
84
			return;
85
		}
86
	}
87
	
88
	static void openSystemEditor(IFile localFile) throws PartInitException {
89
		IEditorDescriptor editorDescriptor = null;
90
		
91
		try {
92
			editorDescriptor = IDE.getEditorDescriptor(localFile);
93
		} catch (PartInitException e) {
94
			
95
		}
96
		
97
		if (editorDescriptor == null) {
98
			if (PlatformUI.isWorkbenchRunning())
99
			{
100
				IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry();
101
				editorDescriptor = registry.findEditor("org.eclipse.ui.DefaultTextEditor"); //$NON-NLS-1$
102
			}
103
		}
104
		
105
		//This file is from local connection, and it is inside a project in the work
106
		IWorkbenchPage activePage = SystemBasePlugin.getActiveWorkbenchWindow().getActivePage();
107
108
		// set editor as preferred editor for this file
109
		String editorId = null;
110
		if (editorDescriptor != null) {
111
				editorId = editorDescriptor.getId();
112
		}
113
114
		IDE.setDefaultEditor(localFile, editorId);
115
		
116
		FileEditorInput fileInput = new FileEditorInput(localFile);
117
		activePage.openEditor(fileInput, IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
118
	
119
		return;
120
		
121
	}
122
	
123
	/**
124
	 * Open the in place editor
125
	 */
126
	public static void openInPlaceEditor(IFile localFile) throws PartInitException
127
	{
128
		IWorkbenchPage activePage = SystemBasePlugin.getActiveWorkbenchWindow().getActivePage();
129
		FileEditorInput fileInput = new FileEditorInput(localFile);
130
		activePage.openEditor(fileInput, IEditorRegistry.SYSTEM_INPLACE_EDITOR_ID);
131
	}
132
	
133
	public static void hackOpenEditor(IFile localFile, IEditorDescriptor descriptor, boolean readOnly) throws PartInitException
134
	{
135
		//This file is from local connection, and it is inside a project in the work
136
		IWorkbenchPage activePage = SystemBasePlugin.getActiveWorkbenchWindow().getActivePage();
137
		ResourceAttributes attr = localFile.getResourceAttributes();
138
		if (attr!=null) {
139
			attr.setReadOnly(readOnly);
140
			try	{
141
				localFile.setResourceAttributes(attr);
142
			}
143
			catch (Exception e)
144
			{}
145
		}
146
147
		// set editor as preferred editor for this file
148
		String editorId = descriptor.getId();
149
		IDE.setDefaultEditor(localFile, editorId);
150
151
		FileEditorInput finput = new FileEditorInput(localFile);
152
153
		IEditorPart editor = null;
154
		if (descriptor.isOpenExternal()){
155
			editor = ((WorkbenchPage)activePage).openEditorFromDescriptor(new FileEditorInput(localFile), descriptor, true, null);
156
		}
157
		else {
158
			editor =  activePage.openEditor(finput, descriptor.getId());
159
		}
160
	}
161
	
162
	static IFile getProjectFileForLocation(String absolutePath)
163
	{
164
		//String pathstr = normalizePath(absolutePath.toString(), srcFileOrFolder.getParentRemoteFileSubSystem().getSeparatorChar());
165
		//char localSeparator = File.separatorChar;
166
		IPath workspacePath = new Path(absolutePath);
167
		//IPath workspacePath = getLocalPathObject(absolutePath);
168
		IFile file = SystemBasePlugin.getWorkspaceRoot().getFileForLocation(workspacePath);
169
		return file;
170
	}
171
	
172
173
}
(-)a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SystemMoveRemoteFileAction.java (-7 / +43 lines)
Lines 1-5 Link Here
1
/********************************************************************************
1
/********************************************************************************
2
 * Copyright (c) 2002, 2011 IBM Corporation and others. All rights reserved.
2
 * Copyright (c) 2002, 2013 IBM Corporation and others. All rights reserved.
3
 * This program and the accompanying materials are made available under the terms
3
 * This program and the accompanying materials are made available under the terms
4
 * of the Eclipse Public License v1.0 which accompanies this distribution, and is 
4
 * of the Eclipse Public License v1.0 which accompanies this distribution, and is 
5
 * available at http://www.eclipse.org/legal/epl-v10.html
5
 * available at http://www.eclipse.org/legal/epl-v10.html
Lines 27-32 Link Here
27
 * David Dykstal (IBM) [230821] fix IRemoteFileSubSystem API to be consistent with IFileService
27
 * David Dykstal (IBM) [230821] fix IRemoteFileSubSystem API to be consistent with IFileService
28
 * David McKnight   (IBM)        - [240699] Problem with moving a file which has been opened in an editor
28
 * David McKnight   (IBM)        - [240699] Problem with moving a file which has been opened in an editor
29
 * David McKnight   (IBM)        - [191132] Incorrect error message when trying to edit a file that has been moved
29
 * David McKnight   (IBM)        - [191132] Incorrect error message when trying to edit a file that has been moved
30
 * Xuan Chen        (IBM)        - [399101] RSE edit actions on local files that map to actually workspace resources should not use temp files
30
 ********************************************************************************/
31
 ********************************************************************************/
31
32
32
package org.eclipse.rse.internal.files.ui.actions;
33
package org.eclipse.rse.internal.files.ui.actions;
Lines 454-467 Link Here
454
				// TODO Auto-generated catch block
455
				// TODO Auto-generated catch block
455
				e.printStackTrace();
456
				e.printStackTrace();
456
			}
457
			}
457
			IResource oldLocalResource = null;
458
			IResource oldLocalTempResource = null;
458
			if (SystemRemoteEditManager.getInstance().doesRemoteEditProjectExist()){				
459
			IResource newLocalTempResource = null;
459
				oldLocalResource = UniversalFileTransferUtility.getTempFileFor(oldRemoteFile);
460
			IResource resourceInProjectForOldRemoteFile = null;
461
			IResource resourceInProjectForNewRemoteFile = null;
462
			if (oldRemoteFile.getHost().getSystemType().isLocal()) {
463
				String absolutePath = oldRemoteFile.getAbsolutePath();
464
				resourceInProjectForOldRemoteFile = SystemFileActionUtility.getProjectFileForLocation(absolutePath);
465
			} 
466
			
467
			if (resourceInProjectForOldRemoteFile == null) {
468
				//The source file is not one of the file inside an eclipse project
469
				oldLocalTempResource = UniversalFileTransferUtility.getTempFileFor(oldRemoteFile);
470
				
471
				if (newRemoteFile.getHost().getSystemType().isLocal()) {
472
					String absolutePath = newRemoteFile.getAbsolutePath();
473
					resourceInProjectForNewRemoteFile = SystemFileActionUtility.getProjectFileForLocation(absolutePath);
474
				} 
475
				if (resourceInProjectForNewRemoteFile == null) {
476
					//The destination file is not one of the files inside an eclipse project.
477
					//We need to do regular moving of temp file.
478
					if (SystemRemoteEditManager.getInstance().doesRemoteEditProjectExist()){				
479
						newLocalTempResource = UniversalFileTransferUtility.getTempFileFor(newRemoteFile);	
480
					}
481
				}
460
			}
482
			}
461
	
483
	
462
			if (oldLocalResource != null){
484
			if (oldLocalTempResource != null && oldLocalTempResource.exists()) {
463
				IResource newLocalResource = UniversalFileTransferUtility.getTempFileFor(newRemoteFile);			
485
				if (newLocalTempResource != null) {
464
				moveTempResource(oldLocalResource, newLocalResource, newRemoteFile, ss);
486
					moveTempResource(oldLocalTempResource, newLocalTempResource, newRemoteFile, ss);
487
				}
488
				else {
489
					//Source file is not inside an eclipse project, but destination file is.  So we need to delete the temp file for source file only.
490
					try
491
					{
492
						oldLocalTempResource.delete(false, null);
493
						// get rid of associated editable if there was one before
494
						SystemIFileProperties properties = new SystemIFileProperties(oldLocalTempResource);
495
						properties.setRemoteFileObject(null);					
496
					}
497
					catch (Exception e)
498
					{
499
					}
500
				}
465
			}
501
			}
466
		}
502
		}
467
		
503
		
(-)a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/actions/SystemRemoteFileOpenWithMenu.java (-3 / +39 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2012 IBM Corporation and others.
2
 * Copyright (c) 2005, 2013 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 21-26 Link Here
21
 * David McKnight   (IBM)        - [309755] SystemRemoteFileOpenWithMenu.getPreferredEditor(), the listed default editor is not always correct
21
 * David McKnight   (IBM)        - [309755] SystemRemoteFileOpenWithMenu.getPreferredEditor(), the listed default editor is not always correct
22
 * David McKnight   (IBM)        - [312362] Editing Unix file after it changes on host edits old data
22
 * David McKnight   (IBM)        - [312362] Editing Unix file after it changes on host edits old data
23
 * Rick Sawyer      (IBM)        - [376535] RSE does not respect editor overrides
23
 * Rick Sawyer      (IBM)        - [376535] RSE does not respect editor overrides
24
 * Xuan Chen        (IBM)        - [399101] RSE edit actions on local files that map to actually workspace resources should not use temp files
24
 *******************************************************************************/
25
 *******************************************************************************/
25
package org.eclipse.rse.internal.files.ui.actions;
26
package org.eclipse.rse.internal.files.ui.actions;
26
import java.lang.reflect.Method;
27
import java.lang.reflect.Method;
Lines 32-38 Link Here
32
import java.util.Hashtable;
33
import java.util.Hashtable;
33
34
34
import org.eclipse.core.resources.IFile;
35
import org.eclipse.core.resources.IFile;
36
import org.eclipse.core.resources.IResource;
35
import org.eclipse.core.resources.ResourceAttributes;
37
import org.eclipse.core.resources.ResourceAttributes;
38
import org.eclipse.core.runtime.CoreException;
36
import org.eclipse.core.runtime.NullProgressMonitor;
39
import org.eclipse.core.runtime.NullProgressMonitor;
37
import org.eclipse.core.runtime.content.IContentType;
40
import org.eclipse.core.runtime.content.IContentType;
38
import org.eclipse.jface.action.ContributionItem;
41
import org.eclipse.jface.action.ContributionItem;
Lines 243-256 Link Here
243
	catch (Exception e){				
246
	catch (Exception e){				
244
	}
247
	}
245
	
248
	
249
	boolean systemEditor = descriptor != null && descriptor.getId().equals(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
250
251
	String absolutePath = remoteFile.getAbsolutePath();
252
	IFile localFile = null;
253
	if (remoteFile.getHost().getSystemType().isLocal())
254
	{
255
		localFile = SystemFileActionUtility.getProjectFileForLocation(absolutePath);
256
	}
257
	if (localFile != null) {
258
		//It is a local file which inside an eclipse project.
259
		try {
260
			if (!localFile.exists()) {
261
				try {
262
					localFile.refreshLocal(IResource.DEPTH_ZERO, null);
263
				} catch (CoreException e) {
264
				}
265
			}
266
			if (systemEditor) {
267
				SystemFileActionUtility.openSystemEditor(localFile);
268
			}
269
			else if (descriptor != null){
270
				SystemFileActionUtility.hackOpenEditor(localFile, descriptor, !remoteFile.canWrite());
271
			}
272
			else {
273
				SystemFileActionUtility.openEditor(localFile, !remoteFile.canWrite());
274
			}
275
		}
276
		catch (Exception e) {
277
			return;
278
		}
279
		return;
280
	}
281
	
246
	SystemEditableRemoteFile editable = SystemRemoteEditManager.getEditableRemoteObject(remoteFile, descriptor);
282
	SystemEditableRemoteFile editable = SystemRemoteEditManager.getEditableRemoteObject(remoteFile, descriptor);
247
	if (editable == null){
283
	if (editable == null){
248
		// case for cancelled operation when user was prompted to save file of different case
284
		// case for cancelled operation when user was prompted to save file of different case
249
		return;
285
		return;
250
	}
286
	}
251
	
287
	
252
	boolean systemEditor = descriptor != null && descriptor.getId().equals(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
288
	
253
289
	
254
	if (isFileCached(editable, remoteFile)) {
290
	if (isFileCached(editable, remoteFile)) {
255
		
291
		
256
		try {
292
		try {
(-)a/rse/plugins/org.eclipse.rse.files.ui/src/org/eclipse/rse/internal/files/ui/view/SystemViewRemoteFileAdapter.java (-2 / +156 lines)
Lines 80-85 Link Here
80
 * David McKnight   (IBM)        - [389838] Fast folder transfer does not account for code page
80
 * David McKnight   (IBM)        - [389838] Fast folder transfer does not account for code page
81
 * David Mcknight   (IBM)        - [374681] Incorrect number of children on the properties page of a directory
81
 * David Mcknight   (IBM)        - [374681] Incorrect number of children on the properties page of a directory
82
 * Samuel Wu        (IBM)        - [398988] [ftp] FTP Only support to zVM
82
 * Samuel Wu        (IBM)        - [398988] [ftp] FTP Only support to zVM
83
 * Xuan Chen        (IBM)        - [399101] RSE edit actions on local files that map to actually workspace resources should not use temp files
83
 *******************************************************************************/
84
 *******************************************************************************/
84
85
85
package org.eclipse.rse.internal.files.ui.view;
86
package org.eclipse.rse.internal.files.ui.view;
Lines 96-107 Link Here
96
import org.eclipse.core.resources.IContainer;
97
import org.eclipse.core.resources.IContainer;
97
import org.eclipse.core.resources.IFile;
98
import org.eclipse.core.resources.IFile;
98
import org.eclipse.core.resources.IResource;
99
import org.eclipse.core.resources.IResource;
100
import org.eclipse.core.resources.ResourceAttributes;
99
import org.eclipse.core.runtime.CoreException;
101
import org.eclipse.core.runtime.CoreException;
100
import org.eclipse.core.runtime.IAdaptable;
102
import org.eclipse.core.runtime.IAdaptable;
101
import org.eclipse.core.runtime.IPath;
103
import org.eclipse.core.runtime.IPath;
102
import org.eclipse.core.runtime.IProgressMonitor;
104
import org.eclipse.core.runtime.IProgressMonitor;
103
import org.eclipse.core.runtime.IStatus;
105
import org.eclipse.core.runtime.IStatus;
104
import org.eclipse.core.runtime.NullProgressMonitor;
106
import org.eclipse.core.runtime.NullProgressMonitor;
107
import org.eclipse.core.runtime.Path;
105
import org.eclipse.core.runtime.Platform;
108
import org.eclipse.core.runtime.Platform;
106
import org.eclipse.core.runtime.Status;
109
import org.eclipse.core.runtime.Status;
107
import org.eclipse.core.runtime.SubProgressMonitor;
110
import org.eclipse.core.runtime.SubProgressMonitor;
Lines 215-222 Link Here
215
import org.eclipse.ui.IEditorRegistry;
218
import org.eclipse.ui.IEditorRegistry;
216
import org.eclipse.ui.ISharedImages;
219
import org.eclipse.ui.ISharedImages;
217
import org.eclipse.ui.IWorkbench;
220
import org.eclipse.ui.IWorkbench;
221
import org.eclipse.ui.IWorkbenchPage;
222
import org.eclipse.ui.PartInitException;
218
import org.eclipse.ui.PlatformUI;
223
import org.eclipse.ui.PlatformUI;
219
import org.eclipse.ui.ide.IDE;
224
import org.eclipse.ui.ide.IDE;
225
import org.eclipse.ui.internal.WorkbenchPage;
220
import org.eclipse.ui.part.FileEditorInput;
226
import org.eclipse.ui.part.FileEditorInput;
221
import org.eclipse.ui.progress.IElementCollector;
227
import org.eclipse.ui.progress.IElementCollector;
222
import org.eclipse.ui.views.properties.IPropertyDescriptor;
228
import org.eclipse.ui.views.properties.IPropertyDescriptor;
Lines 630-636 Link Here
630
	 */
636
	 */
631
	private IFile getLocalResource(IRemoteFile remoteFile) 
637
	private IFile getLocalResource(IRemoteFile remoteFile) 
632
	{
638
	{
633
	    return (IFile)UniversalFileTransferUtility.getTempFileFor(remoteFile);
639
		IFile file = null;
640
		if (remoteFile.getHost().getSystemType().isLocal())
641
		{
642
			String absolutePath = remoteFile.getAbsolutePath();
643
			file = getProjectFileForLocation(absolutePath);
644
		}
645
		if (file == null) {
646
			file = (IFile)UniversalFileTransferUtility.getTempFileFor(remoteFile);
647
		}
648
	    return file;
634
	}
649
	}
635
	
650
	
636
	/**
651
	/**
Lines 3433-3438 Link Here
3433
			}
3448
			}
3434
			
3449
			
3435
			// only handle double click if object is a file
3450
			// only handle double click if object is a file
3451
			String absolutePath = remoteFile.getAbsolutePath();
3452
			IFile localFile = null;
3453
			if (remoteFile.getHost().getSystemType().isLocal())
3454
			{
3455
				localFile = getProjectFileForLocation(absolutePath);
3456
			}
3457
			if (localFile != null) {
3458
				try {
3459
					if (!localFile.exists()) {
3460
						
3461
						localFile.refreshLocal(IResource.DEPTH_ZERO, null);
3462
					}
3463
					openEditor(localFile,  !remoteFile.canWrite());
3464
				}
3465
				catch (Exception e) {
3466
					return false;
3467
				}
3468
				return true;
3469
			}
3436
			ISystemEditableRemoteObject editable = getEditableRemoteObject(remoteFile);	
3470
			ISystemEditableRemoteObject editable = getEditableRemoteObject(remoteFile);	
3437
			if (editable != null)
3471
			if (editable != null)
3438
			{
3472
			{
Lines 3470-3475 Link Here
3470
					// open new editor for correct replica
3504
					// open new editor for correct replica
3471
					editable = getEditableRemoteObject(remoteFile);
3505
					editable = getEditableRemoteObject(remoteFile);
3472
				}
3506
				}
3507
				
3473
				
3508
				
3474
				/* Commenting out - no longer needed with fix to bug #376535
3509
				/* Commenting out - no longer needed with fix to bug #376535
3475
				if (editable instanceof SystemEditableRemoteFile){
3510
				if (editable instanceof SystemEditableRemoteFile){
Lines 3540-3545 Link Here
3540
		// in the system editor)
3575
		// in the system editor)
3541
		IFile file = editable.getLocalResource();
3576
		IFile file = editable.getLocalResource();
3542
		SystemIFileProperties properties = new SystemIFileProperties(file);
3577
		SystemIFileProperties properties = new SystemIFileProperties(file);
3578
		try {
3579
			// refresh workspace with just added resource
3580
			file.refreshLocal(IResource.DEPTH_ZERO, null);
3581
		} catch (CoreException e) {
3582
			SystemBasePlugin.logError(e.getMessage());
3583
		}
3543
		boolean newFile = !file.exists();
3584
		boolean newFile = !file.exists();
3544
3585
3545
		// detect whether there exists a temp copy already
3586
		// detect whether there exists a temp copy already
Lines 3611-3619 Link Here
3611
		RemoteFile remoteFile = (RemoteFile) element;
3652
		RemoteFile remoteFile = (RemoteFile) element;
3612
		if (remoteFile.isFile())
3653
		if (remoteFile.isFile())
3613
		{
3654
		{
3655
			String absolutePath = remoteFile.getAbsolutePath();
3656
			IFile localProjectFile = null;
3657
			if (remoteFile.getHost().getSystemType().isLocal())
3658
			{
3659
				localProjectFile = getProjectFileForLocation(absolutePath);
3660
			}
3614
			try
3661
			try
3615
			{
3662
			{
3616
				IFile file = getCachedCopy(remoteFile); // Note that this is a case-sensitive check
3663
				IFile file = null;
3664
				if (localProjectFile == null) {
3665
					file = getCachedCopy(remoteFile); // Note that this is a case-sensitive check
3666
				}
3667
				else {
3668
					file = localProjectFile;
3669
				}
3617
				if (file != null)
3670
				if (file != null)
3618
				{
3671
				{
3619
					SystemIFileProperties properties = new SystemIFileProperties(file);
3672
					SystemIFileProperties properties = new SystemIFileProperties(file);
Lines 3898-3901 Link Here
3898
	{
3951
	{
3899
	    return new SystemFetchOperation(null, o, this, collector, true);
3952
	    return new SystemFetchOperation(null, o, this, collector, true);
3900
	}
3953
	}
3954
	
3955
	private static IFile getProjectFileForLocation(String absolutePath)
3956
	{
3957
		IPath workspacePath = new Path(absolutePath);
3958
		IFile file = SystemBasePlugin.getWorkspaceRoot().getFileForLocation(workspacePath);
3959
		return file;
3960
	}
3961
	
3962
	private static void openEditor(IFile localFile, boolean readOnly) throws PartInitException {
3963
		IEditorDescriptor editorDescriptor = null;
3964
		
3965
		try {
3966
			editorDescriptor = IDE.getEditorDescriptor(localFile);
3967
		} catch (PartInitException e) {
3968
			
3969
		}
3970
		
3971
		if (editorDescriptor == null) {
3972
			if (PlatformUI.isWorkbenchRunning())
3973
			{
3974
				IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry();
3975
				editorDescriptor = registry.findEditor("org.eclipse.ui.DefaultTextEditor"); //$NON-NLS-1$
3976
			}
3977
		}
3978
		
3979
		//This file is from local connection, and it is inside a project in the work
3980
		IWorkbenchPage activePage = SystemBasePlugin.getActiveWorkbenchWindow().getActivePage();
3981
		
3982
		ResourceAttributes attr = localFile.getResourceAttributes();
3983
		if (attr!=null) {
3984
			attr.setReadOnly(readOnly);
3985
			try
3986
			{
3987
				localFile.setResourceAttributes(attr);
3988
			}
3989
			catch (Exception e)
3990
			{
3991
3992
			}
3993
		}
3994
3995
		// set editor as preferred editor for this file
3996
		String editorId = null;
3997
		if (editorDescriptor != null) {
3998
				editorId = editorDescriptor.getId();
3999
		}
4000
4001
		IDE.setDefaultEditor(localFile, editorId);
4002
		if (editorDescriptor.isOpenExternal()){
4003
			openSystemEditor(localFile); // opening regular way doesn't work anymore
4004
		}
4005
		else {
4006
			FileEditorInput finput = new FileEditorInput(localFile);
4007
			IEditorPart editor = null;
4008
			// check for files already open
4009
			if (editorDescriptor != null && editorDescriptor.isOpenExternal()){
4010
				editor = ((WorkbenchPage)activePage).openEditorFromDescriptor(new FileEditorInput(localFile), editorDescriptor, true, null);
4011
			}
4012
			else {
4013
				editor =  activePage.openEditor(finput, editorDescriptor.getId());
4014
			}
4015
	
4016
			return;
4017
		}
4018
	}
4019
	
4020
	private static void openSystemEditor(IFile localFile) throws PartInitException {
4021
		IEditorDescriptor editorDescriptor = null;
4022
		
4023
		try {
4024
			editorDescriptor = IDE.getEditorDescriptor(localFile);
4025
		} catch (PartInitException e) {
4026
			
4027
		}
4028
		
4029
		if (editorDescriptor == null) {
4030
			if (PlatformUI.isWorkbenchRunning())
4031
			{
4032
				IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry();
4033
				editorDescriptor = registry.findEditor("org.eclipse.ui.DefaultTextEditor"); //$NON-NLS-1$
4034
			}
4035
		}
4036
		
4037
		//This file is from local connection, and it is inside a project in the work
4038
		IWorkbenchPage activePage = SystemBasePlugin.getActiveWorkbenchWindow().getActivePage();
4039
4040
		// set editor as preferred editor for this file
4041
		String editorId = null;
4042
		if (editorDescriptor != null) {
4043
				editorId = editorDescriptor.getId();
4044
		}
4045
4046
		IDE.setDefaultEditor(localFile, editorId);
4047
		
4048
		FileEditorInput fileInput = new FileEditorInput(localFile);
4049
		activePage.openEditor(fileInput, IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
4050
	
4051
		return;
4052
		
4053
	}
4054
	
3901
}
4055
}

Return to bug 399101