テーブル内のいくつかのアイテムを選択しようとしていますが、それらを公開したくありません。問題は、メソッド(以下を参照)を呼び出すと自動的にshowSelected()内部で呼び出されることでTable.classあり、それは私が望んでいることではありません。
tableViewer.getTable().setSelection(lastSelectedIndices);
tableViewerを使用して選択を設定しようとしましたが、何らかの理由で機能しません。たとえば、tableViewer.setSelection(new StructuredSelection (lastSelectedIndices), false);
このコード行では何も選択されません。
とにかく、テーブルの行を選択して、それらを表示させないようにすることはできますか?私のシステムではsetSelection、ユーザーが選択したアイテムを紛失しないように、グリッドが更新された後は毎回呼び出す必要があります。この問題は、ユーザーがグリッドを下にスクロールしたときに発生します->その時点で更新が発生すると、グリッドは選択したアイテムがある場所にジャンプして戻ります。ユーザーがテーブルを下にスクロールし、突然スクロールバーが一番上にジャンプすると、それは本当に奇妙に見えます。
どんな助けでも大歓迎です!
-テーブルを設定するためのコード-
// add table viewer
tableViewer = new TableViewer(this, SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL);
tableViewer.setUseHashlookup(true);
tableViewer.addFilter(new GridPanelViewerFilter());
tableViewer.setComparator(new GridPanelViewerComparator());
tableViewer.setComparer(new GridPanelElementComparer());
table = tableViewer.getTable();
GridData tableGd = new GridData(SWT.FILL, SWT.FILL, true, true);
table.setLayoutData(tableGd);
table.setHeaderVisible(true);
table.setLinesVisible(true);
// set table font
setTableFont();
// listen to paint events for anti aliasing
table.addPaintListener( ...etcetc
---テーブルを更新するためのコード-
protected void refreshGrid() {
if(!updateGrid) return;
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
try {
// check if disposed
if (isDisposed()) {
log.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, getClass().getName() + ": " + "Grid already disposed"));
return;
}
// refresh table
table.setRedraw(false);
try {
// get last selected indices from mouse down event
tableViewer.refresh(true, false);
if(lastSelectedIndices != null){
tableViewer.getTable().deselectAll();
tableViewer.getTable().select(lastSelectedIndices);
}
} catch (Exception e) {
log.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
getClass().getName() + ": " + "Error at refresh table", e));
}
table.setRedraw(true);
// process post grid refresh
postGridRefresh();
} catch (Exception e) {
log.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, getClass().getName() + ": " + "Error during refresh grid", e));
}
}
});
}