1 11 12 package org.eclipse.jdt.internal.ui.viewsupport; 13 14 import java.util.ArrayList ; 15 16 import org.eclipse.core.resources.IResource; 17 18 import org.eclipse.swt.widgets.Composite; 19 import org.eclipse.swt.widgets.Item; 20 import org.eclipse.swt.widgets.Table; 21 import org.eclipse.swt.widgets.Widget; 22 23 import org.eclipse.jface.viewers.IBaseLabelProvider; 24 import org.eclipse.jface.viewers.LabelProviderChangedEvent; 25 import org.eclipse.jface.viewers.TableViewer; 26 27 import org.eclipse.jdt.ui.IWorkingCopyProvider; 28 import org.eclipse.jdt.ui.ProblemsLabelDecorator.ProblemsLabelChangedEvent; 29 30 35 public class ProblemTableViewer extends TableViewer implements ResourceToItemsMapper.IContentViewerAccessor { 36 37 protected ResourceToItemsMapper fResourceToItemsMapper; 38 39 43 public ProblemTableViewer(Composite parent) { 44 super(parent); 45 initMapper(); 46 } 47 48 53 public ProblemTableViewer(Composite parent, int style) { 54 super(parent, style); 55 initMapper(); 56 } 57 58 62 public ProblemTableViewer(Table table) { 63 super(table); 64 initMapper(); 65 } 66 67 private void initMapper() { 68 fResourceToItemsMapper= new ResourceToItemsMapper(this); 69 } 70 71 74 public void doUpdateItem(Widget item) { 75 doUpdateItem(item, item.getData(), true); 76 } 77 78 81 protected void mapElement(Object element, Widget item) { 82 super.mapElement(element, item); 83 if (item instanceof Item) { 84 fResourceToItemsMapper.addToMap(element, (Item) item); 85 } 86 } 87 88 91 protected void unmapElement(Object element, Widget item) { 92 if (item instanceof Item) { 93 fResourceToItemsMapper.removeFromMap(element, (Item) item); 94 } 95 super.unmapElement(element, item); 96 } 97 98 101 protected void unmapAllElements() { 102 fResourceToItemsMapper.clearMap(); 103 super.unmapAllElements(); 104 } 105 106 109 protected void handleLabelProviderChanged(LabelProviderChangedEvent event) { 110 if (event instanceof ProblemsLabelChangedEvent) { 111 ProblemsLabelChangedEvent e= (ProblemsLabelChangedEvent) event; 112 if (!e.isMarkerChange() && canIgnoreChangesFromAnnotionModel()) { 113 return; 114 } 115 } 116 117 Object [] changed= event.getElements(); 118 if (changed != null && !fResourceToItemsMapper.isEmpty()) { 119 ArrayList others= new ArrayList (changed.length); 120 for (int i= 0; i < changed.length; i++) { 121 Object curr= changed[i]; 122 if (curr instanceof IResource) { 123 fResourceToItemsMapper.resourceChanged((IResource) curr); 124 } else { 125 others.add(curr); 126 } 127 } 128 if (others.isEmpty()) { 129 return; 130 } 131 event= new LabelProviderChangedEvent((IBaseLabelProvider) event.getSource(), others.toArray()); 132 } 133 super.handleLabelProviderChanged(event); 134 } 135 136 140 private boolean canIgnoreChangesFromAnnotionModel() { 141 Object contentProvider= getContentProvider(); 142 return contentProvider instanceof IWorkingCopyProvider && !((IWorkingCopyProvider)contentProvider).providesWorkingCopies(); 143 } 144 } 145 | Popular Tags |