Skip to main content

Posts

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 weights The 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 is   instance of  ColumnLayoutData tableColumn is the column on which

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 object Call 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. Benefits: Listeners are managed automatically so you need bother about them Look and feel is also been taken care of Things to keep in mind: You need

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: java.lang.NullPointerException at org.eclipse.jface.viewers.ViewerColumn.refresh(ViewerColumn.java:145) at org.eclipse.jface.viewers.AbstractTableViewer.doUpdateItem(AbstractTableViewer.java:399) at org.eclipse.jface.viewers.StructuredViewer$UpdateItemSafeRunnable.run(StructuredViewer.java:481) at org.eclipse.jface.util.SafeRunnable$1.run(SafeRunnable.java:128) at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175) at org.eclipse.jface.viewers.StructuredViewer.updateItem(StructuredViewer.java:2111) at org.eclipse.jface.viewers.AbstractTableViewer.createItem(AbstractTableViewer.java:277) at org.eclipse.jface.viewers.AbstractTableViewer.internalRefreshAll(AbstractTableViewer.java:757) at org.eclipse.jface.viewers.AbstractTableViewer.internalRefresh(AbstractTableViewer.java:649) at org.eclipse.jface.viewers.AbstractTableViewer.internalRefresh(Abstra

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 created That'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 objects Your 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.edit