Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Can not set ContributionItem size for dynamic toolbar contributions
Can not set ContributionItem size for dynamic toolbar contributions [message #518136] Wed, 03 March 2010 03:50 Go to next message
ali Mising name is currently offline ali Mising name
Messages: 38
Registered: July 2009
Member
Hello community,

I need to find a way to create ContributionItem that are wider than the default square size.

I've created a number of custom classes that extend ContributionItem and are contributed to my RCP Workbench as dynamic toolbar items using the org.eclipse.ui.menu extension point.

Everything was working well for my square buttons... but I also have a requirement to create wider items.

Unfortunately my wider contributions are also being displayed as small, square items that are the same size of a typical 16 x 16 button icon. I've unsuccessfully tried specifying different ToolBar layouts and manually setting the size of the ToolBar and it's ToolItem Control, but the items remain square Mad !

Does anyone know why this is happening and how I can fix it?

Here is a simple version of my "wide" contribution item...

package abc;

import org.eclipse.jface.action.ContributionItem;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;

public class WideContributionItem extends ContributionItem {

  @Override
  public void fill(ToolBar toolBar, int index) {
    
    toolBar.setLayout(new FormLayout());
    
    Text wideText = new Text(toolBar, SWT.BORDER);
    wideText.setText("This is a wide message");
    wideText.setBounds(0, 0, 150, 60);
    
    ToolItem wideToolItem = new ToolItem(toolBar, SWT.PUSH, index);
    wideToolItem.setControl(wideText);
    
    wideToolItem.setWidth(160);
    toolBar.setSize(200, 70);
    toolBar.layout(true, true);
  }
}

...and here is the extension points that contribute it to my RCP Workbench:

<extension point="org.eclipse.ui.menus">
  <menuContribution locationURI="toolbar:org.eclipse.ui.trim.status">
    <toolbar id="mytoolbarid">
      <dynamic class="abc.WideContributionItem" id="abcd"/>
    </toolbar>
  </menuContribution>
</extension>

Can anyone help me find a solution to my problem?
Re: Can not set ContributionItem size for dynamic toolbar contributions [message #518358 is a reply to message #518136] Wed, 03 March 2010 16:12 Go to previous message
ali Mising name is currently offline ali Mising name
Messages: 38
Registered: July 2009
Member
I just found the fix! Adding the following code to the end of the fill method allows wider / taller ContributionItems to be displayed correctly:

ToolBarManager toolBarManager = new ToolBarManager(toolBar);
toolBarManager.update(true);
Previous Topic:Adding new commands and toolbar contributions programmatically
Next Topic:[Databinding] Validate that item only appears once in IObservableList
Goto Forum:
  


Current Time: Fri Apr 18 19:26:47 EDT 2014

Powered by FUDForum. Page generated in 0.02565 seconds