Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 362771 - It's not possible to set horizontal alignment of text with ColumnFormatter for ITableRidget
Summary: It's not possible to set horizontal alignment of text with ColumnFormatter fo...
Status: ASSIGNED
Alias: None
Product: Riena
Classification: RT
Component: ridget (show other bugs)
Version: 4.0.0   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Thorsten Schenkel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-03 05:53 EDT by Sergei Jochim CLA
Modified: 2011-11-03 11:25 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sergei Jochim CLA 2011-11-03 05:53:49 EDT
Build Identifier: 20110615-0604

It is not possible to set text alignment with the method:
getHorizontalAlignment(Object element)
in ColumnFormatter for TableRigets.

This is not a problem if TableRidget has a static number of columns, because the column formats can be set in the view. But if the columns are dynamic generated in the controller the only way to set format is with ColumnFormatters.
With the ColumnFormatter it is not possible to set the alignement for the text.


Reproducible: Always

Steps to Reproduce:
private final class MyColumnFormatter extends ColumnFormatter {
	public MyColumnFormatter() {}

	@Override
	public String getText(final Object element) {}

	@Override
	public int getHorizontalAlignment(Object element) {
	        return SWT.RIGHT; //<-- this should set the alignment
	}
}
Comment 1 Thorsten Schenkel CLA 2011-11-03 11:25:47 EDT
With SWT it is not possible to set the alignment of table items (cells). It is only possible to set the alignment of a table column. This alignment influences although the column header.
With some modifications it is possible that the TableRidget sets the alignment of a table column.
It will be although possible that the ColumnFormatter is used to define the alignment.
But the method getHorizontalAlignment(Object) was designed to return the alignment of one cell (of a MatrixTable), therefore the parameter is necessary.
If this method is used to return the alignment of a column, the parameter will be useless.

Here an implementation for the TableRidget:

	protected void applyColumnFormatters(final IColumnFormatter[] formatters) {
		final Table control = getUIControl();
		if (control == null) {
			return;
		}
		for (int i = 0; i < control.getColumnCount(); i++) {
			final TableColumn column = control.getColumn(i);
			final IColumnFormatter formatter = formatters[i];
			if (formatter != null) {
				final int alignment = formatter.getHorizontalAlignment(column.getText());
				if (alignment != SWT.DEFAULT) {
					column.setAlignment(alignment);
				}
			}
		}
	}
	
	Calls the method at the end of the method AbstractTableRidget.configureControl().
	
The Grid widget uses CellRenderer and this support alignments for single cells. Maybe with Grid the ColumnFormatter can be used correct.