如何在 Eclipse RCP 中实现自定义树列和单元格

How To Implement Custom Tree Columns and Cells In Eclipse RCP

我需要在 Eclipse RCP 中为树组件实现自定义列。 Combo 等列或可以显示另一个选择对话框的选择按钮。默认情况下,Eclipse 树列仅支持原始文本字符串。我想用另一个控件替换简单的 TextBox(或标签)。我怎样才能做到这一点? 下面的例子实现了一个简单的文本单元格。

Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
Table table = new Table(shell, SWT.BORDER);
table.setHeaderVisible(true);
table.setLinesVisible(true);

for (int i = 0; i < 2; i++) {
    new TableColumn(table, SWT.NONE);
}
table.getColumn(0).setText ("Task");
table.getColumn(1).setText ("Progress");
for (int i = 0; i < 40; i++) {
    TableItem item = new TableItem(table, SWT.NONE);
    item.setText("Task " + i);
}
table.getColumn(0).pack();
table.getColumn(1).setWidth(128);
shell.pack();
shell.open();
while (!shell.isDisposed()) {
    if (!display.readAndDispatch()) {
        display.sleep();
    }
}
display.dispose();

如果您想将控件放在那里,可能不是因为您只能显示文本(这本身并不完全正确),而是因为您希望内容是可编辑的。所以使用单元格编辑器1. You can written tutorials at https://eclipse.org/articles/Article-Table-viewer/table_viewer.htmlhttp://www.java2s.com/Tutorial/Java/0280__SWT/TableCellEditorComboTextandButton.htm .