1 11 package org.eclipse.ui.internal.dialogs; 12 13 import java.util.ArrayList ; 14 import java.util.HashMap ; 15 import java.util.Iterator ; 16 import java.util.Map ; 17 18 import org.eclipse.jface.viewers.ITreeContentProvider; 19 import org.eclipse.jface.viewers.Viewer; 20 import org.eclipse.ui.activities.WorkbenchActivityHelper; 21 import org.eclipse.ui.internal.intro.IIntroConstants; 22 import org.eclipse.ui.views.IViewCategory; 23 import org.eclipse.ui.views.IViewDescriptor; 24 import org.eclipse.ui.views.IViewRegistry; 25 26 29 public class ViewContentProvider implements ITreeContentProvider { 30 31 35 private Map childMap = new HashMap (); 36 37 40 public ViewContentProvider() { 41 } 43 44 49 public void dispose() { 50 childMap.clear(); 51 } 52 53 58 public Object [] getChildren(Object element) { 59 Object [] children = (Object []) childMap.get(element); 60 if (children == null) { 61 children = createChildren(element); 62 childMap.put(element, children); 63 } 64 return children; 65 } 66 67 72 private Object [] createChildren(Object element) { 73 if (element instanceof IViewRegistry) { 74 IViewRegistry reg = (IViewRegistry) element; 75 IViewCategory [] categories = reg.getCategories(); 76 77 ArrayList filtered = new ArrayList (); 78 for (int i = 0; i < categories.length; i++) { 79 if (!hasChildren(categories[i])) { 80 continue; 81 } 82 83 filtered.add(categories[i]); 84 } 85 categories = (IViewCategory[]) filtered.toArray(new IViewCategory[filtered 86 .size()]); 87 88 if (categories.length == 1) { 90 return getChildren(categories[0]); 91 } 92 return categories; 93 } else if (element instanceof IViewCategory) { 94 IViewDescriptor [] views = ((IViewCategory) element).getViews(); 95 if (views != null) { 96 ArrayList filtered = new ArrayList (); 97 for (int i = 0; i < views.length; i++) { 98 Object o = views[i]; 99 if (WorkbenchActivityHelper.filterItem(o)) { 100 continue; 101 } 102 filtered.add(o); 103 } 104 return removeIntroView(filtered).toArray(); 105 } 106 } 107 108 return new Object [0]; 109 } 110 111 119 private ArrayList removeIntroView(ArrayList list) { 120 for (Iterator i = list.iterator(); i.hasNext();) { 121 IViewDescriptor view = (IViewDescriptor) i.next(); 122 if (view.getId().equals(IIntroConstants.INTRO_VIEW_ID)) { 123 i.remove(); 124 } 125 } 126 return list; 127 } 128 129 134 public Object [] getElements(Object element) { 135 return getChildren(element); 136 } 137 138 143 public Object getParent(Object element) { 144 return null; 145 } 146 147 152 public boolean hasChildren(java.lang.Object element) { 153 if (element instanceof IViewRegistry) { 154 return true; 155 } else if (element instanceof IViewCategory) { 156 if (getChildren(element).length > 0) { 157 return true; 158 } 159 } 160 return false; 161 } 162 163 169 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 170 childMap.clear(); 171 } 172 } 173 | Popular Tags |