Sigasi Eclipse Blog

Pictures from last Belgian Eclipse Users Group

I have put the pictures from our recent Belgian Eclipse Users Group meeting on Picasa.

Apparently I forgot to take a picture of Peter (ITelegance). I must have been to impressed by the undersea robots... Sorry Peter.

Job opening for R&D engineer at Sigasi, Ghent Belgium

Sigasi is looking for a motivated developer to bring its hardware development toolkit to the next level. To apply for this job, visit our job site.

How to implement "highlight matching brackets" for your custom editor in Eclipse

For our VHDL editor view I wanted to implement highlight matching bracket like it exists in JDT. I had to dig a lot longer in the JDT code than anticipated to find out how JDT implements this functionality. As so often is the case in Eclipse development, in the end this turned out to be really easy. It was again a matter of finding with few lines to add...

The key is to override the configureSourceViewerDecorationSupport method from AbstractDecoratedTextEditor in your editor class and call the setMatchingCharacterPainterPreferenceKeys method. Note that the method name contains character and not bracket, which explains why I had to look so hard to find it.

public final static String EDITOR_MATCHING_BRACKETS = "matchingBrackets";
public final static String EDITOR_MATCHING_BRACKETS_COLOR= "matchingBracketsColor";
 
@Override
protected void configureSourceViewerDecorationSupport (SourceViewerDecorationSupport support) {
	super.configureSourceViewerDecorationSupport(support);		
 
	char[] matchChars = {'(', ')', '[', ']'}; //which brackets to match		
	ICharacterPairMatcher matcher = new DefaultCharacterPairMatcher(matchChars ,
			IDocumentExtension3.DEFAULT_PARTITIONING);
	support.setCharacterPairMatcher(matcher);
	support.setMatchingCharacterPainterPreferenceKeys(EDITOR_MATCHING_BRACKETS,EDITOR_MATCHING_BRACKETS_COLOR);
 
	//Enable bracket highlighting in the preference store
	IPreferenceStore store = getPreferenceStore();
	store.setDefault(EDITOR_MATCHING_BRACKETS, true);
	store.setDefault(EDITOR_MATCHING_BRACKETS_COLOR, "128,128,128");
}

Bracket highlighting is configured by two preference keys in a key store: one for enablement and one for the color of the box around the matched bracket. In the above code fragment I forced matching bracket highlighting with store.setDefault(EDITOR_MATCHING_BRACKETS, true); in neutral gray (store.setDefault(EDITOR_MATCHING_BRACKETS_COLOR, "128,128,128");).

I hope this can save you some time,
Hendrik.

Next Belgian Eclipse User Group Meeting (Tuesday February 23)

The program for the next Belgian Eclipse User Group is ready.

We present Yuri Kok and Wim Jongman, who will introduce us to Eclipse 4.
We are also eagerly looking forward to the presentations of our fellow community members.

Attendance is free, but registration is required and the number of participants is limited.

See you on Tuesday February 23th, 18h00 at PeopleWare in Lier.

How to add a decorator to the splash screen of your RCP application?

Decorated Splash ScreenDecorated Splash Screen I wanted to add a decorator to the splash screen our RCP application Sigasi HDT to give our users a visual clue about which version they are running (beta, trial, ...). After some digging and searching for the correct Google search terms, this turned out to be really simple. There is an extension for that: org.eclipse.ui.splashHandlers

This extension point allows to contribute a splash handler in which you can add custom behavior to the splash screen.
In this extension you have to specify a splashHandler and a splashHandlerProductBinding. In splashHandler you specify the class that implements the custom behaviour. In splashHandlerProductBinding you bind your splashHandler to your RCP application (you could also customize the behaviour of Eclipse's splash screen).

For our product this is:

   <extension point="org.eclipse.ui.splashHandlers">
      <splashHandler
            class="com.sigasi.hdt.ui.SplashHandler"
            id="com.sigasi.hdt.ui.splashHandler">
      </splashHandler>
      <splashHandlerProductBinding
            productId="com.sigasi.hdt.rcp.product"
            splashId="com.sigasi.hdt.ui.splashHandler">
      </splashHandlerProductBinding>
   </extension>

The only thing left to do, is to implement the splashHandler (The quick fix in the Plugin Manifest Editor is a real time saver).

I extended the EclipseSplashHandler (org.eclipse.ui.internal.splash) and just overrided init to superpose a png image in top right corner.

package com.sigasi.hdt.ui;
 
import com.sigasi.hdt.HdtPlugin;
 
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.internal.splash.EclipseSplashHandler;
import org.eclipse.ui.plugin.AbstractUIPlugin;
 
@SuppressWarnings("restriction")
public class SplashHandler extends EclipseSplashHandler {
 
	private static final String BETA_PNG = "icons/splash/beta.png";
	private static final int BORDER = 10;
	private Image image;
 
	public SplashHandler() {
		super();
	}
 
	@Override
	public void init(Shell splash) {
		super.init(splash);
 
		//here you could check some condition on which decoration to show
 
		ImageDescriptor descriptor = AbstractUIPlugin.imageDescriptorFromPlugin(HdtPlugin.ID, BETA_PNG);
		if (descriptor != null)
			image = descriptor.createImage();
		if (image !=null) {
			final int xposition = splash.getSize().x - image.getImageData().width - BORDER;
			final int yposition = BORDER;
			getContent().addPaintListener (new PaintListener () {
				public void paintControl (PaintEvent e) {
					e.gc.drawImage (image, xposition, yposition);
				}
			});
		}
	}
 
	@Override
	public void dispose() {
		super.dispose();
		if (image != null)
			image.dispose();
	}
 
}

Syndicate content