Posts

Showing posts from 2012

Eclipse Editor: Partially editable/read-only editor Part 4

Image
Blocking drag & drop action to non-editable section It is an additional post to Eclipse Editor: Partially editable/read-only editor series . In all the previous pos ts I have explained making editor partially editable step by step to make functionality more robust. This post I am going to explain how to block drag & drop action to non-editable section of editor. Eclipse’s default implementation of text editor supports drag and drop of selection of text. When you have read-only as well as editable code section present, then such drag and drop may disturb read-only code section. To prevent the read-only code section from getting modified knowing or unknowingly , any drop action on read-on code section should be disabled. Eclipse TextEditor gives handle to DragAndDrop service , using it you can install your own implementation for DropTragetListener against the expected source viewer control. In your implementation any drop operation on the read-only code section can be ignore...

Eclipse SWT : Transform Keyboard key codes to String Format

Image
While working on RCP application in eclipse, you need to capture and display the key or combination of key pressed by user. For example to capture key combination for a binding. If it is character key (printable) then its easy to get character presentation from pressed key code. But it would be little difficult to represent sequence of key or non printable key like “Insert”, “Backspace” etc. The straight forward way is to have map between key integer code and its string presentation, liked explained in SWT snippet Print Key State, Code and Character . There is optimized and standard way is available using eclipse JFace framework. It provides a utility class , SWTKeySupport , for converting SWT events into key strokes and KeySequence , to represent zero or multiple key strokes. KeySequence provides standard string presentation of sequence of keys captured. Here is the simple SWT program to demonstrate usage of these utility classes import org.eclipse.jface.bindings.keys.KeySequenc...

Eclipse Editor: Partially editable/read-only editor Part 3

Blocking Editor Actions in read-only code section: In addition to previous posts about partially editable/read-only editor, I am going to explain blocking editor actions like Ctrl-D in read-only code sections. Till now I have taken care of keyboard events and background color for read only code section. This post, we will see restricting editor actions like Ctrl-D, move line up/down etc. I am going to extend same example of XML editor . In this example, XMLEditor extends TextEditors and hence AbstractTextEditor. AbstractTextEditor is the one who introduces all basic text editor actions to text editor. Few of these actions are Delete Line Cut line move line up/down copy line up/down Shift Left/Right Every Action implements IAction directly or indirectly, IAction provides flexibility of enabling/disabling or handling by providing following set of methods 1: /** 2: * Returns whether this action is enabled. 3: * <p> 4: ...