aboutsummaryrefslogtreecommitdiffstats
blob: 7bb83c5031f9c42d407ed3fe4b3475baa2a41256 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*******************************************************************************
 * Copyright (c) 2005, 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jface.tests.viewers;

import junit.framework.AssertionFailedError;

import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.viewers.IContentProvider;
import org.eclipse.jface.viewers.ILazyContentProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;

/**
 * The TestLazyModelContentProvider is the lazy version
 * of the model content provider.
 */
public class TestLazyModelContentProvider extends TestModelContentProvider implements ILazyContentProvider<TestElement>, IContentProvider<TestElement> {

	TableViewerTest test;
	TestElement input;

	TestLazyModelContentProvider(TableViewerTest testObject){
		test = testObject;
		if(!(testObject instanceof VirtualLazyTableViewerTest)) {
			throw new AssertionFailedError("TestLazyModelContentProvider only works with VirtualLazyTableViewerTest");
		}
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ILazyContentProvider#updateElements(int, int)
	 */
	public void updateElement(int index) {

		((VirtualLazyTableViewerTest)test).updateElementCalled(index);

		if(input == null)
			return; //Nothing to update yet

        ((TableViewer<TestElement,TestElement>) test.fViewer).replace(input.getChildAt(index), index);

	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.tests.viewers.TestModelContentProvider#dispose()
	 */
	public void dispose() {
		super.dispose();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.tests.viewers.TestModelContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
	 */
	public void inputChanged(Viewer<TestElement> viewer, TestElement oldInput, TestElement newInput) {
		input = newInput;
		((TableViewer<TestElement,TestElement>)viewer).setItemCount(input==null?0:input.getChildCount());
		super.inputChanged(viewer, oldInput, newInput);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.tests.viewers.TestModelContentProvider#getElements(java.lang.Object)
	 */
	public TestElement[] getElements(TestElement element) {
		Assert.isTrue(false,"Should not ever call getElements if lazy");
		return super.getElements(element);
	}
}