Community
Participate
Working Groups
I have added bunch of Action items into the ToolBarManager. After each addition, I call an update, which is kind of required for the design, I currently have. Here are my observations: 1. If I do not call pack(), only one button shows up. 2. If I only use the LAST update, then all button shows up, no matter, whether I use size(), pack(), or leave both those out. Please find below the SWT code snippet to reproduce the problem. I am using 3.2M3 Build Id: I20051102-1600 <code> import org.eclipse.jface.action.Action; import org.eclipse.jface.action.ToolBarManager; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.ToolBar; public class SampleUI { public static void main( String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout( new GridLayout(1, false)); //Create Images Image blueImage = new Image ( Display.getCurrent(), 20, 20); Color color = Display.getCurrent().getSystemColor (SWT.COLOR_BLUE); GC gc = new GC ( blueImage); gc.setBackground (color); gc.fillRectangle ( blueImage.getBounds ()); gc.dispose(); Image greenImage = new Image ( Display.getCurrent(), 20, 20); color = Display.getCurrent().getSystemColor (SWT.COLOR_GREEN); gc = new GC ( greenImage); gc.setBackground (color); gc.fillRectangle ( greenImage.getBounds ()); gc.dispose(); Image redImage = new Image ( Display.getCurrent(), 20, 20); color = Display.getCurrent().getSystemColor (SWT.COLOR_RED); gc = new GC ( redImage); gc.setBackground (color); gc.fillRectangle ( redImage.getBounds ()); gc.dispose(); ToolBarManager toolBarManager = new ToolBarManager( new ToolBar( shell, SWT.FLAT)); toolBarManager.add( new TestAction( blueImage)); toolBarManager.update( true); toolBarManager.add( new TestAction( greenImage)); toolBarManager.update( true); toolBarManager.add( new TestAction( redImage)); toolBarManager.update( true); //Only leaving this one, eliminates the problem shell.setSize( 200, 200); //Setting the SIZE shows only 1 button //shell.pack(); //Calling PACK, shows all buttons shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } } class TestAction extends Action { public TestAction( Image image) { setImageDescriptor( ImageDescriptor.createFromImage( image)); } public void run() { System.out.println( "Key Pressed"); } } </code>
Created attachment 32748 [details] Snap-shot showing the problem along with the code snippet
If the size of the tool bar is too small, then it won't show all the buttons. Is ToolBarManager setting the size?
Well, the size is much bigger than required. I tried setting different sizes. In the attachment you would see that there is enough room, for the buttons to display. I am not setting any size on the ToolbarManager. I was setting the size on the Shell. Infact, while using this in a Plug-in environment, I do not set any size. And as mentioned, everything works out okay, when there is just ONE update, and not updates after every toolBarManager.add(...) The given code snippet should reproduce the problem.
Moving Dougs bugs
Assigning to component owner PW
Created attachment 77246 [details] Patch to correct the relayout strategy of the ToolBarManager. As can be seen, the current code only calls layout() on the parent control if the item count went from 0 to N or from N to 0. Thus, if it was N to N + 1 (in the given scenario), nothing would happen (shocking!). This new call ensures that layout() is "always" called assuming that neither of them is zero. This is because if you were to swap two contribution items' positions, the size would still be the same but their positions are not so they would have to be re-laid-out. Paul, I am a little concerned about this fix though as I am not sure if it still abides to the API contract of "The default implementation of this framework method re-lays out the parent when the number of items crosses the zero threshold.". I guess you can kind of make the argument that the number of items are non-zero or went from N to 0, it has crossed the zero threshold, per se.
Released to HEAD >20070913 With a slight mod: if ((oldCount != newCount) && (newCount!=0)) { PW
In I20070918-0010 PW