以编程方式打开eclipse启动的透视图

时间:2013-06-01 15:04:04

标签: java eclipse plugins eclipse-plugin

我正在开发一个eclipse插件。我们在第一次打开日食时需要打开我的视线。有没有办法实现这个目标?我猜一些听众必须可用,但无法追查。

我们可以使用PlatformUI.getWorkbench().showPrespective(<prespective id>)

在日食开始之后开启

同样有一种方法可以在eclipse启动时打开预期,以便在开始日食时打开我们想要的预期。

提前致谢。

3 个答案:

答案 0 :(得分:3)

您可以在插件中使用org.eclipse.ui.startup扩展点。激活插件后,检查/设置首选项以决定是否要切换透视图,然后安排UIJob执行此操作。

  1. 实施扩展点。插件中的某些类需要implements org.eclipse.ui.IStartup。在这种情况下,激活类很好。特别是,因为earlyStartup方法中不需要任何内容​​。

  2. 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());
        }
    }
    
  3. 使用首选项存储来保留决策逻辑的数据。在此实现中,每当升级插件时,每个工作区都会切换一次透视图。首选项存储中记录的数据将允许将来的版本具有差异策略。它使用getPreferenceStore中的AbstractUIPlugin,因此它是每个工作区的范围。如果您想使用其他范围,请参阅FAQ

    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;
    }
    

答案 1 :(得分:1)

我在插件中打开自定义透视图的一件事是在eclipe的安装文件夹中的config.ini中进行配置,如下所示:

-perspective <my perspective id>

它工作正常。我从Lars Vogel的教程中获得了这些信息,您可以找到here。希望这可以帮助。

其他方式:

org.eclipse.ui.IPerspectiveRegistry.setDefaultPerspective(id)这会将默认透视设置为给定的ID。 API Docs for the same.

答案 2 :(得分:0)

转到

D:\{MyTestSpace}\eclipse\features\myCustom.plugin.feature_3.1.0.201607220552

您可以在插件标记下看到feature.xml,但您获得了ID。

config.ini中使用此ID,您可以在

下找到该ID

D:\{MyTestSpace}\eclipse\configuration

作为

-perspective <myCustum.plugin>
相关问题