How to programmatically get information in Eclipse

792 views Asked by At

I'm developing an Eclipse Plug-in. I need to programmatically get both filepath and filename of the selected/active file in the eclipse editor.
Also need to programmatically add an existing file (located outside the project) to the project and then open it on the editor.
I'm a totally beginner with Eclipse, so complete solution would be appreciated.

3

There are 3 answers

1
reprogrammer On
0
rambo On

You question is quite general, but this should clear things up a bit:

Eclipse Plugin Development Tutorial

About adding a file to the project, you have to read the documentation and find where eclipse handles projects. I think that if you have a reference to the project it should be easy.

Hope it helps =)

3
Volker Stolz On

Your editor is most likely inheriting from IEditorPart, so you should be able to call getEditorInput(), which then may or may not turn out to be a FileEditorInput, for example. From there, you can get at the underlying details of the file.

For your second problem, you can use IProject.create() and then e.g. do an IFile.createLink() and use a local filesystem path, or copy the file using IFile.appendContents().