1 11 package org.eclipse.jdt.internal.ui.browsing; 12 13 import java.util.List ; 14 15 import org.eclipse.swt.widgets.Composite; 16 import org.eclipse.swt.widgets.Item; 17 import org.eclipse.swt.widgets.Widget; 18 19 import org.eclipse.jface.viewers.ViewerFilter; 20 21 import org.eclipse.jdt.core.IPackageFragment; 22 import org.eclipse.jdt.core.JavaModelException; 23 24 import org.eclipse.jdt.internal.ui.JavaPlugin; 25 import org.eclipse.jdt.internal.ui.viewsupport.ColoredViewersManager; 26 import org.eclipse.jdt.internal.ui.viewsupport.ProblemTreeViewer; 27 28 31 public class PackagesViewTreeViewer extends ProblemTreeViewer implements IPackagesViewViewer{ 32 33 public PackagesViewTreeViewer(Composite parent, int style) { 34 super(parent, style); 35 ColoredViewersManager.install(this); 36 } 37 38 41 public void mapElement(Object element, Widget item) { 42 if (element instanceof LogicalPackage && item instanceof Item) { 43 LogicalPackage cp= (LogicalPackage) element; 44 IPackageFragment[] fragments= cp.getFragments(); 45 for (int i= 0; i < fragments.length; i++) { 46 IPackageFragment fragment= fragments[i]; 47 fResourceToItemsMapper.addToMap(fragment, (Item) item); 48 } 49 } 50 super.mapElement(element, item); 51 } 52 53 56 public void unmapElement(Object element, Widget item) { 57 58 if (element instanceof LogicalPackage && item instanceof Item) { 59 LogicalPackage cp= (LogicalPackage) element; 60 IPackageFragment[] fragments= cp.getFragments(); 61 for (int i= 0; i < fragments.length; i++) { 62 IPackageFragment fragment= fragments[i]; 63 fResourceToItemsMapper.removeFromMap((Object )fragment, (Item)item); 64 } 65 } 66 super.unmapElement(element, item); 67 } 68 69 72 protected boolean isFiltered(Object object, Object parent, ViewerFilter[] filters) { 73 boolean res= super.isFiltered(object, parent, filters); 74 if (res && isEssential(object)) { 75 return false; 76 } 77 return res; 78 } 79 80 private boolean isEssential(Object object) { 81 try { 82 if (object instanceof IPackageFragment) { 83 IPackageFragment fragment = (IPackageFragment) object; 84 if (!fragment.isDefaultPackage() && fragment.hasSubpackages()) { 85 return hasFilteredChildren(fragment); 86 } 87 } else if (object instanceof LogicalPackage) { 88 LogicalPackage logicalPackage= (LogicalPackage) object; 89 if (!logicalPackage.isDefaultPackage() && logicalPackage.hasSubpackages()) { 90 return !hasFilteredChildren(object); 91 } 92 } 93 } catch (JavaModelException e) { 94 JavaPlugin.log(e); 95 } 96 return false; 97 } 98 99 101 public Widget doFindItem(Object element) { 102 return super.doFindItem(element); 103 } 104 105 public Widget doFindInputItem(Object element) { 106 return super.doFindInputItem(element); 107 } 108 109 public List getSelectionFromWidget() { 110 return super.getSelectionFromWidget(); 111 } 112 113 public void doUpdateItem(Widget item, Object element, boolean fullMap){ 114 super.doUpdateItem(item, element, fullMap); 115 } 116 117 public void internalRefresh(Object element){ 118 super.internalRefresh(element); 119 } 120 121 public void setSelectionToWidget(List l, boolean reveal){ 122 super.setSelectionToWidget(l, reveal); 123 } 124 } 125 | Popular Tags |