1 comments Wednesday, September 10, 2008

The following technique can be used to get the currently active page and any view within that page.



IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewPart view = page.findView(MyView.ID);


The MyView.ID specified the ID of the view as declared in the plugin.xml file.



0 comments

If you want to add a custom dialog to a JFace application the easiest way is to override the JFace Dialog class as follows:

public class MyDialog extends Dialog {
/**
* @param parentShell
*/
public MyDialog(Shell parentShell) {
super(parentShell);

//forces open method to block until window is closed.
setBlockOnOpen(true);

}

@Override
protected void createButtonsForButtonBar(Composite parent) {
createButton(parent, IDialogConstants.OK_ID,
IDialogConstants.OK_LABEL, true);
createButton(parent, IDialogConstants.CANCEL_ID,
IDialogConstants.CANCEL_LABEL, false);

}


@Override
protected Control createDialogArea(Composite parent) {

Composite container = (Composite) super.createDialogArea(parent);

Label nameLabel = new Label(container,SWT.NONE);
nameLabel.setText("Name:");
Text nameText = new Text(container, SWT.BORDER);

return container;

}
}
The way you call it within any Action is as follows:
MyDialog d = new MyDialog(Display.getCurrent().getActiveShell());
int status = d.open();
For this example the open method will return OK or CANCEL. It is user-definable by overriding the getReturnCode() method on Dialog.

Make the Dialog resizable
By default it isnt, You must call this in the Dialog constructor:
Dialog.setShellStyle(SWT.RESIZE)

Change the Dialog title
You need to override the Window.configureShell method as follows

protected void configureShell(Shell newShell) {
super.configureShell(newShell);
newShell.setText("My Dialog Title");
}

0 comments

When I started working on a new project at work, I had to decide on the UI platform I wanted to develop in. We have considerable Java experience in-house and hence we were limited to something on the Java platform. I have considerable experience designing in Swing, but I was really smitten by the Eclipse IDE UI. After researching other options that were available, Eclipse RCP seemed to be the most robust, with a well developed code-base, community support and online resources. However as I have started to work with Eclipse RCP, I realized that versions changed quite often and the literature wasnt keeping up. Good online resources that really go in-depth and teach complex tasks were very scarce. The best way to learn how to do stuff was to look at the Eclipse IDE codebase.


I started this blog as a place to document RCP/JFace/SWT tips and tricks that I learnt the hard way.