I resolved my question. Above code wasn't working for me because i was accessing it outside SWT thread. So i have to make a new thread and write code in that thread. Following is the code i used to make it work.
new Thread(new Runnable() {
@SuppressWarnings("static-access")
public void run() {
try {Thread.sleep(10); } catch (Exception e) { }
PlatformUI.getWorkbench().getDisplay().getDefault().asyncExec(new Runnable() {
public void run() {
textViewer.invalidateTextPresentation();
Color lightColor = PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_GRAY);
Color blueColor=new Color(PlatformUI.getWorkbench().getDisplay(),0,0,255);
TextPresentation presentation = new TextPresentation();
TextAttribute attr = new TextAttribute(blueColor,lightColor , 0);
presentation.addStyleRange(new StyleRange(startRegion, finalStr.length(), attr.getForeground(),attr.getBackground()));
textViewer.changeTextPresentation(presentation, true);
}
});
}
}).start();