Kris
Kris

Reputation: 5792

Eclipse RCP - how to add button to the top-right corner of an eclipse form

I cannot find anywhere how to add a button to the top-right corner of the Eclipse form, same as on the screenshot provided.

eclispe-rcp form with a button

The button seems to be a part of the form title area, is it part of the form functionality or its just another composite which looks like a form title? Any source code examples (even drafts) highly appreciated.

Edit:

I have managed to add buttons to the section but still not to the form itself, I have used an example found here:

http://svn.regilo.org/repository/regilo/trunk/org.regilo.menu/src/org/regilo/menu/editor/page/MenuPageMaster.java

private void createSectionToolbar(Section section, FormToolkit toolkit) {
    ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
    ToolBar toolbar = toolBarManager.createControl(section);
    final Cursor handCursor = new Cursor(Display.getCurrent(),
            SWT.CURSOR_HAND);
    toolbar.setCursor(handCursor);
    // Cursor needs to be explicitly disposed
    toolbar.addDisposeListener(new DisposeListener() {
        public void widgetDisposed(DisposeEvent e) {
            if ((handCursor != null) && (handCursor.isDisposed() == false)) {
                handCursor.dispose();
            }
        }
    });

    // save
    CommandContributionItemParameter saveContributionParameter = new CommandContributionItemParameter(
            editor.getSite(), null,
            "it.wellnet.easysitebox.menu.commands.saveMenu",
            CommandContributionItem.STYLE_PUSH);
    saveContributionParameter.icon = RegiloCoreImages.getInstance().DESC_UPDATE;

    CommandContributionItem saveMenu = new CommandContributionItem(
            saveContributionParameter);

    toolBarManager.add(saveMenu);

    toolBarManager.update(true);

    section.setTextClient(toolbar);
}

Still no luck with the form itself though.

Upvotes: 4

Views: 4908

Answers (2)

gamerson
gamerson

Reputation: 5310

You can get the toolbarmanager like this:

IManagedForm mform = formPage.getManagedForm();
IToolBarManager toolbar = mform.getForm().getToolBarManager();

Now you should be able to add items to the toolbar using the toolbar manager APIs as per usual.

Upvotes: 3

muzykagra
muzykagra

Reputation: 21

Try to obtain toolbar manager by using form.getToolBarManager()

Upvotes: 0

Related Questions