Community
Participate
Working Groups
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 } }
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.