[英]Open a prespective on eclipse startup - programmatically
我正在開發一個eclipse插件。 當我們第一次打開日食時,我需要打開我的預想。 有什么方法可以實現這一目標嗎? 我想一定有一些聽眾可用,但無法追蹤。
我們可以在 eclipse 開始使用PlatformUI.getWorkbench().showPrespective(<prespective id>)
類似地,有沒有辦法在 eclipse 啟動時打開預定義,以便在啟動 eclipse 時打開我們想要的預定義。
您可以在插件中使用org.eclipse.ui.startup
擴展點。 激活插件后,檢查/設置首選項以決定是否要切換視角,然后安排UIJob
執行此操作。
實現擴展點。 插件中的某些類需要implements org.eclipse.ui.IStartup
。 在這種情況下,激活器類很好。 特別是,因為您不需要earlyStartup
方法中的任何內容。
在start
方法中,做出切換和調度的決定:
public void start(BundleContext context) throws Exception { super.start(context); plugin = this; final boolean switchPerpective = processPluginUpgrading(); if (switchPerpective) { final IWorkbench workbench = PlatformUI.getWorkbench(); new UIJob("Switching perspectives"){ @Override public IStatus runInUIThread(IProgressMonitor monitor) { try { workbench.showPerspective(perspectiveId, workbench.getActiveWorkbenchWindow()); } catch (WorkbenchException e) { return new Status(IStatus.ERROR,PLUGIN_ID,"Error while switching perspectives", e); } return Status.OK_STATUS; }} .run(new NullProgressMonitor()); } }
使用首選項存儲為您的決策邏輯保留數據。 在此實現中,每當插件升級時,每個工作區都會切換一次透視圖。 偏好存儲中記錄的數據將允許未來版本具有差異策略。 它使用來自AbstractUIPlugin
的getPreferenceStore
,因此它的范圍是每個工作區。 如果您想使用其他范圍,請參閱常見問題解答。
private Boolean processPluginUpgrading() { final Version version = getDefault().getBundle().getVersion(); final IPreferenceStore preferenceStore = getDefault().getPreferenceStore(); final String preferenceName = "lastVersionActivated"; final String lastVersionActivated = preferenceStore.getString(preferenceName); final boolean upgraded = "".equals(lastVersionActivated) || (version.compareTo(new Version(lastVersionActivated)) > 0); preferenceStore.setValue(preferenceName, version.toString()); return upgraded; }
為了在插件中打開自定義透視圖,我正在做的一件事是在 eclipe 安裝文件夾中的config.ini
中對其進行配置,如下所示:
-perspective <my perspective id>
它工作正常。 我從 Lars Vogel 的教程中得到了這些信息,你可以在這里找到。 希望這可以幫助。
另一種方式:
org.eclipse.ui.IPerspectiveRegistry.setDefaultPerspective(id)
這將默認透視圖設置為給定的 id。 相同的 API 文檔。
去
D:\{MyTestSpace}\eclipse\features\myCustom.plugin.feature_3.1.0.201607220552
你可以在插件標簽下看到feature.xml
你得到 id。
在config.ini
使用此 ID,您可以在下面找到
D:\\{MyTestSpace}\\eclipse\\configuration
作為
-perspective <myCustum.plugin>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.