KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > viewers > ArrayContentProvider


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.jface.viewers;
13
14 import java.util.Collection JavaDoc;
15
16 /**
17  * This implementation of <code>IStructuredContentProvider</code> handles
18  * the case where the viewer input is an unchanging array or collection of elements.
19  * <p>
20  * This class is not intended to be subclassed outside the viewer framework.
21  * </p>
22  *
23  * @since 2.1
24  */

25 public class ArrayContentProvider implements IStructuredContentProvider {
26
27     /**
28      * Returns the elements in the input, which must be either an array or a
29      * <code>Collection</code>.
30      */

31     public Object JavaDoc[] getElements(Object JavaDoc inputElement) {
32         if (inputElement instanceof Object JavaDoc[]) {
33             return (Object JavaDoc[]) inputElement;
34         }
35         if (inputElement instanceof Collection JavaDoc) {
36             return ((Collection JavaDoc) inputElement).toArray();
37         }
38         return new Object JavaDoc[0];
39     }
40
41     /**
42      * This implementation does nothing.
43      */

44     public void inputChanged(Viewer viewer, Object JavaDoc oldInput, Object JavaDoc newInput) {
45         // do nothing.
46
}
47
48     /**
49      * This implementation does nothing.
50      */

51     public void dispose() {
52         // do nothing.
53
}
54 }
55
Popular Tags