Toolbar Positioning in Eclipse / RCP

I was working on my tiny RCP application that needs a custom perspective switch to control which views users can get. So here I am, trying to add a toolbar with a few buttons to switch perspectives.

I decided that the best way to have some control over the material is to add a second toolbar to the ApplicationActionBarAdvisor that will trigger my actions / commands to switch perspectives.

So, let's say I create a second ToolBarContributionItem in the fillCoolBar method, which will 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 that it is on the right side of the window? I would like this position to be hard-coded.

,

+5
2

: . . , , fill 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);
}
+4

, , ? menuContributions URI . locationURI MenuUtil

+4

All Articles