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 104115 Details for
Bug 235368
[table] ArrayIndexOutOfBoundsException in virtual TableViewer
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.
Snippet #2 to reproduce the SWT error
clipboard.txt (text/plain), 7.36 KB, created by
Stefan Röck
on 2008-06-09 02:41:46 EDT
(
hide
)
Description:
Snippet #2 to reproduce the SWT error
Filename:
MIME Type:
Creator:
Stefan Röck
Created:
2008-06-09 02:41:46 EDT
Size:
7.36 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= 314; > > 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); > 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(); > 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 " + 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(){ > 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() { > > > public void shellClosed(ShellEvent e){ > mainShell.dispose(); > } > }); > > mainShell.open(); > while( !mainShell.isDisposed() ) { > if( !display.readAndDispatch() ) { > display.sleep(); > } > } > > return 0; > } > > /** > * @param tableViewer > * <p><b>Author:</b> stefan.roeck (<a href="mailto:stefan.roeck@cas.de">stefan.roeck@cas.de</a>)</p> > * @since 09.05.2008 > */ > private void updateRowCountStatus(final TableViewer tableViewer){ > tableViewer.getTable().getShell().setText(getModel().size() + " rows"); > }
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 235368
:
103345
|
103552
|
103757
|
103908
| 104115