[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: re TablesViewer and new 3.3 API Snippet 24

I guess I have run into the Java problem of anonymous class cannot access parent variables (only final values) if instantiated in a method of the parent class. I have made a few attempts at work arounds etc without any success - seem to always wind up back where i started. There seems to be a bit of discussion and work on proposed java lang modifications etc to overcome the anonymous/variable problem.

However for the time being is there a work around using JFace classes to allow looping through data as per original post or must I code hard code the data set up for each column - ie the ColumnLabelProvider getText method as per the snippet.

Regrds
Peter Snowball


Southman wrote:
Hi Tom
Thanks thanks for the quick reply
will check out
Regards
Peter

Tom Schindl wrote:
Hi,

I don't think this is true. It creates an intance for every column. My guess is that your variable j is an instance var and thus in the end j will always point to the last index. Without seeing a complete snippet I can't say more.

Tom

Southman schrieb:
I am new to JFace and am trying to have reusable table class based on snippet 24 that loops through the columns and sets up column titles etc. and column data etc. as follows

for column[j]

TableViewerColumn column[j] = new TableViewerColumn(v, SWT.NONE);
    column[j].getColumn().setWidth(w[j]);
    column[j].getColumn().setText(title[j]);
    column[j].getColumn().setMoveable(movable[j]);
    column[j].setLabelProvider(new ColumnLabelProvider() {

    public String getText(Object element) {
            return ((Person) element).getData(j);
    }
});

Everything works for the column width and titles etc. however it appears as if the loop only creates one ColumnLableProvder for all the columns. Is there a way around this or must you hard code the column data as per the snippet 24.

Original code - one block per column
*************************************
TableViewerColumn column = new TableViewerColumn(v, SWT.NONE);
    column.getColumn().setWidth(200);
    column.getColumn().setText("Givenname");
    column.getColumn().setMoveable(true);
    column.setLabelProvider(new ColumnLabelProvider() {

    public String getText(Object element) {
            return ((Person) element).givenname;
    }
});
******************************************************

Thanks
Peter Snowball