java - SWT/Jface 单元格文本未保存在模型中
问题描述
我问了一个与我之前遇到的问题相关的问题,但出现了一个新问题。最初,我希望能够通过单击突出显示表格中的一行,并通过双击来编辑单元格。greg-449 给了我解决问题的方法(摆脱 FocusCellManager 并简单地使用 EditingSupport 以及我拥有的其他类,并将 editorActivationStrategy 设置为具有 MOUSE_DOUBLE_CLICK_SELECTION 位。但是,现在当我在单元格中键入文本时,文本没有保存到我的模型中。另一方面,当我使用 FocusCellManager 时,确实保存了文本。
现在,我必须使用 CellEditors,因为已经为特定列设置了很长的 CellEditor 列表。我不确定是否可以将 EditingSupport 与 CellEditors 一起使用,或者是否有必要。我附上了一些片段。
DatumTableViewer.java 的相关部分:
FocusCellOwnerDrawHighlighter drawHighlighter = new FocusCellOwnerDrawHighlighter(this); //removed this to fix the highlighting issue
final TableViewerFocusCellManager mgr = new TableViewerFocusCellManager(this, drawHighlighter); //removed this to fix the highlighting issue.
final ColumnViewerEditorActivationStrategy editorActivationSupport = getEditorActivationStrategy();
int tableKeyboardTraversalFeature = getKeyboardTraversalFeature();
TableViewerEditor.create(this, mgr, editorActivationSupport, tableKeyboardActivationFeature);
DatumColumnEmnum[] tableColumnsAsArray = getTableColumnsAsArray();
createTable(this.getTable(), tableColumnsAsArray);
setColumnProperties(properties.getPresentedColumnNames); //properties is passed into constructor
setCellEditors(tableColumnsAsArray); //I think this doesn't work properly without FocusCellManager
DatumCellModifier modifier = new DatumCellModifier(this, properties, myExpressionDataProvider); // myExpressionDataProvider is passed into constructor)
setCellModifier(modifier);
setContentProvider(contentProvider);
setInput(_myDatumList); // myDatumList set before this snippet
}
设置细胞编辑器:
private void setCellEditors(DatumColumnEnum[] columns)
{
cellEditor[] editors = new CellEditor[columns.length];
for(int i = 0; i < columns.length; i++){
DatumColumnEnum columnID = columns[i];
switch(columnID) // cases have been trimmed to shorten this snippet
{
case DATUM_ID_COLUMN:
case DATUM_NUMBER_COLUMN:
case DATUM_NAME_COLUMN:
editors[i] = new TextCellEditor(this.getTable());
((Text) editors[i].getControl()).setTextLimit(60);
break;
}
}
this.setCellEditors(editors);
}
我怀疑这些片段包含问题,但如果没有,请告诉我,我也会添加其他功能。
解决方案
推荐阅读
- r - R:使用 FOR 循环和 IF-ELSE 构造来省略列中的奇数
- php - Heroku PHP 文档根问题
- database - 利用 Redis 中的 TTL 来建模这种关系的正确数据结构是什么
- python - 如何从电报深度链接中提取数据?
- javascript - react-select 下拉菜单在模态中打开
- c++ - 如何在使用 MinGW 32 编译的 Qt 框架中使用使用 MSVC 14.0 编译的库?
- sql - 查询性能改进建议?
- python - 在 Mac 上运行 S3 命令时获取“/usr/local/opt/python/bin/python2.7: bad interpreter: No such file or directo”
- python - 遍历文本文件的行并执行某些操作
- java - 反应式:缓存服务响应几个小时