KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > model > JavaModelContentProvider


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.jdt.internal.ui.model;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
15
16 import org.eclipse.core.runtime.CoreException;
17
18 import org.eclipse.core.resources.IFolder;
19
20 import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy;
21 import org.eclipse.ltk.core.refactoring.history.RefactoringHistory;
22
23 import org.eclipse.jdt.core.ICompilationUnit;
24 import org.eclipse.jdt.core.IJavaProject;
25
26 import org.eclipse.jdt.ui.StandardJavaElementContentProvider;
27
28 /**
29  * Content provider for Java models.
30  *
31  * @since 3.2
32  */

33 public final class JavaModelContentProvider extends StandardJavaElementContentProvider {
34
35     /** The name of the settings folder */
36     private static final String JavaDoc NAME_SETTINGS_FOLDER= ".settings"; //$NON-NLS-1$
37

38     /**
39      * Creates a new java model content provider.
40      */

41     public JavaModelContentProvider() {
42         super(true);
43     }
44
45     /**
46      * {@inheritDoc}
47      */

48     public Object JavaDoc[] getChildren(final Object JavaDoc element) {
49         if (element instanceof ICompilationUnit)
50             return NO_CHILDREN;
51         else if (element instanceof RefactoringHistory)
52             return ((RefactoringHistory) element).getDescriptors();
53         else if (element instanceof IJavaProject) {
54             final List JavaDoc elements= new ArrayList JavaDoc();
55             elements.add(((IJavaProject) element).getProject().getFolder(NAME_SETTINGS_FOLDER));
56             final Object JavaDoc[] children= super.getChildren(element);
57             for (int index= 0; index < children.length; index++) {
58                 if (!elements.contains(children[index]))
59                     elements.add(children[index]);
60             }
61             return elements.toArray();
62         } else if (element instanceof IFolder) {
63             final IFolder folder= (IFolder) element;
64             try {
65                 return folder.members();
66             } catch (CoreException exception) {
67                 // Do nothing
68
}
69         }
70         return super.getChildren(element);
71     }
72
73     /**
74      * {@inheritDoc}
75      */

76     public boolean hasChildren(final Object JavaDoc element) {
77         if (element instanceof ICompilationUnit)
78             return false;
79         else if (element instanceof RefactoringHistory)
80             return true;
81         else if (element instanceof RefactoringDescriptorProxy)
82             return false;
83         else if (element instanceof IFolder)
84             return true;
85         return super.hasChildren(element);
86     }
87 }
88
Popular Tags