简体   繁体   English

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

[英]How To Implement Custom Tree Columns and Cells In Eclipse RCP

I need to implement custom columns in Eclipse RCP for tree component. 我需要在Eclipse RCP中为树组件实现定制列。 Columns like Combo or a selection button that can display another selection dialog. 诸如“组合”或选择按钮之类的列可以显示另一个选择对话框。 By default, Eclipse tree columns only support raw text strings. 默认情况下,Eclipse树列仅支持原始文本字符串。 I want to replace the simple TextBox (or label) with another control. 我想用另一个控件替换简单的TextBox(或标签)。 How can I achieve that? 我该如何实现? The following example implements a simple text cells. 下面的示例实现一个简单的文本单元格。

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();

If you want to put Controls there, it's probably not because you can only display text (which itself isn't exactly true), it's because you want the contents to be editable. 如果要在此处放置控件,可能不是因为只能显示文本(其本身并不完全正确),而是因为您希望内容是可编辑的。 So use cell editors 1 . 因此,请使用单元格编辑器1 You can written tutorials at https://eclipse.org/articles/Article-Table-viewer/table_viewer.html and http://www.java2s.com/Tutorial/Java/0280__SWT/TableCellEditorComboTextandButton.htm . 您可以在https://eclipse.org/articles/Article-Table-viewer/table_viewer.htmlhttp://www.java2s.com/Tutorial/Java/0280__SWT/TableCellEditorComboTextandButton.htm上编写教程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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