Eclipse RCP: programmatically associate file type with Editor? - eclipse

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.

Related

How to activate Fluid (TYPO3) autocompletion in Netbeans?

I did what it said here: Extbase and Fluid Autocompletion
In NetBeans right-click your Extension project and choose Properties
in the opened context menu to edit the project properties. Select the
category PHP Include Path and use Add Folder... to add the directories
of Extbase and Fluid.
So I added the Fluid and Extbase Folders which I previously copied onto my computer from the Server at /var/www/typo3_src/typo3_src-6.2.25/typo3/sysext:
but it didn't work - here's my Project:
And here is fluid stuff that the editor still doesn't recognize:
What am I doing or thinking wrong?
Found info here, works for me:
It's an old topic but I have a trick so that you can add Auto-complete
function for fluid, vhs, flux.
First of all, download the XSD schema files from here :
https://fluidtypo3.org/viewhelpers/fluid/master.html put them
somewhere locally.
Next step, in Netbeans, go to menu Tools > DTD and XML Schemas, add
your 3 DTD in user catalog :
Flux : Public ID = http://typo3.org/ns/FluidTYPO3/Flux/ViewHelpers URI
= path to your flux XDS file
Fluid : Public ID = http://typo3.org/ns/TYPO3/Fluid/ViewHelpers URI =
path to your fluid XDS file
Vhs : Public ID = http://typo3.org/ns/FluidTYPO3/Vhs/ViewHelpers URI =
path to your flux VHS file
Next, in project properties, go to 'testing' menu and add the folder
where you stored your DTD.
Now, in your Project > Test Files, add a new XML Document and choose
"XML Schema-Constrained Document" on next step, click the button
'Browse' and By File > Your Project > Test Files and select import for
all the xsd schema files.
Then, change the prefix f for fluid, flux for flux and vhs for vhs
choose fluid as primary and finish.
A file is created with this content :
And into the section <f:alias>, you have the auto-completion for
fluid, vhs and flux.
<f:alias
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns:f='http://typo3.org/ns/TYPO3/Fluid/ViewHelpers'
xmlns:vhs='http://typo3.org/ns/FluidTYPO3/Vhs/ViewHelpers'
xmlns:flux='http://typo3.org/ns/FluidTYPO3/Flux/ViewHelpers'
xsi:schemaLocation='http://typo3.org/ns/TYPO3/Fluid/ViewHelpers file:/home/florian/Documents/Docs/Netbeans/Autocomplete%20Fluid/Schemas/Fluid.xsd
http://typo3.org/ns/FluidTYPO3/Vhs/ViewHelpers file:/home/florian/Documents/Docs/Netbeans/Autocomplete%20Fluid/Schemas/Vhs.xsd
http://typo3.org/ns/FluidTYPO3/Flux/ViewHelpers file:/home/florian/Documents/Docs/Netbeans/Autocomplete%20Fluid/Schemas/Flux.xsd'>
Auto-completion here
</f:alias>
http://netbeans-org.1045718.n5.nabble.com/Schemas-for-code-completion-with-xsd-tt5752294.html#none
take files from https://fluidtypo3.org/schemas/
Some more info Use Netbeans to Create Sample XML from XSD
From a project that contains the .xsd:
Click New File on the tool bar or File > New File from the menu
Choose XML > XML Document
Name your file, click next
Choose XML Schema-Constrained Document, click next
Click the Browse button and use By File to navigate to the .xsd
Click the Import check box beside the file name, click next
Review the options available and click Finish to generate
You can use more than one .xsd file to generate the .xml. In this case it will use whichever .xsd file you choose as Primary to resolve any conflicts.

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.

Create editor with multiple parts in Eclipse 4.x

I want to create an application that can open files. When opening a file, an editor should open like in the normal Eclipse IDE. but i want in this Editor multiple Parts (e.g. TreeView of the opened data and data in plaintext)
Is there a way to describe the contents of this editor in the Application.e4xmi and then just opening this "view"?
like this:
Application.e4xmi:
PartStack (id = "editor.partstack")
|- Part (DataTreeViewer.java)
|- Part (PlaintextViewer.java)
\- Part (ImagePart.java)
OpenHandler.java:
PartStack ps = openPartStack("editor.partstack");
addToMainPartstack(ps);
Or do i have to describe the editor contents programmatically in the OpenHandler? like this:
OpenHandler.java:
PartStack ps = createNewPartStack();
ps.add(new DataTreeViewer());
ps.add(new PlainTextViewer());
ps.add(new ImagePart());
addToMainPartstack(ps);
I just used a PartDescriptor for the editor part and an ordinary CTabFolder for the pages in the editor.

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

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