Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 285581

Summary: [Toolbar] Index not considered when adding items afterwards
Product: [RT] RAP Reporter: Setya Nugdjaja <jsetya>
Component: JFaceAssignee: Project Inbox <rap-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 1.2   
Target Milestone: 1.3 M1   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
patch+testcase none

Description Setya Nugdjaja CLA 2009-08-04 09:17:06 EDT
Hi all,

When adding toolbar item at runtime it's always placed last.

Here's the snippet to reproduce the problem:

@Override
public void createPartControl(Composite parent)
{
    parent.setLayout(GridLayoutFactory.fillDefaults().create());
          toolkit = new FormToolkit(parent.getDisplay());
      toolkit.adapt(parent);
        final IToolBarManager toolbarManager = new ToolBarManager(SWT.FLAT | SWT.WRAP | SWT.HORIZONTAL);
    ToolBar toolbar = ((ToolBarManager)toolbarManager).createControl(parent);
    toolbar.setLayoutData(GridDataFactory.swtDefaults().align(SWT.END, SWT.TOP).grab(true, false).create());
    toolkit.adapt(toolbar, false, false);

    toolbarManager.add(new Separator("dynamic"));
    toolbarManager.add(new Separator("static"));

    final IAction dynamicAction = new Action("Dynamic")
    {
        @Override
        public String getId(){return "action.dynamic";}
    };
    toolbarManager.appendToGroup("dynamic", dynamicAction);

    IAction action = new Action("Add")
        {
            @Override
            public String getId(){return "action.add";}

            @Override
            public void run()
            {
                if (toolbarManager.find("action.dynamic") != null) return;

                toolbarManager.appendToGroup("dynamic", dynamicAction);
                toolbarManager.update(true);
            }
        };
        toolbarManager.appendToGroup("static", action);
           action = new Action("Remove")
        {
            @Override
            public String getId(){return "action.remove";}

            @Override
            public void run()
            {
                toolbarManager.remove("action.dynamic");
                toolbarManager.update(true);
            }
        };
        toolbarManager.appendToGroup("static", action);
               toolbarManager.update(true);
}

Using above snippets just click 'Remove' then 'Add' and you'll see that the 'Dynamic' button is always placed last.

I've tried above snippet in RCP and it worked fine.


Best Regards,

Setya
Comment 1 Benjamin Muskalla CLA 2009-08-09 16:34:48 EDT
Created attachment 143856 [details]
patch+testcase

We always add new ToolItems at the end of the toolbar without looking at the index. This works when we initially set up the toolbar but fails when adding items dynamically with an index != itemlength.

Waiting with the patch until bug 286073 is resolved.

Ralf, do you think this is worth to backport to SR121?
Comment 2 Benjamin Muskalla CLA 2009-08-11 06:13:54 EDT
This has been fixed for 1.3 M1 in CVS HEAD.

If we really backport this to SR121 we should also think about backporting bug 286179