I have a ViewPart that is created using a regular plugin extension point with a ratio that defines it's height. At a later point I have a block of code that is adding some more things to the Canvas for the ViewPart. The new items are not shown unless the user drags the edge of the ViewPart to make it bigger. Is there a way to programmatically tell the ViewPart to resize itself either to match it's current contents or to a value I specify?
If I recall correctly, there is no way to ask a ViewPart to resize itself. We ran into this problem before (in RCP 3.4) and I believe we had to work around it.
I think what we would up doing was adding all possible controls first, then hiding them. However, we were doing this with a wizard, so all we did was show the first page and the controls weren't incredibly dynamic. For instance, we knew the maximum number of controls and nothing was user-modifiable.
"The short answer is that you can’t always control the size and position of your view."
More at the Eclipse FAQ.
You can make it work, but only for views that are in their own view stack. See the JavaDoc for IViewPart:
As of 3.4, views may optionally adapt to ISizeProvider if they have a
preferred size. The default presentation will make a best effort to
allocate the preferred size to a view if it is the only part in a stack.
If there is more than one part in the stack, the constraints will be
disabled for that stack. The size constraints are adjusted for the size
of the tab and border trim. Note that this is considered to be a hint to
the presentation, and not all presentations may honor size constraints.
To see this in action, check out the UI test project as described here and open the view called "Layout Constraints Test".