[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: TableEditor Question/Proglem

Okay attached is a small example that has a table with two buttons. One button clears and adds data, the other clears. There are two columns one standard text one StyledText. Pressing the clear button should clear the table and does underneath. Following a clear click the horizontal scroll bar to redraw.

I even have a table.redraw() in both places to try and force it...

Thanks for your help.



Steve Northover wrote:
Part 1:  Wow.  Need a small stand alone snippet that shows then problem.
Just setting the data into the items should redraw it.
Part 2:  The selection of the parent table cannot overwrite a child in the
table.

"Michael Kilgore" <mfkilgore@xxxxxxxxx> wrote in message
news:csqt12$inv$1@xxxxxxxxxxxxxxxxxx


I am using StyledText in a TableEditor to display a column of text that has "fancy" formats in it. Everything works exactly as I expect until I need to refdraw the table (clear the old data, draw new). The table is redrawn by I do not see the the changes, they are in fact there, until I hit the scrollbar (any direction) on the table itself. This causes the current data to be displayed.

To redraw I am doing the following (tried various combinations):
 tableResult.clearAll();
 tableResult.removeAll();

 // load new data for display

 tableResult.redraw();



My second question relates to selection bar.  This is probably the way
it works, given my limited understanding of TableEditor...  I have
selected to have the selection bar extend across the table.  It does not
extend across my StyledText which happens to be the largest column.  The
result looks a bit odd to the user.

I am on Windows, Eclipse 3.1M4

Thanks in advance.




import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.custom.TableEditor;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;

/*
 * Created on Jan 21, 2005
 * 
 * TODO To change the template for this generated file go to Window - Preferences - Java - Code
 * Style - Code Templates
 */

/**
 * @author mfkilgore
 * 
 * TODO To change the template for this generated type comment go to Window - Preferences - Java -
 * Code Style - Code Templates
 */
public class TestTableDraw
{

    private Table table;

    protected Shell shell;

    public static void main(String[] args)
    {
        try
        {
            TestTableDraw window = new TestTableDraw();
            window.open();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    public void open()
    {
        final Display display = Display.getDefault();
        createContents();
        shell.layout();
        shell.open();
        while (!shell.isDisposed())
        {
            if (!display.readAndDispatch())
                display.sleep();
        }
    }

    protected void createContents()
    {
        shell = new Shell();
        shell.setLayout(new FormLayout());
        shell.setSize(835, 686);
        shell.setText("SWT Application");

        table = new Table(shell, SWT.BORDER);
        final FormData formData = new FormData();
        formData.bottom = new FormAttachment(0, 565);
        formData.right = new FormAttachment(0, 795);
        formData.top = new FormAttachment(0, 50);
        formData.left = new FormAttachment(0, 15);
        table.setLayoutData(formData);
        table.setLinesVisible(true);
        table.setHeaderVisible(true);

        final TableColumn tableColumn = new TableColumn(table, SWT.NONE);
        tableColumn.setWidth(100);
        tableColumn.setText("New column");

        final TableColumn tableColumn_1 = new TableColumn(table, SWT.NONE);
        tableColumn_1.setWidth(520);
        tableColumn_1.setText("New column");

        final TableColumn tableColumn_2 = new TableColumn(table, SWT.NONE);
        tableColumn_2.setWidth(179);
        tableColumn_2.setText("New column");

        final Button buttonNew = new Button(shell, SWT.NONE);
        buttonNew.addSelectionListener(new SelectionAdapter()
        {
            public void widgetSelected(SelectionEvent e)
            {
                table.removeAll();
                table.clearAll();
                table.redraw();

                for (int i = 0; i < 20; ++i)
                {
                    StyledText widget = new StyledText(table, SWT.NONE);
                    widget.setText("This is a line of the table it is some number of characters long - " + i);

                    StyleRange styleRange = new StyleRange();
                    styleRange.start = 0 + i;
                    styleRange.length = 5;
                    styleRange.fontStyle = SWT.BOLD;
                    widget.setStyleRange(styleRange);

                    TableItem item = new TableItem(table, SWT.NONE);
                    item.setText(0, "fixed");

                    TableEditor editor = new TableEditor(table);
                    editor.grabHorizontal = true;
                    editor.grabVertical = true;
                    editor.setEditor(widget, item, 1);
                }

            }
        });
        final FormData formData_1 = new FormData();
        formData_1.bottom = new FormAttachment(0, 625);
        formData_1.right = new FormAttachment(0, 190);
        formData_1.top = new FormAttachment(0, 585);
        formData_1.left = new FormAttachment(0, 40);
        buttonNew.setLayoutData(formData_1);
        buttonNew.setText("New Data");

        final Button buttonClear = new Button(shell, SWT.NONE);
        buttonClear.addSelectionListener(new SelectionAdapter()
        {
            public void widgetSelected(SelectionEvent e)
            {
                table.removeAll();
                table.clearAll();
                table.redraw();
            }
        });
        final FormData formData_2 = new FormData();
        formData_2.bottom = new FormAttachment(buttonNew, 0, SWT.BOTTOM);
        formData_2.right = new FormAttachment(0, 370);
        formData_2.top = new FormAttachment(buttonNew, 0, SWT.TOP);
        formData_2.left = new FormAttachment(0, 240);
        buttonClear.setLayoutData(formData_2);
        buttonClear.setText("Clear Data");
    }
}