I'm learning how to create an Eclipse RCP application with forms, and I'm building a simple prototype of what I need to do so. I'm using 64 bit Eclipse 3.7 and Java 1.7 on a Windows x64 platform.
What I'm trying to do is fairly standard: A view on the left of the app contains a tree (ViewTree
), and a view on the right (ViewDetail
) uses eclipse forms to present the detailed information regarding the tree selection. I set ViewTree
to be a selection provider, and ViewDetail
is set to listen to ViewTree
. I want ViewDetail
to refresh itself with every new tree selection.
Here is the relevant code for ViewTree
:
public class ViewTree extends ViewPart
{
private TreeViewer treeViewer;
public ViewTree() {
super();
}
@Override
public void createPartControl(Composite parent) {
treeViewer = new TreeViewer(parent, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
getSite().setSelectionProvider(treeViewer);
treeViewer.setLabelProvider(new TreeObjLabelProvider());
treeViewer.setContentProvider(new TreeObjContentProvider());
}
Here is the relevant code for ViewDetail
:
public class ViewDetail extends ViewPart implements ISelectionListener
{
private FormToolkit toolkit;
private ScrolledForm form;
private Composite compParent;
public ViewDetail() {}
@Override
public void createPartControl(Composite parent) {
toolkit = new FormToolkit(parent.getDisplay());
form = toolkit.createScrolledForm(parent);
compParent = parent;
// register as a selection listener with the workbench
getSite().getPage().addSelectionListener(ViewTree.ID, (ISelectionListener) this);
}
Because I want the form in ViewDetail
to erase itself and redraw with the new information for every new selection, in the selectionChanged(IWorkbenchPart part, ISelection selection)
function of ViewDetail, I call
form.dispose();
to erase it and then recreate the form using:
form = toolkit.createScrolledForm(compParent);
I then determine what type of object has been selected and build the form accordingly.
The problem is that once I select an object in the tree, my form is disposed of and the ViewDetail
goes blank. Nothing will show up in the view until the window is resized. Once the form has been built, I attempt to refresh it by calling:
form.getBody().layout();
but this does not seem to help. Any ideas as to what to try next?
I was able to get the form to redraw without resizing by calling:
compParent.layout();
So I was on the right track with the layout command, I just needed to call it on the top level - the parent Composite, instead of the form, which is a child of the parent Composite. Thanks @GGeorge for the help.