How do you stop Eclipse from inserting a certain class in Content-Assist? - eclipse

I'm using SpringSource Tool Suite (Eclipse) to program with Grails, and I'm also using JFreechart in the program.
In Grails you log by typing log.info("method worked"). Unfortunately JFrechart has a class called "Log" with Static methods like "info". This means that in STS I type log.info and then when I type space or ( Eclipse "assists" me by importing the JFreechart Log class and changing what I've typed to Log.info(message). Very irritating.
I reckon I could turn off the Eclipse option to "insert single proposals automatically", but I like this feature. Can I instruct Eclipse not to give me content assist from this particular JFreechart class?

You can add the JFreechart Log class to Type Filters via Window > Preferences > Java > Appearance > Type Filters:
alt text http://www.imagebanana.com/img/aairbchy/screenshot_009.png

Related

Use of RCP e3-plugins in pure e4-application

I have an existing RCP-project that consists mostly of e3.x plugins. The target-platform is already migrated to Eclipse 4.5 and the compatibility layer is also in use. Currently it is possible to use the new POJO e4view in plugins. That "mixed mode" is working fine. But when I need to extend the existing menu via extensions (org.eclipse.ui.main.menu), I have to use the extension in plugin.xml.
My goal is to create an application-model (Application.e4xmi) and migrate the definitions from the current main-plugin.xml to the new application-model (i.e. handler, menu definitions etc.). New plugins should use the new model-fragment (fragment.e4xmi). It is very important, that I wont modify the existing e3-plugins. Is it possible to migrate the existing main-plugin to pure e4 plugin and add the old e3-plugins without having to change them.
The main goal is to write new e4-plugins (with DI, POJO handler, views etc.) while keeping the e3-plugins.
For example:
Plugin Main(e4):
Application.e3xmi (contains menu definition, handler, commands etc.)
plugin.xml (contains application and product target)
Plugin A(e4):
e4views (POJO)
fragment.e4xmi (contains extentions for new menu-entry)
plugin.xml
Plugin B(legacy e3):
e3 (extends from ViewPart)
plugin.xml (contains extentions for new menu-entry, old handler)
I think at the moment there are only 2 ways to contribute to the application model.
Model Fragment
Model Processor
The second one would be an option for you to contribute your menu entries. The problem is afaik it's only possible with the new model elements and you would need to implement a processor in the e3 plug-ins. My conclusion is that a pure e4 application with e3 contributions is not possible right now but I could be wrong.
Example taken from:
Eclipse4Modularity vogella
// the menu is injected based on the parameter
// defined in the extension point
#Inject
#Named("org.eclipse.ui.file.menu")
private MMenu menu;
MDirectMenuItem menuItem = modelService.createModelElement(MDirectMenuItem.class);
menuItem.setLabel("Another Exit");
menuItem.setContributionURI("bundleclass://"
+ "com.example.e4.rcp.todo.contribute/"
+ ExitHandlerWithCheck.class.getName());
menu.getChildren().add(menuItem);

Apply code format style to large Java project in Eclipse

Recently I did something wrong and it ruined my project's code style format, my eyes bleed with the new code style format and I neither can read or edit my code. I fixed the project settings by restoring to default, but pre-formatted code resits the new Eclipse Format and I have to fix every Java file one by one by hand...
This is how all my sources look like after the mistake
dropDat.setItemId(Integer
.parseInt(attrs
.getNamedItem(
"itemid")
.getNodeValue()));
dropDat.setMinDrop(Integer
.parseInt(attrs
.getNamedItem(
"min")
.getNodeValue()));
dropDat.setMaxDrop(Integer
.parseInt(attrs
.getNamedItem(
"max")
.getNodeValue()));
dropDat.setChance(Integer
.parseInt(attrs
.getNamedItem(
"chance")
.getNodeValue()));
The same code should look like:
dropDat.setItemId(Integer.parseInt(attrs.getNamedItem("itemid").getNodeValue()));
...
dropDat.setItemId(Integer.parseInt(attrs.getNamedItem("chance").getNodeValue()));
My whole project is destroyed (30.000+ Java files) into this annoying coding style... What should I do to automatically fix it?
Create a formatter profile here Windows > Preferences > Java > Code Style > Formatter.
Then in package explorer view right click on project then select Source > Format.
You can also create your source clean up profile here Windows > Preferences > Java > Code Style > Clean Up
Then in package explorer view right click on project then select Source > Clean up.
You have to repeat it for all projects.
If you have many many projects then try this solution

Shortcuts key for Eclipse for Return - Eclipse

I was a Netbeans user for almost one year. Now, I´m changing my IDE to Eclipse and I´m learning Shortcuts Keys. In Netbeans I used to type "re", then hit Tab key to complete return keyword. How is this done in Eclipse?
While I don't think there is a predefined option for this, your best bet will be to create a custom Java Editor Template. In your Eclipse Preferences, under Java > Editor > Templates, you can create a new template with the following specifications:
Name: re
Context: Java statements
Automatically Insert: Checked
Pattern: return ${retVal:var('${return_type}')};
What this will do is you can type re and then bring up Content Assist using Ctrl+Space. The very first proposal will be this template and it will be selected already. If you hit Enter and it'll insert a line like the following:
return retVal;
At this point, there will be an outline around retVal and you can hit Ctrl+Space again and it'll give you variables you can return that are in scope and match your method's return type or simply type what you want to return.

Proper Case formatting a text in JasperReports

Is there a way to create a "proper case text display in JasperReports". I am using JasperReports 5.x with iReport Designer.
I have data returned from DB which is a string/text field user entered text... the problem here is some users enter in all calitals and some enter in all small I want to display the text values in a proper case... I know this can be achieved in SQL but unfortunately I dont have that option to simply edit the query....
Thanks for your help in advance...
Meeza
There wouldnt be any standard settings in iReport, you would need to use an external Method to create the text you need. I would try to go for an Apache Commons solution, or create your own Method.
I have not used the WordUtils class from Apache Commons Lang, but it looks like capitalize may be what you want.
http://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/WordUtils.html#capitalize(java.lang.String)
To Add a Jar to your classpath in iReport:
Tools -> Option -> Classpath -> Add Jar
You then need to import the Class as well:
From the Report root element, edit the Properties. Find "Imports" click on the ellipses (...) and add your class!
iReport Imports

Eclipse RCP: programmatically associate file type with Editor?

How programmatically associate file type with Editor?
That is what Eclipse-RCP Java code can do what is archived with the following UI interaction:
Window -> Preferences
General -> Editors -> File Associations
Add... > File type: *.json
Select *.json file type
Add... (Associated editors) > JavaScript Editor
Make it default
Ralated to Q
https://stackoverflow.com/questions/12429221/eclipse-file-associations-determine-which-editor-in-list-of-associated-editors
Eclipse: associate an editor with a content type
Get associated file extensions for an Eclipse editor
Opening a default editor, on a treeviewer selection eclipse rcp(eg: as eclipse knows that j.java files must be opened in text editor)
eclipse rcp change icon for xml configuration file
I know your questions says "programmatically" but I'll give a complete run down of the methods.
If you are writing the plugin that provides the editor, then you should simply declare the extension in your plugin.xml.
<extension
point="org.eclipse.ui.editors">
<editor
...
extensions="json"
...
If you are distributing a complete RPC application, you can edit the plugin.xml for the plugin that provides the editor or add a plugin that just refers to that editor.
But, if you have to do it programmatically, you are manipulating the internals of an RPC instance. Eclipse does not provide a public API for that but this code will do it:
// error handling is omitted for brevity
String extension = "json";
String editorId = "theplugin.editors.TheEditor";
EditorRegistry editorReg = (EditorRegistry)PlatformUI.getWorkbench().getEditorRegistry();
EditorDescriptor editor = (EditorDescriptor) editorReg.findEditor(editorId);
FileEditorMapping mapping = new FileEditorMapping(extension);
mapping.addEditor(editor);
mapping.setDefaultEditor(editor);
IFileEditorMapping[] mappings = editorReg.getFileEditorMappings();
FileEditorMapping[] newMappings = new FileEditorMapping[mappings.length+1];
for (int i = 0; i < mappings.length; i++) {
newMappings[i] = (FileEditorMapping) mappings[i];
}
newMappings[mappings.length] = mapping;
editorReg.setFileEditorMappings(newMappings);
Associating file type means associating content of ur editor with a predefined one.
This can be easily achieved via plugin.xml..
Just follow the following link:-
Eclipse help Documentation
http://help.eclipse.org/indigo/index.jsp
and search for org.eclipse.core.contenttype.contentTypes.