如何以编程方式调整日食ViewPart的大小?

时间:2022-08-26 00:02:33

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?

我有一个ViewPart,使用常规插件扩展点创建,其比例定义了它的高度。稍后我会有一段代码,它会为ViewPart的Canvas添加更多内容。除非用户拖动ViewPart的边缘以使其更大,否则不会显示新项目。有没有办法以编程方式告诉ViewPart调整自身大小以匹配它的当前内容或我指定的值?

3 个解决方案

#1


You can make it work, but only for views that are in their own view stack. See the JavaDoc for IViewPart:

您可以使它工作,但仅适用于自己视图堆栈中的视图。请参阅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".

要查看此操作,请查看此处所述的UI测试项目,并打开名为“布局约束测试”的视图。

#2


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

“简短的回答是,你不能总是控制视图的大小和位置。”

More at the Eclipse FAQ.

更多Eclipse Eclipse常见问题解答。

#3


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.

如果我没记错的话,就没有办法让ViewPart调整自己的大小。我们之前遇到过这个问题(在RCP 3.4中),我相信我们必须解决它。

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.

我认为我们要做的是首先添加所有可能的控件,然后隐藏它们。但是,我们使用向导执行此操作,因此我们所做的只是显示第一页,控件不是非常动态。例如,我们知道控件的最大数量,并且没有任何东西是用户可修改的。

#1


You can make it work, but only for views that are in their own view stack. See the JavaDoc for IViewPart:

您可以使它工作,但仅适用于自己视图堆栈中的视图。请参阅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".

要查看此操作,请查看此处所述的UI测试项目,并打开名为“布局约束测试”的视图。

#2


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

“简短的回答是,你不能总是控制视图的大小和位置。”

More at the Eclipse FAQ.

更多Eclipse Eclipse常见问题解答。

#3


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.

如果我没记错的话,就没有办法让ViewPart调整自己的大小。我们之前遇到过这个问题(在RCP 3.4中),我相信我们必须解决它。

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.

我认为我们要做的是首先添加所有可能的控件,然后隐藏它们。但是,我们使用向导执行此操作,因此我们所做的只是显示第一页,控件不是非常动态。例如,我们知道控件的最大数量,并且没有任何东西是用户可修改的。