[英]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.