Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-swt-dev] Problems with TableViewer VIRTUAL on MAC

Hello,
I have a problem with TableViewer VIRTUAL on MAC. When I have more than
1751 lines in my table the setSelection method don't work correctly only
on MAC. In particular, the setSelection method select the correct item
in the table but dont show it. Is there an open bug?

I attach a simple snippet code to verify problem.

Thanks for your attention.
package it;

import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;

public class TableViewerTestMAC extends ApplicationWindow {

    private Table table;
    private TableViewer tableViewer;
    static String[] input = new String[1752];

    /**
     * Create the application window
     */
    public TableViewerTestMAC() {
	super(null);
    }

    /**
     * Create contents of the application window
     * @param parent
     */
    @Override
    protected Control createContents(Composite parent) {
	Composite container = new Composite(parent, SWT.NONE);
	container.setLayout(new GridLayout());
	//
	tableViewer = new TableViewer(container, SWT.VIRTUAL);
	table = tableViewer.getTable();
	table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
	tableViewer.setContentProvider(new IStructuredContentProvider(){

	    public Object[] getElements(Object inputElement) {
		// TODO Auto-generated method stub
		return (String[])inputElement;
	    }

	    public void dispose() {
		// TODO Auto-generated method stub
		
	    }

	    public void inputChanged(Viewer viewer, Object oldInput,
		    Object newInput) {
		// TODO Auto-generated method stub
		
	    }
	    
	});
	tableViewer.setLabelProvider(new TableLabelProviderTest());
	tableViewer.setInput(input);

	final Button button = new Button(container, SWT.NONE);
	button.setText("button");
	button.addSelectionListener(new SelectionAdapter(){

	    /* (non-Javadoc)
	     * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
	     */
	    @Override
	    public void widgetSelected(SelectionEvent e) {
		//
		super.widgetSelected(e);
		
		//Run
		//tableViewer.setSelection(new StructuredSelection(input[input.length-2]));
		//Not Run
		tableViewer.setSelection(new StructuredSelection(input[input.length-1]));
	    }
	    
	});
	return container;
    }

    /**
     * Launch the application
     * @param args
     */
    public static void main(String args[]) {
	try {
	    for (int i = 0; i < input.length; i++) {
		input[i] = new String(Integer.toString(i));
	    }
	    TableViewerTestMAC window = new TableViewerTestMAC();
	    window.setBlockOnOpen(true);
	    window.open();
	    Display.getCurrent().dispose();
	} catch (Exception e) {
	    e.printStackTrace();
	}
    }

    /**
     * Configure the shell
     * @param newShell
     */
    @Override
    protected void configureShell(Shell newShell) {
	super.configureShell(newShell);
	newShell.setText("New Application");
    }

    /**
     * Return the initial size of the window
     */
    @Override
    protected Point getInitialSize() {
	return new Point(800, 600);
    }

    class TableLabelProviderTest extends ColumnLabelProvider implements
	ITableLabelProvider{

	public Image getColumnImage(Object element, int columnIndex) {
	    // TODO Auto-generated method stub
	    return null;
	}

	public String getColumnText(Object element, int columnIndex) {
	    //
	    return (String)element;
	}
	
    }
}

Back to the top