Bug 297054 [Contributions] extension of org.eclipse.jface.action.StatusLineContributionItem that should not "guess" contribution width
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
bundles/org.eclipse.jface/src/org/eclipse/jface/action/StatusLineContributionItem.java
* 
	 * @param text
	 *            the text to be displayed, must not be <code>null</code>
	 */
	public void setText(String text) {
		Assert.isNotNull(text);
		this.text = LegacyActionTools.escapeMnemonics(text);
		if (label != null && !label.isDisposed()) {
			label.setText(this.text);
		}
		if (this.text.length() == 0) {
			if (isVisible()) {
				setVisible(false);
				IContributionManager contributionManager = getParent();
				if (contributionManager != null) {
					contributionManager.update(true);
				}
			}
		} else {
			if (!isVisible()) {
				setVisible(true);
				IContributionManager contributionManager = getParent();
				if (contributionManager != null) {
					contributionManager.update(true);
				}
			}
		}
	}
}