eclipse rcp:如何在tableviewer中选择单个单元格? [英] eclipse rcp :how to select a single cell in tableviewer?
问题描述
我可以更改表的默认选择行为吗,我想在用户单击时选择一个单元格,并在用户双击时使其可编辑。
hwo can I change the default selection behaviour of tables, I want to make a cell selected when user click it and make it editable when user double click it.
在@nonty的帮助下,我得到了我想要的。
是我的单元突出显示工具的实现:
with @nonty 's help, I get what I want.
here is my cell highlighter implemention:
package com.amarsoft.rcputil;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.FocusCellOwnerDrawHighlighter;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
public class DefaultCellFocusHighlighter extends FocusCellOwnerDrawHighlighter {
public DefaultCellFocusHighlighter(ColumnViewer viewer) {
super(viewer);
}
protected boolean onlyTextHighlighting(ViewerCell cell) {
return false;
}
protected Color getSelectedCellBackgroundColor(ViewerCell cell) {
return cell.getControl().getDisplay().getSystemColor(SWT.COLOR_DARK_BLUE);
}
protected Color getSelectedCellForegroundColor(ViewerCell cell) {
return cell.getControl().getDisplay().getSystemColor(SWT.COLOR_WHITE);
}
protected Color getSelectedCellForegroundColorNoFocus(ViewerCell cell) {
return cell.getControl().getDisplay().getSystemColor(SWT.COLOR_WHITE);
}
protected Color getSelectedCellBackgroundColorNoFocus(ViewerCell cell) {
return cell.getControl().getDisplay().getSystemColor(SWT.COLOR_DARK_BLUE);
}
protected void focusCellChanged(ViewerCell newCell, ViewerCell oldCell) {
super.focusCellChanged(newCell, oldCell);
}
}
使用它的代码:
TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(tv,new DefaultCellFocusHighlighter(tv));
ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(tv) {
protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL
|| event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION
|| (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR)
|| event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
}
};
TableViewerEditor.create(tv, focusCellManager, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL
| ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR
| ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION);
但我遇到了新问题:
当我双击单元格以编辑其值时,单元格的左侧有一个小区域仍然用深蓝色突出显示
but I got new problem :
when I double click on cell to edit it's value, there is a little area at the left side of the cell is still highlighted with dark blue color
我知道为什么:
创建带有边框的文本控件时,则该操作系统包括围绕控件内容的特定于平台的插入项。
仍在寻求修复...
I know why :
When a text control is created with a border, the operating system includes a platform specific inset around the contents of the control.
still seeking for fixing...
推荐答案
看看这两个JFace代码段:
Have a look at these two JFace Snippets:
- Snippet036FocusBorderCellHighlighter -通过突出显示当前选中的带有焦点边框的单元格来演示键盘导航,该边框再次显示了新单元格导航支持的灵活性
- Snippet034CellEditorPerRowNewAPI -通过JFace-Viewers的3.3-API在一个列中演示了不同的CellEditor类型。
- Snippet036FocusBorderCellHighlighter - Demonstrates keyboard navigation by highlighting the currently selected cell with a focus border showing once more the flexibility of the new cell navigation support
- Snippet034CellEditorPerRowNewAPI - Demonstrates different CellEditor-Types in one COLUMN with 3.3-API of JFace-Viewers
这篇关于eclipse rcp:如何在tableviewer中选择单个单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!