How to programmatically get information in Eclipse - eclipse

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.

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 =)

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().

Have you tried the solution proposed in http://www.eclipse.org/forums/index.php/mv/msg/97927/300308/#msg_300308?

Related

discover which Eclipse projects are opened

Is there any way to discover programatically (but not in PDE code) which eclipse projects are opened?
I was hoping that would exist a .metadata anywhere telling me that, but couldn't find any non binary data.
The closer I got was something like:
"$WORKSPACE.metadata/.plugins/org.eclipse.core.resources/.projects/%s/org.eclipse.jdt.core/state.dat" where %s refers to the project name
I think m2eclipse uses that guy for some kind of control, because on a m2project this file gets removed as soon as the projects build.
Also, i found some information on .metadata/.plugins/org.eclipse.ui.workbench/workingsets.xml but none of them give me the full info I was hoping to find.
Does anyone knows how to solve it?
I was trying on eclipse 3.7.
On eclipse 4.3 , at least, its possible to parse $WORKSPACE/.metadata/.plugins/org.eclipse.ui.workbench/workingsets.xml and look up whether the desired project has a factoryID="org.eclipse.jdt.ui.PersistableJavaElementFactory", meaning it is opened.
I Didn't try this on 4.2 tough, maybe it works there as well.
To do it "programmatically", you call the APIs from the org.eclipse.core.resources plug-in. Otherwise, you are doing it wrong.

Mapping between resource file and model object in Eclipse plugin app

Please anyone help me understand and use IDE.openEditor(IWorkbenchPage, IFile).
I have a resource file (xml format), it contains my model objects. I'm writing a wizard to create it, save it into workspace, view it inside a tree view (I use CommonNavigator) and open it in an editor. I need to know the control flow of this all. How to map between resource file and model objects, how the navigator can show that objects and how to open editor that associated with my resource file.
I'm sorry, I'm a newbie in Eclipse field. I know I need too much, but please give me at least an idea.
Thanks a lot.
A great character once said... "You have much to learn young padawan".
Here's a great place to start your journey though the basics of Eclipse plug-in / RCP development...
http://www.vogella.com/eclipse.html
If you really want to get down and dirty into the bowels of Eclipse, you can use Eclipse itself to teach you the dirty details about what's really going on.
Figure out how to view Eclipse source code inside of Eclipse.
Set break points at interesting points in Eclipse source code that you want to know more about.
Use the 'Eclipse Application' run configuration to run an instance of Eclipse from within your main Eclipse.
Use your newly launched Eclipse to preform the tasks you want to mimic and hopefully, you'll hit one of your break points and see how the Eclipse developers did what you want to do.

Files filter plugin in eclipse (in Package Explorer - Navigator)

I want to create a some custom filters for my eclipse project. I think this can be done extending a plugin.
For example .asm file should go to the ASM filter, .c files to the C filter, and so on.
All my input files are stored in the Source folder (on my computer).
But I need this filters only for a better file management, in the Package Explorer.
Please, if anybody have a starting point for this issue ... I will appreciate.
The sooner, the better :)
You might want to have a look at this:
Eclipse Common Navigator Framework
And read this tutorial to create a custom navigation:
Custom Navigator
(It's part 7, but in the beginning there is a lot of theory. just find your personal starting point)
I hope this is what you were looking for or that you can at least get something useful out of it...

Auto upload files in included path using Netbeans

I have a NetBeans javascript project with several included paths for plugins. I do not want to include the plugins in my core repository, so I have created separate, external folders for each and am including them via an include path. Because I test across many devices, I need my changes to upload on save and this works fine for the main code base, however, I would like to be able to edit a plugin via the include path and see those changes auto uploaded as well. Is this possible?
As of right now, the only alternative I see is to create separate projects for each plugin, which I am willing to do if this is the only option. The single project workflow is very preferable to me and I might be willing to switch IDE's if this is possible in another environment.
I would be happy to elaborate if my intentions are unclear.
I don't think it's possible. What about creating one single "umbrella" project for all plugins and simply manage it the same way you do the main project?
Personal note: What you have is basically several projects and the uploading is focused always on single project. So what you want is like "I want to treat them as projects but not to at the same time" :) Btw, how do you edit a plugin? I guess open it as a project in NetBeans or use some text editor. So again you basically treat it as a project.

Play 2.0 with Eclipse 3.6, Scala template editing

I´m new to Play and Scala world, so I´m needing some help to figure out how can I edit the scala template files using Eclipse. I already installed scala ide 2.9 but when I try to edit the index.scala.html, the contents of the file aren´t editable...
Please can anyone help me?
I experienced this just recently, too, but lucky for you I made the full migration from IntelliJ to Eclipse.
There is some setting up you need to do with the Scala templates, but one of the easiest ways to get it done is following these steps:
Step 1: Add file extensions
http://help.eclipse.org/helios/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Ftasks%2Ftasks-51.xhtml
Be sure that your file extensions are properly added to the file associations.
Step 2:
Look at the associated editor. In the image above you'll see that the only associated editor with *.htm is Web Browser. So you'll need to hit the "Add..." button to add the Scala editor. Don't forget to set it as default :)
Step 3:
Right-click on your Scala template and be sure that you are choosing the right editor. You can also use this to switch between editors.
Hope this helps!