001: /*******************************************************************************
002: * Copyright (c) 2005, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jface.tests.performance;
011:
012: import org.eclipse.jface.util.Assert;
013: import org.eclipse.jface.viewers.IStructuredContentProvider;
014: import org.eclipse.jface.viewers.Viewer;
015: import org.eclipse.jface.viewers.ViewerSorter;
016:
017: /**
018: * The RefreshTestContentProvider is the content
019: * provider for refresh tests.
020: *
021: */
022: public class RefreshTestContentProvider implements
023: IStructuredContentProvider {
024:
025: static int seed = 1;
026: static TestElement[] allElements;
027: public static int ELEMENT_COUNT = 10000;
028: TestElement[] currentElements;
029:
030: static {
031: allElements = new TestElement[ELEMENT_COUNT];
032: for (int i = 0; i < ELEMENT_COUNT; i++) {
033: allElements[i] = new TestElement(i);
034: }
035: }
036:
037: void preSortElements(Viewer viewer, ViewerSorter sorter) {
038: sorter.sort(viewer, currentElements);
039:
040: }
041:
042: public RefreshTestContentProvider(int size) {
043: Assert.isTrue(size <= ELEMENT_COUNT);
044: setSize(size);
045: }
046:
047: /**
048: * Set the size of the amount we are currently displaying
049: * to size.
050: * @param size
051: */
052: public void setSize(int size) {
053:
054: currentElements = new TestElement[size];
055: for (int i = 0; i < currentElements.length; i++) {
056: currentElements[i] = allElements[i];
057: }
058:
059: }
060:
061: /* (non-Javadoc)
062: * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
063: */
064: public Object[] getElements(Object inputElement) {
065: return currentElements;
066: }
067:
068: /* (non-Javadoc)
069: * @see org.eclipse.jface.viewers.IContentProvider#dispose()
070: */
071: public void dispose() {
072: currentElements = null;
073:
074: }
075:
076: /* (non-Javadoc)
077: * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
078: */
079: public void inputChanged(Viewer viewer, Object oldInput,
080: Object newInput) {
081: //Do nothing here
082: }
083:
084: /**
085: * Restore the elements to thier old poorly sorted
086: * state.
087: *
088: */
089: public void refreshElements() {
090: for (int i = 0; i < ELEMENT_COUNT; i++) {
091: currentElements[i] = new TestElement(i + seed);
092: }
093: seed += 257;
094:
095: }
096:
097: public void cloneElements() {
098: currentElements = (TestElement[]) currentElements.clone();
099: }
100:
101: }
|