【问题标题】:Positioning Toolbars in Eclipse/RCP在 Eclipse/RCP 中定位工具栏
【发布时间】:2011-01-21 13:57:37
【问题描述】:

我正在开发我的小型 RCP 应用程序,它需要一个自定义透视切换器来控制用户可以访问哪些视图。所以我在这里,尝试添加一个带有几个按钮的工具栏来切换视角。

我认为对这些东西进行一些控制的最佳方法是在 ApplicationActionBarAdvisor 中添加第二个工具栏,它会调用我的动作/命令来切换视角。

假设我在 fillCoolBar 方法中创建了第二个 ToolBarContributionItem,如下所示:

protected void fillCoolBar(ICoolBarManager coolBar) {
    IToolBarManager toolbar = new ToolBarManager(SWT.FLAT | SWT.RIGHT);
    ToolBarContributionItem mainBar = new ToolBarContributionItem(toolbar, "main");
    coolBar.add(mainBar);

    toolbar.add(openViewAction);
    toolbar.add(newConnectionAction);

    //Custom perspective switcher bar
    IToolBarManager perspectives = new ToolBarManager(SWT.FLAT | SWT.RIGHT);
    ToolBarContributionItem perspectiveBar = new ToolBarContributionItem(perspectives, "perspectives");
    coolBar.add(perspectiveBar);        
}

任何想法如何对齐工具栏,使其位于窗口的右侧?我很想硬编码这个职位。

问候, 迈克尔

【问题讨论】:

    标签: java eclipse eclipse-plugin swt eclipse-rcp


    【解决方案1】:

    我有一个类似的问题:我想在左侧有一个标准工具栏,在左侧有一个搜索文本和按钮。我发现并不是真正的解决方案。我所做的是覆盖 ToolBarContributionItem 中的填充方法,以便更改 CoolBarManager 的布局。这不是一个好的解决方案,它适用于 Windows(在这种情况下就足够了),但不适用于 Linux,但它可能会有所帮助:

    protected void fillCoolBar(ICoolBarManager coolBar) {
        coolBar.setLockLayout(true);
    
        IToolBarManager mainToolBar = new ToolBarManager(SWT.FLAT | SWT.RIGHT);
        coolBar.add(new ToolBarContributionItem(mainToolBar, "main"));      
        fillMainToolBar(mainToolBar);
    
        IToolBarManager searchToolBar = new ToolBarManager(SWT.FLAT | SWT.RIGHT);
        ToolBarContributionItem searchBarItem = new ToolBarContributionItem(
                searchToolBar, "search") {
            @Override
            public void fill(CoolBar coolBar, int index) {
                super.fill(coolBar, index);
                // change the layout of the cool-bar to have the search
                // controls on the right side
                GridLayout coolBarLayout = new GridLayout(2, false);
                coolBarLayout.marginHeight = 0;
                coolBarLayout.marginWidth = 0;
                coolBarLayout.horizontalSpacing = 20;
                coolBarLayout.verticalSpacing = 0;
                coolBarLayout.marginLeft = 10;
                coolBar.setLayout(coolBarLayout);
                GridData mainGridData = new GridData(SWT.LEFT, SWT.CENTER, true,
                        false);
                GridData searchGridData = new GridData(SWT.RIGHT, SWT.CENTER,
                        false, false);
                coolBar.getItem(0).getControl().setLayoutData(mainGridData);
                coolBar.getItem(1).getControl().setLayoutData(searchGridData);
            }
        };
        coolBar.add(searchBarItem);
        searchToolBar.add(new SearchTextControl());
        searchToolBar.add(searchAction);
    }
    

    【讨论】:

    • 你能解释一下为什么它不能在 Linux 上运行吗?我在这里看不到任何依赖于平台的魔法。 (我不使用linux,我只是好奇。:))
    【解决方案2】:

    你们为什么要为此编写代码?您可以将 menuContributions 扩展点与装饰条的 locationURI 一起使用。 locationURI 在 MenuUtil 类中可用

    【讨论】:

    • 你是对的。但是没有可能使用 locationURI 来定义菜单贡献是右对齐的,对吧?
    猜你喜欢
    • 1970-01-01
    • 2013-11-04
    • 1970-01-01
    • 2014-11-23
    • 2010-09-14
    • 2013-09-29
    • 2012-12-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多