KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > typehierarchy > SubTypeHierarchyViewer


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.jdt.internal.ui.typehierarchy;
12
13 import java.util.List JavaDoc;
14
15 import org.eclipse.swt.widgets.Composite;
16
17 import org.eclipse.ui.IWorkbenchPart;
18
19 import org.eclipse.jdt.core.IType;
20 import org.eclipse.jdt.core.ITypeHierarchy;
21
22 /**
23  * A viewer including the content provider for the subtype hierarchy.
24  * Used by the TypeHierarchyViewPart which has to provide a TypeHierarchyLifeCycle
25  * on construction (shared type hierarchy)
26  */

27 public class SubTypeHierarchyViewer extends TypeHierarchyViewer {
28     
29     public SubTypeHierarchyViewer(Composite parent, TypeHierarchyLifeCycle lifeCycle, IWorkbenchPart part) {
30         super(parent, new SubTypeHierarchyContentProvider(lifeCycle), lifeCycle, part);
31     }
32
33     /*
34      * @see TypeHierarchyViewer#getTitle
35      */

36     public String JavaDoc getTitle() {
37         if (isMethodFiltering()) {
38             return TypeHierarchyMessages.SubTypeHierarchyViewer_filtered_title;
39         } else {
40             return TypeHierarchyMessages.SubTypeHierarchyViewer_title;
41         }
42     }
43     
44     /*
45      * @see TypeHierarchyViewer#updateContent
46      */

47     public void updateContent(boolean expand) {
48         getTree().setRedraw(false);
49         refresh();
50         
51         if (expand) {
52             int expandLevel= 2;
53             if (isMethodFiltering()) {
54                 expandLevel++;
55             }
56             expandToLevel(expandLevel);
57         }
58         getTree().setRedraw(true);
59     }
60     
61     /**
62      * Content provider for the subtype hierarchy
63      */

64     public static class SubTypeHierarchyContentProvider extends TypeHierarchyContentProvider {
65         public SubTypeHierarchyContentProvider(TypeHierarchyLifeCycle lifeCycle) {
66             super(lifeCycle);
67         }
68         
69         protected final void getTypesInHierarchy(IType type, List JavaDoc res) {
70             ITypeHierarchy hierarchy= getHierarchy();
71             if (hierarchy != null) {
72                 IType[] types= hierarchy.getSubtypes(type);
73                 if (isObject(type)) {
74                     for (int i= 0; i < types.length; i++) {
75                         IType curr= types[i];
76                         if (!isAnonymousFromInterface(curr)) {
77                             res.add(curr);
78                         }
79                     }
80                 } else {
81                     for (int i= 0; i < types.length; i++) {
82                         res.add(types[i]);
83                     }
84                 }
85             }
86             
87         }
88         
89         protected IType getParentType(IType type) {
90             ITypeHierarchy hierarchy= getHierarchy();
91             if (hierarchy != null) {
92                 return hierarchy.getSuperclass(type);
93                 // dont handle interfaces
94
}
95             return null;
96         }
97
98 }
99     
100     
101     
102 }
103
Popular Tags