Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 345387

Summary: [TCF][File system] Open the remote files with a proper editor
Product: [Tools] TCF Reporter: Uwe Stieber <uwe.st>
Component: TargetAssignee: William Chen <william.chen>
Status: RESOLVED FIXED QA Contact: Uwe Stieber <uwe.st>
Severity: enhancement    
Priority: P3 CC: cdtdoug, mober.at+eclipse, william.chen
Version: unspecified   
Target Milestone: 0.4.0   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Bug Depends on:    
Bug Blocks: 345552    
Attachments:
Description Flags
The patch of the fix.
uwe.st: iplog+
Modified patch none

Description Uwe Stieber CLA 2011-05-11 05:39:33 EDT
In a first step open the remote files in read-only mode in a proper editor. 

- Text-type files should open in a internal Eclipse editor by default plus allowing the user to choose the system editor. 
- Binary, non-executable files (.png and similar) should open in the system editor if one is associated.
- Binary, executable files should optionally open in a nice read-only hex editor, if there is one. If not, open this kind of files should be prevented.
Comment 1 Doug Schaefer CLA 2011-05-11 11:39:24 EDT
Cool! I assume you'll be able to save the files to the remote in a future step?
Comment 2 Uwe Stieber CLA 2011-05-11 13:54:33 EDT
Yes. Editing the file and saving the modified content back to the remote target will be a second step and I'll open a separate bugzilla for it too.
Comment 3 Doug Schaefer CLA 2011-05-11 15:27:29 EDT
(In reply to comment #2)
> Yes. Editing the file and saving the modified content back to the remote target
> will be a second step and I'll open a separate bugzilla for it too.

Very cool :).
Comment 4 William Chen CLA 2011-07-04 23:11:27 EDT
Created attachment 199081 [details]
The patch of the fix.

Hi Uwe,

I created a fix for this bug and attached its patch here. Could you please have a review?

The basic idea is that the file is downloaded to a local cache folder before it is opened. The last modified time stamp of the cache file will be set to the same value to that of the remote file. Next time the file is requested to be opened, it checks if the local cache file exists and if the time stamp is the same as the remote file. If it is, then the local cache file will be opened. Or else, it will be downloaded again and then opened.

Technically, a URLStreamHandlerService is registered in the plugin's activator. Every remote file is associated with a URL with the following format:

tcf:///<TCF_AGENT_PEER_ID>/remote/path/to/the/file

The stream handler then creates TcfURLConnection and opens TcfInputStream for streaming. The implementation of TcfInputStream pumps the data from the remote system using TCF channel APIs.

In the future when the feature of saving files is implemented, this stream protocol could be expanded with an TcfOutputStream to do output streaming. 
The reason to use URL API is that I think it is simple, flexible, and easy to be extended.

When the file to be opened is too large, a time triggered progress dialog will pop up to display the downloading progress. The downloading of a large file could be canceled using the progress dialog.

The "Open" menu will show only when the selected file is not a binary file. The content type parsing is based on file name extensions so that the testing is fast enough. 

-William
Comment 5 Uwe Stieber CLA 2011-07-05 02:45:58 EDT
Created attachment 199086 [details]
Modified patch

William,

I've attached a slightly modified version of your patch, fixing some build issues and NPEs. Please resync your local versions with the modified patch.

1. The TCFInputStream implementation is using Java 6 API. Not sure how that builds in your workspace, but the API level for the TE project is still on Java 5.

2. On Windows, the constructed URL is malformed. You get something like "tcf:/<peer id>C:\Temp/x.txt". As the peer id cannot be extracted anymore correctly, you run in a lot of NPEs trying to open the file. I've modified the construction and parsing slightly to deal with it.

If you agree with this changes, I'll go ahead and commit the patch.

Thanks, Uwe
Comment 6 William Chen CLA 2011-07-05 03:51:24 EDT
Hi Uwe,

I've examined your changes to the patch. Yes, I agree with you on the changes. Please go ahead and commit it. Thanks!

-William
Comment 7 William Chen CLA 2011-07-05 04:11:45 EDT
I, William Chen, declare that I developed the attached code from scratch,
without referencing any 3rd party materials except materials licensed under the
EPL. I am authorized by my employer to make this contribution under the EPL.

-William Chen
Comment 8 Uwe Stieber CLA 2011-07-05 04:13:25 EDT
Committed patch.
Comment 9 Martin Oberhuber CLA 2011-07-21 07:31:21 EDT
I think the original patch should not be "obsolete" and should be iplog+