首页 > 解决方案 > 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);
}

我怀疑这些片段包含问题,但如果没有,请告诉我,我也会添加其他功能。

标签: javaswtjface

解决方案


推荐阅读