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

时间:2009-06-10 18:57:51

标签: eclipse eclipse-rcp

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

3 个答案:

答案 0 :(得分:4)

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

要查看此操作,请按照here所述检查UI测试项目,然后打开名为“布局约束测试”的视图。

答案 1 :(得分:1)

“简短的回答是,您无法始终控制视图的大小和位置。”

更多Eclipse FAQ

答案 2 :(得分:0)

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

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