KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > dialogs > ListContentProvider


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

11 package org.eclipse.ui.internal.dialogs;
12
13 import java.util.List JavaDoc;
14
15 import org.eclipse.jface.viewers.IStructuredContentProvider;
16 import org.eclipse.jface.viewers.Viewer;
17
18 /**
19  * Provides elements from a List.
20  */

21 public class ListContentProvider implements IStructuredContentProvider {
22     List JavaDoc contents;
23
24     public ListContentProvider() {
25     }
26     /**
27      * Implements IStructuredContentProvider.
28      *
29      * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(Object)
30      */

31     public Object JavaDoc[] getElements(Object JavaDoc input) {
32         if (contents != null && contents == input) {
33             return contents.toArray();
34         }
35         return new Object JavaDoc[0];
36     }
37     /**
38      * Implements IContentProvider.
39      *
40      * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(Viewer, Object, Object)
41      */

42     public void inputChanged(Viewer viewer, Object JavaDoc oldInput, Object JavaDoc newInput) {
43         if (newInput instanceof List JavaDoc) {
44             contents = (List JavaDoc) newInput;
45         }
46         else {
47             contents = null;
48         }
49     }
50     /**
51      * Implements IContentProvider.
52      *
53      * @see org.eclipse.jface.viewers.IContentProvider#dispose()
54      */

55     public void dispose() {
56     }
57 }
58
Popular Tags