Posts

Showing posts from June, 2012

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

Serializable Singleton Class

Previously I have posted about Singleton Design Pattern implementation and handling concurrency . In this post I am going to explains challenges for serializable Singleton class. Lets know about Singleton Class ( Single Design Pattern), A Singleton class restricts access to its constructor to ensure that only a single instance is ever created. I have taken example from previous post only   1: /** 2: * Singleton Class 3: * 4: * @author ydevatra 5: * 6: */ 7: public class SingletonResource implements Serializable { 8:   9: /* Private instance reference */ 10: private static SingletonResource resource = new SingletonResource(); 11:   12: /** 13: * Private constructor to restrict creation of instance of this class by 14: * other class. 15: */ 16: private SingletonResource() { 17: // Initialization code... 18: } 19:   20: ...