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.
Useful Eclipse RCP code snippets that I could not find anywhere else on the Internet
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewPart view = page.findView(MyView.ID);
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 {The way you call it within any Action is as follows:
/**
* @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;
}
}
MyDialog d = new MyDialog(Display.getCurrent().getActiveShell());For this example the open method will return OK or CANCEL. It is user-definable by overriding the getReturnCode() method on Dialog.
int status = d.open();
Dialog.setShellStyle(SWT.RESIZE)
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
newShell.setText("My Dialog Title");
}
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.
Copyright 2009 | Girish Chavan