在我的RCP應用程序,我在左側有一個TreeViewer
用於查看導航和我在右側視圖的文件夾。透視看起來像這樣:傳遞參數給視圖
public void createInitialLayout(IPageLayout layout) {
layout.setEditorAreaVisible(false);
layout.setFixed(false);
layout.addStandaloneView(NavigationView.ID, false, IPageLayout.LEFT, 0.7f, layout.getEditorArea());
right = layout.createFolder("right", IPageLayout.RIGHT, 0.3f, "com.my.app.views.browser.navigation");
layout.getViewLayout(WallpaperView.Id).setCloseable(false);//dummy view to keep the folder from closing
layout.getViewLayout(WallpaperView.Id).setMoveable(false);
right.addView(WallpaperView.Id);
//add some placeholders for the potential views
right.addPlaceholder(DefaultAdminView.ID+":*");
}
我想根據用戶在導航樹中選擇的內容打開不同的視圖。認爲這不會很難。我的導航樹視圖:
tree = new TreeViewer(composite);
tree.setContentProvider(new BrowserNavigationTreeContentProvider());
tree.setLabelProvider(new BrowserNavigationTreeLabelProvider());
tree.setInput(UserProfileAdvisor.getProject());
//register Mouselistener for doubleclick events
tree.addDoubleClickListener(new IDoubleClickListener(){
@Override
public void doubleClick(DoubleClickEvent event) {
TreeSelection ts = (TreeSelection) event.getSelection();
Object selectedItem = ts.getFirstElement();
String viewId = DefaultAdminView.ID;
//set viewId depending on the selectedItem.class
try {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(viewId, String.valueOf(++viewCounter), IWorkbenchPage.VIEW_ACTIVATE);
} catch (PartInitException e) {
ILogHelper.error("The view for the selected object could not be opened", e);
}
}
});
這似乎工作正常。這裏有一個小小的問題: 我需要傳遞的對象(比方說將selectedItem),以我的觀點在某種程度上,爲了讓用戶使用其內容的互動。我怎麼做?
我已經看到了一些例子,其中一些同事寫了自己的視圖,他們放置在右側。然後,他們增加了一個CTabFolder
,實例化的意見和手動添加他們。有更聰明的解決方案嗎?
好老訪問者模式! – 2011-02-15 14:57:24
這正是我期待的!但是,如何將IViewPart實例轉換爲接口? – yat0 2014-12-29 16:48:21