KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > model > BaseWorkbenchContentProvider


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 package org.eclipse.ui.model;
12
13 import org.eclipse.jface.viewers.ITreeContentProvider;
14 import org.eclipse.jface.viewers.Viewer;
15 import org.eclipse.ui.internal.util.Util;
16
17 /**
18  * Tree content provider for objects that can be adapted to the interface
19  * {@link org.eclipse.ui.model.IWorkbenchAdapter IWorkbenchAdapter}.
20  * <p>
21  * This class may be instantiated, or subclassed.
22  * </p>
23  *
24  * @see IWorkbenchAdapter
25  * @since 3.0
26  */

27 public class BaseWorkbenchContentProvider implements ITreeContentProvider {
28
29     /**
30      * Creates a new workbench content provider.
31      *
32      */

33     public BaseWorkbenchContentProvider() {
34         super();
35     }
36
37     /* (non-Javadoc)
38      * Method declared on IContentProvider.
39      */

40     public void dispose() {
41         // do nothing
42
}
43
44     /**
45      * Returns the implementation of IWorkbenchAdapter for the given
46      * object. Returns null if the adapter is not defined or the
47      * object is not adaptable.
48      * <p>
49      * </p>
50      *
51      * @param element the element
52      * @return the corresponding workbench adapter object
53      */

54     protected IWorkbenchAdapter getAdapter(Object JavaDoc element) {
55         return (IWorkbenchAdapter)Util.getAdapter(element, IWorkbenchAdapter.class);
56     }
57
58     /* (non-Javadoc)
59      * Method declared on ITreeContentProvider.
60      */

61     public Object JavaDoc[] getChildren(Object JavaDoc element) {
62         IWorkbenchAdapter adapter = getAdapter(element);
63         if (adapter != null) {
64             return adapter.getChildren(element);
65         }
66         return new Object JavaDoc[0];
67     }
68
69     /* (non-Javadoc)
70      * Method declared on IStructuredContentProvider.
71      */

72     public Object JavaDoc[] getElements(Object JavaDoc element) {
73         return getChildren(element);
74     }
75
76     /* (non-Javadoc)
77      * Method declared on ITreeContentProvider.
78      */

79     public Object JavaDoc getParent(Object JavaDoc element) {
80         IWorkbenchAdapter adapter = getAdapter(element);
81         if (adapter != null) {
82             return adapter.getParent(element);
83         }
84         return null;
85     }
86
87     /* (non-Javadoc)
88      * Method declared on ITreeContentProvider.
89      */

90     public boolean hasChildren(Object JavaDoc element) {
91         return getChildren(element).length > 0;
92     }
93
94     /* (non-Javadoc)
95      * Method declared on IContentProvider.
96      */

97     public void inputChanged(Viewer viewer, Object JavaDoc oldInput, Object JavaDoc newInput) {
98         // do nothing
99
}
100
101 }
102
Popular Tags