Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 111773 Details for
Bug 235583
[table] Selecting multiple items sometimes doesn't work
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
Enhanced snippet to illustrate selection problem with table more clearly
clipboard.txt (text/plain), 8.12 KB, created by
Stefan Röck
on 2008-09-05 03:05:58 EDT
(
hide
)
Description:
Enhanced snippet to illustrate selection problem with table more clearly
Filename:
MIME Type:
Creator:
Stefan Röck
Created:
2008-09-05 03:05:58 EDT
Size:
8.12 KB
patch
obsolete
>public class VirtualTableTest{ > > private static final int DB_FETCH_DELAY = 200; > private static final int ADD_ENTRIES = 100; > private static final int PREFETCH_TRESHOLD = 50; > private static final int MAX_ENTRIES= 208; > > private int rowcounter = 0; > > private List<String> model = new ArrayList<String>(); > > private void createContent(Composite parent) { > initModel(); > > Composite container = new Composite(parent, SWT.NONE); > container.setLayout(new GridLayout(1, false)); > > final TableViewer tableViewer = new TableViewer(container, SWT.VIRTUAL | SWT.BORDER | SWT.MULTI); > tableViewer.setContentProvider(new ILazyContentProvider(){ > > public void updateElement(int index){ > if (index >= 0 && index <tableViewer.getTable().getItemCount()) { > if (index > getModel().size() - PREFETCH_TRESHOLD && (getModel().size() < MAX_ENTRIES)) { > // simulate loading the next page of data from db > int approxRecordCount = addElementsToModel(); > > System.out.println("approx. record count: " + approxRecordCount); > tableViewer.setItemCount(approxRecordCount); > updateRowCountStatus(tableViewer); > } > if (index < getModel().size()) { > tableViewer.replace(getModel().get(index), index); > } else { > System.out.println("invalid index " + index + " model count " + getModel().size()); > } > } else { > System.out.println("invalid index " + index + " tableItemCount " + tableViewer.getTable().getItemCount()); > } > } > > public void dispose(){ > } > > public void inputChanged(Viewer arg0, Object arg1, Object arg2){ > } > }); > String[] columnProperties = new String[] { "Spalte 1", "Virtual Tables rock" }; > tableViewer.setColumnProperties(columnProperties); > > final Table table = tableViewer.getTable(); > > TableColumn col = new TableColumn(table, SWT.NONE); > col.setText(columnProperties[0]); > col.setWidth(200); > > col = new TableColumn(table, SWT.NONE); > col.setText(columnProperties[1]); > col.setWidth(400); > > table.setHeaderVisible(true); > table.setLinesVisible(true); > > GridDataFactory.fillDefaults().grab(true, true).applyTo(tableViewer.getTable()); > tableViewer.setItemCount(getModel().size()); > tableViewer.setInput(getModel()); > > table.setSelection(0); > > updateRowCountStatus(tableViewer); > > Button btn; > > btn = new Button(container, SWT.PUSH); > btn.setText("Clear table"); > btn.addSelectionListener(new SelectionAdapter(){ > > @Override > public void widgetSelected(SelectionEvent e){ > tableViewer.setItemCount(0); > updateRowCountStatus(tableViewer); > } > > }); > > btn = new Button(container, SWT.PUSH); > btn.setText("Delete selected rows"); > btn.addSelectionListener(new SelectionAdapter(){ > > @Override > public void widgetSelected(SelectionEvent e){ > ISelection sel = tableViewer.getSelection(); > if (sel instanceof IStructuredSelection) { > IStructuredSelection structSel = (IStructuredSelection) sel; > Iterator iterator = structSel.iterator(); > > // remove selected elements from model > while (iterator.hasNext()) { > Object element = iterator.next(); > getModel().remove(element); > } > > // refresh TableViewer > try { > tableViewer.setItemCount(getModel().size()); > tableViewer.refresh(); > tableViewer.setSelection(null); > tableViewer.getTable().setTopIndex(0); > > tableViewer.getTable().setSelection(0); > > updateRowCountStatus(tableViewer); > > } catch (Exception exc) { > System.out.println("ERROR on table refresh"); > exc.printStackTrace(); > } > } > } > > }); > > btn = new Button(container, SWT.PUSH); > btn.setText("Load new list"); > btn.addSelectionListener(new SelectionAdapter(){ > > @Override > public void widgetSelected(SelectionEvent e){ > initModel(); > tableViewer.setSelection(null); > tableViewer.getTable().setTopIndex(0); > tableViewer.setItemCount(getModel().size()); > tableViewer.refresh(); > > tableViewer.getTable().setSelection(0); > > updateRowCountStatus(tableViewer); > } > > }); > > table.addSelectionListener(new SelectionAdapter() { > @Override > public void widgetSelected(SelectionEvent e) { > updateRowCountStatus(tableViewer); > } > > }); > } > > > // Methods returns an approximate record count which is always > // one page size larger than the actually fetched records, until > // all records have been fetched and the end of list has been reached. > protected int addElementsToModel(){ > int approxRecordCount = 0; > int itemsToAdd; > > if (getModel().size() + ADD_ENTRIES < MAX_ENTRIES) { > itemsToAdd = ADD_ENTRIES; > } else { > itemsToAdd = MAX_ENTRIES - getModel().size(); > } > > for (int i = 0; i < itemsToAdd; i++) { > getModel().add("Item " + this.rowcounter++); > } > > if (getModel().size() == MAX_ENTRIES) { > approxRecordCount = MAX_ENTRIES; > } else { > approxRecordCount = getModel().size() + ADD_ENTRIES; > } > > simulateSlowDBQuery(); > return approxRecordCount; > } > > > // simulated time which is needed to perform a db query > private void simulateSlowDBQuery() { > try { > Thread.sleep(DB_FETCH_DELAY); > } catch (InterruptedException e) { > e.printStackTrace(); > } > } > > private void initModel(){ > this.rowcounter = 0; > getModel().clear(); > addElementsToModel(); > } > > private List<String> getModel(){ > return this.model; > } > > public int runTableTest(Display display){ > final Shell mainShell = new Shell(display, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX); > mainShell.setLayout(new FillLayout()); > mainShell.setMaximized(true); > > > createContent(mainShell); > > mainShell.addShellListener(new ShellAdapter() { > > > @Override > public void shellClosed(ShellEvent e){ > mainShell.dispose(); > } > }); > > mainShell.open(); > while( !mainShell.isDisposed() ) { > if( !display.readAndDispatch() ) { > display.sleep(); > } > } > > return 0; > } > > private void updateRowCountStatus(final TableViewer tableViewer){ > final Table table = tableViewer.getTable(); > String shellCaption = getModel().size() + " rows"; > > if (table.getSelectionCount() > 0) { > String selectionIdx = null; > for (int idx: table.getSelectionIndices()) { > if (selectionIdx == null) { > selectionIdx = String.valueOf(idx); > } else { > selectionIdx += "," + String.valueOf(idx); > } > } > shellCaption += "; Selection: [" + selectionIdx + "]"; > } else { > shellCaption += "; No selection"; > } > table.getShell().setText(shellCaption); > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 235583
:
103542
|
111652
| 111773