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
data.widthHint = widthHint;
		label.setLayoutData(data);
		label.setText(text);
		data = new StatusLineLayoutData();
		data.heightHint = heightHint;
		sep.setLayoutData(data);
	}
	/**
	 * An accessor for the current location of this status line contribution
	 * item -- relative to the display.
	 * 
	 * @return The current location of this status line; <code>null</code> if
	 *         not yet initialized.
	 */
	public Point getDisplayLocation() {
		if ((label != null) && (statusLine != null)) {
			return statusLine.toDisplay(label.getLocation());
		}
		return null;
	}
	/**
	 * Retrieves the text that is being displayed in the status line.
	 * 
	 * @return the text that is currently being displayed
	 */
	public String getText() {
		return text;
	}
	/**
	 * Sets the text to be displayed in the status line.