在Eclipse / RCP中定位工具栏 [英] Positioning Toolbars in Eclipse/RCP

查看:145
本文介绍了在Eclipse / RCP中定位工具栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I was working on my tiny RCP app, which needs a custom perspective switcher to control which views the user can access. So here I am, trying to add a toolbar with a couple of buttons to switch perspectives.

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

I figured the best way to have some control over the stuff would be to add a second toolbar in ApplicationActionBarAdvisor which would call my thee actions/commands to switch perspectives.

所以让我们在fillCoolBar方法中创建一个第二个ToolBarContributionItem,它将如下所示:

So let's say I create a second ToolBarContributionItem in the fillCoolBar method, which would look like this:

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

任何想法我如何对齐工具栏,以便它在右侧的窗口?我很想让这个位置变硬。

Any ideas how I can align the Toolbar so it would be on the right side of the window? I'd love to have this position hardcoded.

问候,
Michael

Regards, Michael

推荐答案

我有一个类似的问题:我想在左边有一个标准工具栏,左侧有一个搜索文本和按钮。我发现没有真正的解决方案。我所做的是在ToolBarContributionItem中覆盖fill-method,以便更改CoolBarManager的布局。这不是一个很好的解决方案,它适用于Windows(这在本例中足够),但不适用于Linux,但可能有助于:

I had a similar problem: I wanted to have a standard toolbar on the left side and a search text and button on the left. I found not really a solution. What I have done is that I override the fill-method in ToolBarContributionItem so that the layout of the CoolBarManager is changed. This is not a good solution, it works on Windows (which was enough in this case), but NOT on Linux, but it maybe helps:

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

这篇关于在Eclipse / RCP中定位工具栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆