Eclipse RCP Toolbar buttons with the Eclipse Look
Asked Answered
W

2

1

In Eclipse, its easy to specify buttons for your toolbar using the ActionSets extension point. However, when I need to specify some items programmatically, I can't get the same look. I don't believe that the framework is using native buttons for these, but so far, I can't find the right recipe to match the Eclipse look. I wanted to see if anyone has found the right snippet to duplicate this functionality in code.

Wahoo answered 1/10, 2008 at 19:5 Comment(1)
What code are you using to add the buttons programmatically?Nahum
S
6

It's difficult to tell from your question, but it sounds like you may be attempting to add a ControlContribution to the toolbar and returning a Button. This would make the button on the toolbar appear like a native button like you seem to be describing. This would look something like this:

IToolBarManager toolBarManager = actionBars.getToolBarManager();
toolBarManager.add(new ControlContribution("Toggle Chart") {
    @Override
    protected Control createControl(Composite parent)
    {
        Button button = new Button(parent, SWT.PUSH);
        button.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
                // Perform action
            }
        });
     }
});

Instead you should add an Action to the toolbar. This will create a button on the toolbar that matches the standard eclipse toolbar buttons. This would look something like this:

Action myAction = new Action("", imageDesc) {
    @Override
    public void run() {
        // Perform action
    }
};

IToolBarManager toolBarManager = actionBars.getToolBarManager();
toolBarManager.add(myAction);
Suppression answered 13/1, 2009 at 14:43 Comment(0)
D
2

Could you perhaps put in an extract of the code you have for adding actions programmatically to the toolbar? I assume you do this in an ApplicationActionBarAdvisor class? Their should be no difference in the look of buttons you add declaratively vs those you add programatically.

Dysphasia answered 17/10, 2008 at 12:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.