Posts

Showing posts with the label code

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

WeakHashMap by example

Usually we read following explanation about java.util.WeakHashMap “A hashtable-based Map implementation with weak keys. An entry in a WeakHashMap will automatically be removed when its key is no longer in ordinary use” Unlike java.util.HashMap, WeakHashMap maintain weak reference for the all keys objects and strong reference of value objects. As per features of weak reference, they are more prone to be collection by GC. WeakHashMap runs some kind of unknown services to remove all the entries from collection whose keys are already garbage collected. It means entries in weak hash map may changes over the time. Whenever there  is a need of more memory to your application, GC cycle will execute and its job is to collect all un-referenced objects or weak references. In some cases GC may collected keys of weak hash map as those are a weak references. Once keys are garbage collected , WeakHashMap’s implementation job is to clear all such entries.   See the following program, I...

Eclipse PDE: Everything about Editor Part 5

Image
Code Completion using Content Assist This post explains about completion proposal feature of eclipse editor framework. This is part of Everything About Editor series. Content assist provides content assist help to developer while writing code in editor. It helps from static suggestion of language keyword to methods suggestion for dynamic reference on hitting “Ctrl-Space” or entering  any of activator character like ‘.’. Following two interfaces plays key role in implementing code completion for customer editor. ICompletionProposal – Responsible for providing set of proposals text, associated icons etc. IContentAssistProcessor – Responsible for calculating the completion proposals at a point in the editor. It also defines character on which it shoud auto-activate. In this example we are going to see providing content assist then user enters ‘#’. To achieve this we need to implement IComppletionProposal that will return set of proposals as well as tells framework which c...