1 /*******************************************************************************
2 * Copyright (c) 2000, 2004 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
12 package net.sourceforge.phpdt.internal.ui.viewsupport;
14 import java.util.ArrayList;
16 import net.sourceforge.phpdt.ui.IWorkingCopyProvider;
17 import net.sourceforge.phpdt.ui.ProblemsLabelDecorator.ProblemsLabelChangedEvent;
19 import org.eclipse.core.resources.IResource;
20 import org.eclipse.jface.viewers.IBaseLabelProvider;
21 import org.eclipse.jface.viewers.LabelProviderChangedEvent;
22 import org.eclipse.jface.viewers.TableViewer;
23 //import org.eclipse.swt.widgets.Composite;
24 import org.eclipse.swt.widgets.Item;
25 import org.eclipse.swt.widgets.Table;
26 import org.eclipse.swt.widgets.Widget;
29 * Extends a TableViewer to allow more performance when showing error ticks. A
30 * <code>ProblemItemMapper</code> is contained that maps all items in the tree
31 * to underlying resource
33 public class ProblemTableViewer extends TableViewer {
35 protected ResourceToItemsMapper fResourceToItemsMapper;
38 * Constructor for ProblemTableViewer.
42 // public ProblemTableViewer(Composite parent) {
48 * Constructor for ProblemTableViewer.
53 // public ProblemTableViewer(Composite parent, int style) {
54 // super(parent, style);
59 * Constructor for ProblemTableViewer.
63 public ProblemTableViewer(Table table) {
68 private void initMapper() {
69 fResourceToItemsMapper = new ResourceToItemsMapper(this);
73 * @see StructuredViewer#mapElement(Object, Widget)
75 protected void mapElement(Object element, Widget item) {
76 super.mapElement(element, item);
77 if (item instanceof Item) {
78 fResourceToItemsMapper.addToMap(element, (Item) item);
83 * @see StructuredViewer#unmapElement(Object, Widget)
85 protected void unmapElement(Object element, Widget item) {
86 if (item instanceof Item) {
87 fResourceToItemsMapper.removeFromMap(element, (Item) item);
89 super.unmapElement(element, item);
93 * @see StructuredViewer#unmapAllElements()
95 protected void unmapAllElements() {
96 fResourceToItemsMapper.clearMap();
97 super.unmapAllElements();
101 * @see ContentViewer#handleLabelProviderChanged(LabelProviderChangedEvent)
103 protected void handleLabelProviderChanged(LabelProviderChangedEvent event) {
104 if (event instanceof ProblemsLabelChangedEvent) {
105 ProblemsLabelChangedEvent e = (ProblemsLabelChangedEvent) event;
106 if (!e.isMarkerChange() && canIgnoreChangesFromAnnotionModel()) {
111 Object[] changed = event.getElements();
112 if (changed != null && !fResourceToItemsMapper.isEmpty()) {
113 ArrayList others = new ArrayList(changed.length);
114 for (int i = 0; i < changed.length; i++) {
115 Object curr = changed[i];
116 if (curr instanceof IResource) {
117 fResourceToItemsMapper.resourceChanged((IResource) curr);
122 if (others.isEmpty()) {
125 event = new LabelProviderChangedEvent((IBaseLabelProvider) event
126 .getSource(), others.toArray());
128 super.handleLabelProviderChanged(event);
132 * Answers whether this viewer can ignore label provider changes resulting
133 * from marker changes in annotation models
135 private boolean canIgnoreChangesFromAnnotionModel() {
136 Object contentProvider = getContentProvider();
137 return contentProvider instanceof IWorkingCopyProvider
138 && !((IWorkingCopyProvider) contentProvider)
139 .providesWorkingCopies();