How to programmatically resize a viewpart eclipse?

I have a ViewPart that is created using a regular plugin extension point with a relation that determines its height. At a later point, I have a block of code that adds a few more things to Canvas for ViewPart. New items are not displayed unless the user dragged the edge of the ViewPart to make it larger. Is there a way to programmatically tell ViewPart to resize itself to fit the current content or value that I specify?

+4
source share
3 answers

You can make it work, but only for views that are in their own view stack. See 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 the user interface testing project as described here and open a view called Layout Constraint Test.

+4
source

"The short answer is that you cannot always control the size and position of your view."

Read more at Eclipse Frequently Asked Questions .

+1
source

If I remember correctly, there is no way to ask ViewPart to resize itself. Previously, we encountered this problem (in RCP 3.4), and I believe that we had to get around it.

I think that we should first add all the possible controls and then hide them. However, we did this using the wizard, so all we did was show the first page, and the controls were not incredibly dynamic. For example, we knew the maximum number of controls, and nothing was modified by the user.

0
source

Source: https://habr.com/ru/post/1286032/


All Articles