Showing posts from 2010

Hide empty last column from Table/Tree Viewer

1. How to remove last vestigial column from TableViewer
You might have seen that there is dummy or vestigial column in the TableViewer (as marked by the red oval in the below figure) which  is annoying at times because not only it look ugly but more so it occupy;s the precious  real state from your component/control like shown in figure below:

Solution: You can use TableColumnLayout from org.eclipse.jface.layout package inside org.eclipse.jface plugin which allows to layout the columns in your TableViewer in essentially two ways:

Firstly via mentioning the width in pixel for each column present in the Viewer Secondly, we could mentioned weightsThe data could be supplied to the layout via of the implementation of ColumnLayoutData. The following snippet shows how to achieve it:

tableColumnLayout.setColumnData(tableColumn, new ColumnWeightData(1));

Explanation of the above line:

tableColumnLayout isinstance of ColumnLayoutDatatableColumn is the column on which LayoutData need to be set in the …

IAction and Widget mapping

This post explains how you can map a IAction as an model to a Button. In this case IAction will act as an model to your UI component Button by which you can control the behaviour of the button. In fact in the same way you can use IAction for MenuItem and ToolItem.

IAction belong to jface and button is and SWT component. Well  ActionContributionItem in the package org.eclipse.jface.action from the plugin org.eclipse.jface comes to rescue, the class provides API for the conversion.

Below are the step wise instructions needs to be followed to achieve it:

Instantiate ActionContributionItem with IAction objectCall the fill method on the ActionContributionItem object with appropriate parameter (in our case it should be instanceof Composite)That's all you are done now call a getWidget API to work on your SWT widget.

Listeners are managed automatically so you need bother about themLook and feel is also been taken care ofThings to keep in mind:

You need to set the layout data on the

Null Pointer in ViewerColumn of TableViewer on call of setInput

If you are getting the the NPE whle creating the TableViewer and your stack trace looks somewhat like this:

at org.eclipse.jface.viewers.ViewerColumn.refresh(
at org.eclipse.jface.viewers.AbstractTableViewer.doUpdateItem(
at org.eclipse.jface.viewers.StructuredViewer$
at org.eclipse.jface.util.SafeRunnable$
at org.eclipse.jface.viewers.StructuredViewer.updateItem(
at org.eclipse.jface.viewers.AbstractTableViewer.createItem(
at org.eclipse.jface.viewers.AbstractTableViewer.internalRefreshAll(
at org.eclipse.jface.viewers.AbstractTableViewer.internalRefresh(
at org.eclipse.jface.viewers.AbstractTableViewer.internalRefresh(

JFace's IAction and SWT's Button Mapping

Has it ever occurred to you that, you use the IAction/Action as a model for the swt's button widget.

Well there is very simple way of doing it, following steps help you achieve just that:
Create and IAction object  Create the Wrapper around IAction object of ActionContributionItem Call the fill method (there are 3 overridden fill method are present choose as per your requirement) of the class ActionContributionItem passing the parent composite on which you want your button widget to be createdThat's it your button widget is ready with Action model on the backend :)Following are the benefits of keeping the model and UI separate:
You don't have to bother about the state change and propagation of events   You can work on Action object on the back-end which is easier and simpler than working on UI objectsYour UI layer can be automated without worrying about sync problems

Content Assist in DLTK editor

This post explains how to contribute your templates in the Dynamic Languages Toolkit (DLTK) editor's content assist. Its a common requirement to incorporate your custom library API's into existing API, hence provide developer with larger domain of predefined functionality to work with.

The second step is to incorporate the options in all the existing IDE tools(the post covers only content assist) so that developer can easily leverage.

There are couple extension point which make your job hell lot easier, following are the abstract dummy steps to accomplish the same:

1. First of all there is a extension point="org.eclipse.dltk.ui.scriptCompletionProposalComputer" which essentially requires the ancestor as org.eclipse.dltk.ui.text.completion.ScriptCompletionProposalComputer (or its parent), apart from this some declarative options are also there.

2. Secondly you can provide static templates in the form of xml file via extension point="org.eclipse.ui.editors.templat…