|
|
Re: jface table viewer (columns and content) [message #439113 is a reply to message #438921] |
Tue, 06 July 2004 05:09 |
Eclipse User |
|
|
|
Originally posted by: john.rmts.donpac.ru
> Columns must be added to the undelying table instance; contents
> is provided using ContentProvider and LabelProviders
IMHO, it's jface design lack.
I wrote simple classes corecting this:
public class ExtendedTableViewer extends TableViewer {
private ITableColumnProvider provider;
public ExtendedTableViewer(Composite arg0) {
super(arg0);
}
public ExtendedTableViewer(Composite arg0, int arg1) {
super(arg0, arg1);
}
public ExtendedTableViewer(Table arg0) {
super(arg0);
}
public void setColumnProvider(ITableColumnProvider provider) {
this.provider = provider;
}
protected void internalRefresh(Object element) {
if (provider != null)
columnsFill();
super.internalRefresh(element);
pack();
}
protected void inputChanged(Object newInput, Object oldInput) {
if (newInput != null && provider != null)
provider.inputChanged(this, oldInput, newInput);
super.inputChanged(newInput, oldInput);
pack();
}
protected void columnsFill(){
String columns[] = provider.getColumns();
if (columns != null) {
int count = getTable().getColumnCount();
for (int i=0;i<count;i++)
getTable().getColumn(0).dispose();
for (int i=0;i<columns.length;i++) {
final TableColumn tableColumn = new TableColumn(getTable(), SWT.NONE);
tableColumn.setText(columns[i]);
}
setColumnProperties(columns);
}
}
public void pack() {
for (int i=0;i<getTable().getColumnCount();i++)
getTable().getColumn(i).pack();
}
}
public interface ITableColumnProvider {
public String[] getColumns() ;
public void inputChanged(Viewer viewer, Object oldInput, Object newInput);
}
|
|
|
Powered by
FUDForum. Page generated in 0.02767 seconds