I am trying to select some items in my table, but I DO NOT want them to be shown. The problem is that calling the method (see below) automatically causes showSelected() called inside Table.class , and this is not what I want.
tableViewer.getTable().setSelection(lastSelectedIndices);
I tried to set the selection using tableViewer, but for some reason it does not work ex: tableViewer.setSelection(new StructuredSelection (lastSelectedIndices), false); this line of code does not cause a selection.
In any case, can I choose the row order of the table and NOT force them to expand? On my system, I need to call setSelection every time after updating the grid so that the user does not lose his selected item. The problem arises when the user scrolls the grid → if an update occurs at that moment, the grid goes back to where the selected elements are. It looks strange when the user scrolls down the table, and suddenly the scroll bar goes up.
Any help is much appreciated!
- code for setting up the table -
// 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
--- code to update the table -
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)); } } }); }