Project: Eclipse_Platform_UI
Bug 297054 [Contributions] extension of org.eclipse.jface.action.StatusLineContributionItem that should not "guess" contribution width
Reported: 2009-12-07 05:37:28 | Status: verified fixed

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729) Build Identifier: 20090920-1017 Current implementation of org.eclipse.jface.action.StatusLineContributionItem uses a DEFAULT_CHAR_WIDTH to "guess" the needed size (which will fail e.g. if many uppercase letters are used). Also, the size is fix once the instance is created. A much better and more dynamic implementation, however, would be a Contribution item that calculates its needed size based on the actual text contained (thus, grabbing exactly the size it needs for the text). This can be easily achieved by creating a new Contribution Item class that differs from StatusLineContributionItem in just the fill method. Below is a suggestion for the new method: public void fill(Composite parent) { statusLine = parent; Label sep = new Label(parent, SWT.SEPARATOR); label = new CLabel(statusLine, SWT.SHADOW_NONE); label.setText(text); // compute the size of the label to get the width hint for the contribution int widthHint = label.computeSize(SWT.DEFAULT, SWT.DEFAULT).x; StatusLineLayoutData data = new StatusLineLayoutData(); data.widthHint = widthHint; label.setLayoutData(data); data = new StatusLineLayoutData(); data.heightHint = heightHint; sep.setLayoutData(data); } Reproducible: Always

Files changed in fix:
bundles/org.eclipse.jface/src/org/eclipse/jface/action/StatusLineContributionItem.java