1 11 package org.eclipse.jdt.internal.ui.typehierarchy; 12 13 import java.util.Arrays ; 14 import java.util.List ; 15 16 import org.eclipse.swt.widgets.Composite; 17 18 import org.eclipse.ui.IWorkbenchPart; 19 20 import org.eclipse.jdt.core.Flags; 21 import org.eclipse.jdt.core.IType; 22 import org.eclipse.jdt.core.ITypeHierarchy; 23 24 31 public class TraditionalHierarchyViewer extends TypeHierarchyViewer { 32 33 public TraditionalHierarchyViewer(Composite parent, TypeHierarchyLifeCycle lifeCycle, IWorkbenchPart part) { 34 super(parent, new TraditionalHierarchyContentProvider(lifeCycle), lifeCycle, part); 35 } 36 37 40 public String getTitle() { 41 if (isMethodFiltering()) { 42 return TypeHierarchyMessages.TraditionalHierarchyViewer_filtered_title; 43 } else { 44 return TypeHierarchyMessages.TraditionalHierarchyViewer_title; 45 } 46 } 47 48 51 public void updateContent(boolean expand) { 52 getTree().setRedraw(false); 53 refresh(); 54 55 if (expand) { 56 TraditionalHierarchyContentProvider contentProvider= (TraditionalHierarchyContentProvider) getContentProvider(); 57 int expandLevel= contentProvider.getExpandLevel(); 58 if (isMethodFiltering()) { 59 expandLevel++; 60 } 61 expandToLevel(expandLevel); 62 } 63 getTree().setRedraw(true); 64 } 65 66 69 public static class TraditionalHierarchyContentProvider extends TypeHierarchyContentProvider { 70 71 72 public TraditionalHierarchyContentProvider(TypeHierarchyLifeCycle provider) { 73 super(provider); 74 } 75 76 public int getExpandLevel() { 77 ITypeHierarchy hierarchy= getHierarchy(); 78 if (hierarchy != null) { 79 IType input= hierarchy.getType(); 80 if (input != null) { 81 return getDepth(hierarchy, input) + 2; 82 } else { 83 return 5; 84 } 85 } 86 return 2; 87 } 88 89 private int getDepth(ITypeHierarchy hierarchy, IType input) { 90 int count= 0; 91 IType superType= hierarchy.getSuperclass(input); 92 while (superType != null) { 93 count++; 94 superType= hierarchy.getSuperclass(superType); 95 } 96 return count; 97 } 98 99 102 protected final void getRootTypes(List res) { 103 ITypeHierarchy hierarchy= getHierarchy(); 104 if (hierarchy != null) { 105 IType input= hierarchy.getType(); 106 if (input == null) { 107 IType[] classes= hierarchy.getRootClasses(); 108 for (int i= 0; i < classes.length; i++) { 109 res.add(classes[i]); 110 } 111 IType[] interfaces= hierarchy.getRootInterfaces(); 112 for (int i= 0; i < interfaces.length; i++) { 113 res.add(interfaces[i]); 114 } 115 } else { 116 if (Flags.isInterface(hierarchy.getCachedFlags(input))) { 117 res.add(input); 118 } else if (isAnonymousFromInterface(input)) { 119 res.add(hierarchy.getSuperInterfaces(input)[0]); 120 } else { 121 IType[] roots= hierarchy.getRootClasses(); 122 for (int i= 0; i < roots.length; i++) { 123 if (isObject(roots[i])) { 124 res.add(roots[i]); 125 return; 126 } 127 } 128 res.addAll(Arrays.asList(roots)); } 130 } 131 } 132 } 133 134 137 protected final void getTypesInHierarchy(IType type, List res) { 138 ITypeHierarchy hierarchy= getHierarchy(); 139 if (hierarchy != null) { 140 IType[] types= hierarchy.getSubtypes(type); 141 if (isObject(type)) { 142 for (int i= 0; i < types.length; i++) { 143 IType curr= types[i]; 144 if (!isAnonymousFromInterface(curr)) { res.add(curr); 146 } 147 } 148 } else { 149 boolean isHierarchyOnType= (hierarchy.getType() != null); 150 boolean isClass= !Flags.isInterface(hierarchy.getCachedFlags(type)); 151 if (isClass || isHierarchyOnType) { 152 for (int i= 0; i < types.length; i++) { 153 res.add(types[i]); 154 } 155 } else { 156 for (int i= 0; i < types.length; i++) { 157 IType curr= types[i]; 158 if (Flags.isInterface(hierarchy.getCachedFlags(curr)) || isAnonymous(curr)) { 160 res.add(curr); 161 } 162 } 163 } 164 } 165 } 166 } 167 168 protected IType getParentType(IType type) { 169 ITypeHierarchy hierarchy= getHierarchy(); 170 if (hierarchy != null) { 171 return hierarchy.getSuperclass(type); 172 } 174 return null; 175 } 176 177 } 178 } 179 | Popular Tags |