[英]How to synchronize changes in Eclipse RCP?
I have a view with a tableviewer and another one with a text widget. 我有一个带tableviewer的视图,另一个带文本小部件的视图。 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: 您只需要听
SWT.Verify
在Text
并相应地更新TableViewer
数据即可:
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. 或者,如果你只是想在用户完成更改文本更新表,侦听
SWT.FocusOut
上的Text
来代替。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.