how to organize imports via commandhttps://www.eclipse.org/forums/index.php/mv/msg/296552/804614/#msg_804614
I'm creating a plugin where I often generate code into active editor. This code of course contains classes, so I would like to organise imports after I generate this code (shortcut ctrl+shift+o).

Has anyone done this before? I've been searchin the web for answer but either haven't found anything or it was not working.

but nothing happens after execute. Although when I used different command (org.eclipse.ui.edit.selectAll) it worked and it selected all nodes in my tree viewer. Which means these few lines of code works, but not with organize.imports command. Would be cool if anyone knew why. My guess is, that command is executed at my view and therefore it doesnt work, because it is tryin to organize imports in view. But I have no idea to make it work at my active editor.

I also tried playing with this Class:

org.eclipse.jdt.ui.actions.OrganizeImportsAction

but I just got Exception java.lang.NoClassDefFoundError which I could not get rid of.

This code I posted I'm calling in my tree viewer class in Action which is in viewer contextmenu.]]>Andrej B2012-02-22T20:33:50-00:00Re: how to organize imports via commandhttps://www.eclipse.org/forums/index.php/mv/msg/296552/822914/#msg_822914
. Execution of import command wasn't working because editor wasn't active. I tried calling command in menu (because when you select items in menu, editor is still active) and it organized my imports.

For those who generate some code... also this command is quite useful: "org.eclipse.jdt.ui.edit.text.java.format" which calls the formatter (ctrl+shift+f)

//edit: if you still want to call command from view (or anywhere except editor) just activate him and then use executeCommand service

Case closed. Have a nice day everyone.]]>Andrej B2012-03-17T13:42:30-00:00Re: how to organize imports via commandhttps://www.eclipse.org/forums/index.php/mv/msg/296552/909414/#msg_909414
we would like to execute the OrganizeImportAction on the whole Project, without any Editors beeing open.
How can this be done ?