http://stackoverflow.com/questions/1233102/replace-selected-code-from-eclipse-editor-thru-plugin-comand
try {
IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if ( part instanceof ITextEditor ) {
final ITextEditor editor = (ITextEditor)part;
IDocumentProvider prov = editor.getDocumentProvider();
IDocument doc = prov.getDocument( editor.getEditorInput() );
ISelection sel = editor.getSelectionProvider().getSelection();
if ( sel instanceof TextSelection ) {
final TextSelection textSel = (TextSelection)sel;
String newText = "/*" + textSel.getText() + "*/";
doc.replace( textSel.getOffset(), textSel.getLength(), newText );
}
}
} catch ( Exception ex ) {
ex.printStackTrace();
}