Eclipse RCP 開發中頻繁用到的四個核心操作,整理為即用速查表,涵蓋應用重啟、透視圖查找、Shell 獲取與幫助顯示。
PlatformUI.getWorkbench().restart();
適用於安裝更新、配置變更需重載場景。
IPerspectiveDescriptor ipd = PlatformUI.getWorkbench()
.getPerspectiveRegistry()
.findPerspectiveWithId(FavoritePerspective.ID);
FavoritePerspective.ID 對應 plugin.xml 中 extension point="org.eclipse.ui.perspectives" 定義的 id。同理可查找 View、Editor 等擴展點資源。
Shell shell = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow()
.getShell();
Shell 是對話框、彈出視窗的父容器,常用於 MessageDialog、FileDialog 等。
PlatformUI.getWorkbench().getHelpSystem().displayHelp();
啟動 Eclipse Help 系統,可配合 displayHelpResource("context_id") 定位特定幫助頁。
getActiveWorkbenchWindow() != nullplugin.xml 配置 org.eclipse.help.toc 擴展點掌握這四個 API,覆蓋 80% 的 RCP 基礎控制需求。