01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jface.viewers;
11:
12: import java.util.Collection;
13:
14: /**
15: * This implementation of <code>IStructuredContentProvider</code> handles
16: * the case where the viewer input is an unchanging array or collection of elements.
17: * <p>
18: * This class is not intended to be subclassed outside the viewer framework.
19: * </p>
20: *
21: * @since 2.1
22: */
23: public class ArrayContentProvider implements IStructuredContentProvider {
24:
25: /**
26: * Returns the elements in the input, which must be either an array or a
27: * <code>Collection</code>.
28: */
29: public Object[] getElements(Object inputElement) {
30: if (inputElement instanceof Object[]) {
31: return (Object[]) inputElement;
32: }
33: if (inputElement instanceof Collection) {
34: return ((Collection) inputElement).toArray();
35: }
36: return new Object[0];
37: }
38:
39: /**
40: * This implementation does nothing.
41: */
42: public void inputChanged(Viewer viewer, Object oldInput,
43: Object newInput) {
44: // do nothing.
45: }
46:
47: /**
48: * This implementation does nothing.
49: */
50: public void dispose() {
51: // do nothing.
52: }
53: }
|