Posts

Showing posts with the label development

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: ...

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

Image
Decorating read-only section by line background The second part of this series I am going to explain changing line background color for particular section of editor, in this case read-only code section. We had reached till restricting editing in read-only code section in previous post . After previous post changes, user won’t able to edit in read-only code section, but user should get some kind of feedback about not able to edit the particular section of file. It would be very informative to color the background with grey color so that user understand that greyed out section is read-only. This can be achieved by providing Line background color listen over source viewer. LineBackgroundListener lineBackgroundListener = new LineBackgroundListener(){ @Override public void lineGetBackground(LineBackgroundEvent event) { int offset = event.lineOffset; if (editorSupport.isInsideReadOnlyBlock(offset, 0)){ event.lineBackground = colorManager.getColor...