KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > sourcelookup > BasicContainerContentProvider


1 /*******************************************************************************
2  * Copyright (c) 2003, 2005 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.debug.internal.ui.sourcelookup;
12
13 import java.util.ArrayList JavaDoc;
14
15 import org.eclipse.core.resources.IProject;
16 import org.eclipse.core.resources.IResource;
17 import org.eclipse.core.resources.IWorkspaceRoot;
18 import org.eclipse.jface.viewers.ITreeContentProvider;
19 import org.eclipse.jface.viewers.Viewer;
20 /**
21  * Provides content for a tree viewer that shows only containers.
22  *
23  * @since 3.0
24  */

25 public class BasicContainerContentProvider implements ITreeContentProvider {
26
27     private boolean fShowClosedProjects = true;
28     /**
29      * Creates a new ResourceContentProvider.
30      */

31     public BasicContainerContentProvider() {
32     }
33     /**
34      * The visual part that is using this content provider is about
35      * to be disposed. Deallocate all allocated SWT resources.
36      */

37     public void dispose() {
38     }
39     
40     /**
41      * @see ITreeContentProvider#getChildren
42      */

43     public Object JavaDoc[] getChildren(Object JavaDoc element) {
44         if (element instanceof IWorkspaceRoot) {
45             // check if closed projects should be shown
46
IProject[] allProjects = ((IWorkspaceRoot) element).getProjects();
47             if (fShowClosedProjects)
48                 return allProjects;
49             
50             ArrayList JavaDoc accessibleProjects = new ArrayList JavaDoc();
51             for (int i = 0; i < allProjects.length; i++) {
52                 if (allProjects[i].isOpen()) {
53                     accessibleProjects.add(allProjects[i]);
54                 }
55             }
56             return accessibleProjects.toArray();
57         }
58         return new Object JavaDoc[0];
59     }
60     
61     /**
62      * @see ITreeContentProvider#getElements
63      */

64     public Object JavaDoc[] getElements(Object JavaDoc element) {
65         return getChildren(element);
66     }
67     
68     /**
69      * @see ITreeContentProvider#getParent
70      */

71     public Object JavaDoc getParent(Object JavaDoc element) {
72         if (element instanceof IResource)
73             return ((IResource) element).getParent();
74         return null;
75     }
76     
77     /**
78      * @see ITreeContentProvider#hasChildren
79      */

80     public boolean hasChildren(Object JavaDoc element) {
81         return getChildren(element).length > 0;
82     }
83     
84     /**
85      * @see IContentProvider#inputChanged
86      */

87     public void inputChanged(Viewer viewer, Object JavaDoc oldInput, Object JavaDoc newInput) {
88         
89     }
90 }
91
Popular Tags