简体   繁体   中英

How to synchronize changes in Eclipse RCP?

I have a view with a tableviewer and another one with a text widget. When I select something in table viewer the text selected is shown in the text widget and I can edit that text. How can I update the table viewer with the text from the text widget while editing?

You just need to listen to SWT.Verify in the Text and update the TableViewer data accordingly:

public static void main(String[] args)
{
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    shell.setText("StackOverflow");

    final Text text = new Text(shell, SWT.BORDER);

    text.addListener(SWT.Verify, new Listener()
    {
        @Override
        public void handleEvent(Event e)
        {
            String oldString = text.getText();
            String newString = oldString.substring(0, e.start) + e.text + oldString.substring(e.end);

            /* SET STRING TO TABLEVIEWER DATA HERE */

            System.out.println(newString);
        }
    });

    shell.pack();
    shell.open();
    while (!shell.isDisposed())
    {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

Alternatively, if you just want to update the table when the user is done changing the text, listen for SWT.FocusOut on the Text instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM