f115b514fcf1409221008d40bbd83be8e2087484
[phpeclipse.git] / net.sourceforge.phpeclipse.ui / src / net / sourceforge / phpdt / internal / ui / viewsupport / FilterUpdater.java
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
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.viewsupport;
12
13 import org.eclipse.core.resources.IResourceChangeEvent;
14 import org.eclipse.core.resources.IResourceChangeListener;
15 import org.eclipse.core.resources.IResourceDelta;
16 import org.eclipse.jface.util.Assert;
17 import org.eclipse.jface.viewers.StructuredViewer;
18 import org.eclipse.swt.widgets.Control;
19
20 public class FilterUpdater implements IResourceChangeListener {
21
22         private StructuredViewer fViewer;
23
24         public FilterUpdater(StructuredViewer viewer) {
25                 Assert.isNotNull(viewer);
26                 fViewer = viewer;
27         }
28
29         /*
30          * (non-Javadoc)
31          * 
32          * @see org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent)
33          */
34         public void resourceChanged(IResourceChangeEvent event) {
35                 IResourceDelta delta = event.getDelta();
36                 if (delta == null)
37                         return;
38
39                 IResourceDelta[] projDeltas = delta
40                                 .getAffectedChildren(IResourceDelta.CHANGED);
41                 for (int i = 0; i < projDeltas.length; i++) {
42                         IResourceDelta pDelta = projDeltas[i];
43                         if ((pDelta.getFlags() & IResourceDelta.DESCRIPTION) != 0) {
44                                 final Control ctrl = fViewer.getControl();
45                                 if (ctrl != null && !ctrl.isDisposed()) {
46                                         // async is needed due to bug 33783
47                                         ctrl.getDisplay().asyncExec(new Runnable() {
48                                                 public void run() {
49                                                         if (!ctrl.isDisposed())
50                                                                 fViewer.refresh(false);
51                                                 }
52                                         });
53                                 }
54                         }
55                 }
56         }
57 }