Eclipse automatically opening some files in system editor - java

Was finding this problem with Eclipse(Kepler) over the last week, so downloaded Eclipse (Luna) and checked out the relevent project into an entirely new workspace.
I'm using *.str files for a particular project (they are standard editor files anyway - short for 'string'). But Eclipse wants to open such files as macVim files:
I have NO file associations set for *.str files:
...althought I do use macVim to open them in the underlying operating system. So I change the system editor to TextEdit and Eclipse happily now wants them to open in TextEdit - but I want to open them in the eclipse editor! (appart from anything else, I've got to develop an editor plugin for *.str files.
How can I convince Eclipse that it can open *.str in it's own editors without having to resort to the system editor?
EDIT - follow the answers - my understanding is this. If Eclipse doens't know what the file is, it will ask the system. If you ask it to open in a particular editor it will overlay that information on that particular file, and to make it happen in general (and change the icon) you need to add a file association.

You can add a a File Associations for '*.str' and set the Associated Editor to 'Text Editor'. Eclipse will use this for files that you have not yet opened.
For files that you have already opened Eclipse will be remembering the editor you last used, so for these right click on the file and use 'Open With > Text Editor'. You should only have to do this once.

Right click on the file, select open with, and there should be three options (Text Editor/System Editor/Default). Selecting text editor should associate it with eclipse (from within eclipse only) in future.

Related

Is it possible to override default code formatt of Eclipse

I have java code style formatter of Eclipse (for that matter it can be formatter of the other language also). When I import he format then it is saved in the workspace and that is applicable for that workspace.
I want code format/style imported and saved in the Eclipse setting itself so that this Eclipse used by anyone gets the format whatever workspace they use.
Is it possible to override the default format? Do I have to write my own plugin?
Thanks,
I can suggest the following in the Java perspective, Eclipse version Indigo...
click Window -> Preferences
expand Java -> Code Style
click Formatter
This will get you to the Formatter screen below. Follow the link on the top right
and see if this provides you with what you are requesting.
Configure Project Specific Settings screen
I wanted settings to be present in the eclipse packaging itself so that these settings (code format, template, spacing strategy etc.) are not repeated at every project and workspace level.
I got a way (at least it works on Linux with neon version). Here are the steps
Open eclipse with some workspace location
Apply all the settings like code formatting, template, Editor
preferences and all other preferred settings present in Window ->
Preferences Press OK. it will save the preferences.
Go to File -> Export -> General -> Preferences and press Next
Make sure Export all is checked and then provide the To
Preference File location and then Click Finish
Now open the exported file in you favorite editor
You will observe it is like a properties file with each property prefixed with /instance/ or /configuration/ (these are preference scopes). Remove all these prefixes (after that all the properties will look like org.* or net.* etc.). You will also see some workspace path related properties are present in this file, either remove them or change to appropriate one.
Save this file with some name say my-eclipse-preference.epf and copy
this file to your eclipse location (where eclipse start file is
present, say ECLIPSE_HOME)
Open $ECLIPSE_HOME/configuration/config.ini and add a line with
the property puluginCoustomization=my-eclipse-preference.epf at the end and save config.ini.
Restart the eclipse, you will find your settings are present even if you open with empty/new workspace. If you are starting from terminal then got to
the ECLIPSE_HOME directory first and then start.
If you want to start from the terminal but you want to avoid going
to the directory to start (i.e. starting from any location) then you should store the file my-eclipse-preference.epf at some standard location and have the value of puluginCoustomization with full path in config.ini.
Hope this helps.

How to enable syntax highlighting in Eclipse Indigo?

How to enable syntax highlighting in Eclipe Indigo? I write in Java. I installed this plugins for more comfortable usage on small screens, but even if I turn it off - all the words in editor are black:(
You may set your coloring preferences by
Window->Preferences-> Java->Editor->Syntax Coloring
Make sure you are using the Java perspective (or Java EE) as well. You should be able to see the name of the active perspective and/or editor in the title bar.
To be 100% sure, you can always right click on the file in question and Open With->Java Editor to ensure that it is the Java editor that is open for your file.
Eclipse remembers which editor you last used to open a file and keeps opening it with that editor, even if you've installed a better one later. Right-click on the file and force it to open with the Java Editor using the "Open With..." menu. If you're not getting any coloring at all, you might just be using the wrong editor.

How get a list of all open files in Eclipse editors?

In my RCP application is editor, almost like in Eclipse. Class editor extends from org.eclipse.ui.texteditor.AbstractTextEditor and it is added in extension in plugin.xml -> org.eclipse.ui.editors. I would like to do view which contains open in editor files. The question is, how do I get a list of all open files?
Screen shot:
I haven't tested it, but you should be able to get it starting from the PlatformUI class.
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences()
In your workspace the following file contains your workbench information:
.metadata/.plugins/org.eclipse.ui.workbench/workbench.xml
It is possible to delete it (or edit it but that requires some fiddling around I suppose) without breaking your workspace, the file gets regenerated by Eclipse. When you delete it all workbench related settings are lost (ie all editors are closed), but your projects of that workspace stay intact.
from that you can get the list of file..

How to make eclipse recognize the correct file extension/open the correct editor for files opened outside of the scope of a project?

I have a simple file index.jsp outside of a project in a location such as /home/user/other/ and I open it in eclipse with File - Open file. The file opens but things such as content assist are not working.
I tried creating a file inside an eclipse project (with File - new - jsp file) and everything works (including content assist).
Is there a way to force eclipse to open the proper editor for files opened outside the scope of a project?
Edit: I'm running eclipse indigo for java ee.
There seems to be a problem with the file not being in a project. I tried moving the file inside a project and now it works. I still want to know how to make this work outside a project though.
Are the file associations set correctly in your eclipse version?
This can be done under Preferences -> General -> Editors -> File Associations
You can set the desired editors for each file extension there. You can also set multiple editors for file associations. In that case you should set the default associated editor to the desired one.
When the default editor is set to your desired one, it should open files from outside of your project with this one.
For JSP files specifically, Java content assist will not work outside the workspace since it relies on a project's Java Build Path (you'll find the same limitations opening .java files). This is normal.

Viewing Java documentation with Eclipse on Mac OS X

I'm trying to accomplish a very basic task and somehow can't seem to find how... I would like to have my Eclipse environment set in a way that I can get help and documentation on any standard class/method in the JDK, like I used to do a few years ago with Eclipse on Windows, where having the cursor on a class name (e.g. PrintWriter), and clicking Ctrl+F2 would open up the Java documentation for the PrintWriter class.
Here's my environment:
Running OS X version 10.6.6.
Just downloaded and installed the Java Developer Package for Mac OS X 10.6 Update 4 from connect.apple.com
I have Eclipse Galileo installed.
Under /Library/Java/JavaVirtualMachines I have a file named 1.6.0_24-b07-334.jdk, which seems to be the new JDK I just installed. However, it's a single file, not expanded into directories and files. Right-clicking it and selecting "Show Package Content" shows me that deep inside it contains the files docs.jar and src.jar. However, not sure what I should be doing with the 1.6.0_24-b07-334.jdk file - should I leave it as is, or perhaps expand it to a full directory structure?
Under Eclipse Preferences, Java/Installed JREs I have JVM 1.6.0 (MacOS X Default) selected. However, the path points to /System/Library... and not to /Library...
Anyway, in Eclipse, putting the mouse over a class name, I get a brown dialog with a short explanation of the class. However, I don't know how to open up the full java documentation of the class. Also couldn't find anywhere in Eclipse a place to indicate where to take the java documentation from, nor which hotkey would bring the java documentation up.
I apologize for the many details, I'm just assuming they may be necessary to get a good answer.
Thanks!
/A
I've had the same problem — previously I had been able access Java documentation and source directly in Eclipse, but that disappeared after one of the Java updates from Apple last year.
My solution was to manually add the source and Javadoc to the JRE definition in Eclipse. Here's how:
Navigate to Preferences --> Java --> Installed JREs
Select your preferred JRE and click Edit...
Select the classes.jar library (should be the first one in the list) and click Javadoc Location...
Click Javadoc in archive
Set Archive path to /Library/Java/JavaVirtualMachines/1.6.0_24-b07-334.jdk/Contents/Home/docs.jar
Set Path within archive to docs/api
Click OK
now, optionally, you can set the source code too...
With classes.jar still selected, click Source Attachment...
Set Location path to /Library/Java/JavaVirtualMachines/1.6.0_24-b07-334.jdk/Contents/Home/src.jar
Click OK
In fact that 1.6.0_24-b07-334.jdk package is actually just a folder; it is treated as a single file by OS X but you can access its contents directly if you know the right path. What if you don't know what path the enter? You can browse the contents from Eclipse if you know this trick:
While attaching source code or Javadoc in Eclipse, click on the External File... or External Folder... button etc to bring up a Finder window
Navigate to your Java JDK folder (usually /Library/Java/JavaVirtualMachines)
You should see a list of your JDKs, for example 1.6.0_22-b04-307.jdk and 1.6.0_24-b07-334.jdk)
Press / on your keyboard to bring up the Go to the folder dialog box
Delete the / from the dialog box, and start typing the name of JDK you want to navigate. You can press Tab to autocomplete the name if you like.
Click Go
You are now browsing the contents of the JDK package; you can now click through to Contents/Home etc where you should see appledocs.jar, docs.jar, src.jar and other goodies.
For everyone finding this StackOverflow-Post and not finding the src.jar:
Apple removed it from the SDK and it's not supplied by default, however you can download it from Apple self at:
http://connect.apple.com/cgi-bin/WebObjects/MemberSite.woa/wo/5.1.17.2.1.3.3.1.0.1.1.0.3.9.3.3.1
http://danbim.blogspot.com/2011/01/java-for-mac-os-x-106-update-3-and.html
P.S. Apple account is required (free registration)
To bring up the Java documentation in Mac, move your mouse to the desired class, then click SHIFT+FN+F2.
By the way, you can find out the shortcut key from Preferences -> General -> Keys -> type "Open Attached Javadoc". Here's my screenshot:-
Under /Library/Java/JavaVirtualMachines I have a file named 1.6.0_24-b07-334.jdk, which seems to be the new JDK I just installed. However, it's a single file, not expanded into directories and files. Right-clicking it and selecting "Show Package Content" shows me that deep inside it contains the files docs.jar and src.jar. However, not sure what I should be doing with the 1.6.0_24-b07-334.jdk file - should I leave it as is, or perhaps expand it to a full directory structure?
From what I remember from Mac OS (I had to use one two years ago for some months) I think this is not really a "single file", it only looks so in the file manager application. Look if you can navigate inside it in the file-chooser dialog of eclipse where you can select the docs.jar for your documentation.
I was having a similar problem, and was having trouble accessing the Apple Developer page to download a local copy of the docs.jar. I went to Preferences > Java > Installed JREs > Edit, and then looked at the "Javadoc Location..." value for the jars. The Javadoc URI was still set to "http://java.sun.com/javase/6/docs/api/". When I changed it to "http://docs.oracle.com/javase/6/docs/api/" the tooltips started showing up again. Of course, this will only work when you are online.

Categories