View | Details | Raw Unified | Return to bug 68031 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jface/viewers/TableViewer.java (-61 / +82 lines)
Lines 454-525 Link Here
454
 */
454
 */
455
protected void internalRefresh(Object element, boolean updateLabels) {
455
protected void internalRefresh(Object element, boolean updateLabels) {
456
	tableViewerImpl.applyEditorValue();
456
	tableViewerImpl.applyEditorValue();
457
	if (element == null || equals(element, getRoot())) {
457
	boolean usingMotif = "motif".equals(SWT.getPlatform());//$NON-NLS-1$
458
		// the parent
458
		try {
459
			if (usingMotif) {
460
				// This avoids a "graphic is disposed" error on Motif by not letting
461
				// it redraw while we remove entries.  Some items in this table are
462
				// being removed and may have icons which may have already been
463
				// disposed elsewhere.
464
				table.setRedraw(false);
465
			}
466
467
			if (element == null || equals(element, getRoot())) {
468
				// the parent
469
470
				// in the code below, it is important to do all disassociates
471
				// before any associates, since a later disassociate can undo an
472
				// earlier associate
473
				// e.g. if (a, b) is replaced by (b, a), the disassociate of b
474
				// to item 1 could undo
475
				// the associate of b to item 0.
459
476
460
		// in the code below, it is important to do all disassociates
477
				Object[] children = getSortedChildren(getRoot());
461
		// before any associates, since a later disassociate can undo an earlier associate
478
				TableItem[] items = table.getItems();
462
		// e.g. if (a, b) is replaced by (b, a), the disassociate of b to item 1 could undo
479
				int min = Math.min(children.length, items.length);
463
		// the associate of b to item 0.
480
				for (int i = 0; i < min; ++i) {
464
		
481
					// if the element is unchanged, update its label if
465
		Object[] children = getSortedChildren(getRoot());
482
					// appropriate
466
		TableItem[] items = table.getItems();
483
					if (equals(children[i], items[i].getData())) {
467
		int min = Math.min(children.length, items.length);
484
						if (updateLabels) {
468
		for (int i = 0; i < min; ++i) {
485
							updateItem(items[i], children[i]);
469
			// if the element is unchanged, update its label if appropriate
486
						} else {
470
			if (equals(children[i], items[i].getData())) {
487
							// associate the new element, even if equal to the
471
				if (updateLabels) {
488
							// old one,
472
					updateItem(items[i], children[i]);
489
							// to remove stale references (see bug 31314)
473
				}
490
							associate(children[i], items[i]);
474
				else {
491
						}
475
					// associate the new element, even if equal to the old one,
492
					} else {
476
					// to remove stale references (see bug 31314)
493
						// updateItem does an associate(...), which can mess up
477
					associate(children[i], items[i]);
494
						// the associations if the order of elements has
495
						// changed.
496
						// E.g. (a, b) -> (b, a) first replaces a->0 with b->0,
497
						// then replaces b->1 with a->1, but this actually
498
						// removes b->0.
499
						// So, if the object associated with this item has
500
						// changed,
501
						// just disassociate it for now, and update it below.
502
						items[i].setText(""); //$NON-NLS-1$
503
						items[i].setImage(new Image[0]);
504
						disassociate(items[i]);
505
					}
506
				}
507
508
				// dispose of all items beyond the end of the current elements
509
				if (min < items.length) {
510
					for (int i = items.length; --i >= min;) {
511
						disassociate(items[i]);
512
					}
513
					table.remove(min, items.length - 1);
514
				}
515
516
				// Workaround for 1GDGN4Q: ITPUI:WIN2000 - TableViewer icons get
517
				// scrunched
518
				if (table.getItemCount() == 0) {
519
					table.removeAll();
520
				}
521
522
				// Update items which were removed above
523
				for (int i = 0; i < min; ++i) {
524
					if (items[i].getData() == null) {
525
						updateItem(items[i], children[i]);
526
					}
478
				}
527
				}
479
			}
480
			else {
481
				// updateItem does an associate(...), which can mess up
482
				// the associations if the order of elements has changed.
483
				// E.g. (a, b) -> (b, a) first replaces a->0 with b->0, then replaces b->1 with a->1, but this actually removes b->0.
484
				// So, if the object associated with this item has changed,
485
				// just disassociate it for now, and update it below.
486
				items[i].setText(""); //$NON-NLS-1$
487
				items[i].setImage(new Image[0]);
488
				disassociate(items[i]);
489
			}
490
		}
491
		
492
		// dispose of all items beyond the end of the current elements
493
		if (min < items.length) {
494
			for (int i = items.length; --i >= min;) {
495
				disassociate(items[i]);
496
			}
497
			table.remove(min, items.length-1);
498
		}
499
		
500
		// Workaround for 1GDGN4Q: ITPUI:WIN2000 - TableViewer icons get scrunched
501
		if (table.getItemCount() == 0) {
502
			table.removeAll();
503
		}
504
528
505
		// Update items which were removed above
529
				// add any remaining elements
506
		for (int i = 0; i < min; ++i) {
530
				for (int i = min; i < children.length; ++i) {
507
			if (items[i].getData() == null) {
531
					updateItem(new TableItem(table, SWT.NONE, i), children[i]);
508
				updateItem(items[i], children[i]);
532
				}
533
			} else {
534
				Widget w = findItem(element);
535
				if (w != null) {
536
					updateItem(w, element);
537
				}
538
			}
539
		} finally {
540
			if (usingMotif) {
541
				table.setRedraw(true);
509
			}
542
			}
510
		}
543
		}
511
	
512
		// add any remaining elements
513
		for (int i = min; i < children.length; ++i) {
514
			updateItem(new TableItem(table, SWT.NONE, i), children[i]);
515
		}
516
	}
517
	else {
518
		Widget w = findItem(element);
519
		if (w != null) {
520
			updateItem(w, element);
521
		}
522
	}
523
}
544
}
524
/**
545
/**
525
 * Removes the given elements from this table viewer.
546
 * Removes the given elements from this table viewer.

Return to bug 68031