2009-06-10 120 views
4

我有一個ViewPart是使用普通的插件擴展點創建的,其比例定義了它的高度。在稍後的時間點,我有一段代碼將一些更多的東西添加到Canvas的ViewPart中。除非用戶拖動ViewPart的邊緣以使其更大,否則不會顯示新項目。有沒有辦法以編程方式告訴ViewPart調整自己的大小,以匹配它的當前內容或我指定的值?如何以編程方式調整eclipse ViewPart的大小?

回答

0

如果我沒有記錯,沒有辦法讓ViewPart調整自己的大小。我們之前遇到過這個問題(在RCP 3.4中),我相信我們必須解決它。

我想我們會做的是先添加所有可能的控件,然後隱藏它們。但是,我們正在使用嚮導來做這件事,所以我們所做的只是顯示第一頁,而且控件不是令人難以置信的動態。例如,我們知道控件的最大數量,沒有什麼是用戶可修改的。

1

「簡而言之,您無法始終控制視圖的大小和位置。」

更多在Eclipse FAQ

4

您可以使其工作,但僅限於處於其自己的視圖堆棧中的視圖。查看javadoc瞭解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. 

要在行動中看到這一點,檢查出的UI測試項目描述here,然後打開名爲「佈局約束測試」的觀點。

+0

這太棒了!非常感謝。這裏是如果有人感興趣的文件:https://github.com/eclipse/eclipse.platform.ui/blob/master/tests/org.eclipse.ui.tests/Eclipse%20UI%20Tests/org/eclipse/ui /tests/layout/constraints/LayoutConstraintsView.java – parasietje 2012-01-25 20:33:12