92147c338f01f7a490f15ca0df6b7de99ab21e5a
[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 //incastrix
17 //import org.eclipse.jface.text.Assert;
18 import org.eclipse.core.runtime.Assert;
19 import org.eclipse.jface.viewers.StructuredViewer;
20 import org.eclipse.swt.widgets.Control;
21
22 public class FilterUpdater implements IResourceChangeListener {
23
24         private StructuredViewer fViewer;
25
26         public FilterUpdater(StructuredViewer viewer) {
27                 Assert.isNotNull(viewer);
28                 fViewer = viewer;
29         }
30
31         /*
32          * (non-Javadoc)
33          * 
34          * @see org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent)
35          */
36         public void resourceChanged(IResourceChangeEvent event) {
37                 IResourceDelta delta = event.getDelta();
38                 if (delta == null)
39                         return;
40
41                 IResourceDelta[] projDeltas = delta
42                                 .getAffectedChildren(IResourceDelta.CHANGED);
43                 for (int i = 0; i < projDeltas.length; i++) {
44                         IResourceDelta pDelta = projDeltas[i];
45                         if ((pDelta.getFlags() & IResourceDelta.DESCRIPTION) != 0) {
46                                 final Control ctrl = fViewer.getControl();
47                                 if (ctrl != null && !ctrl.isDisposed()) {
48                                         // async is needed due to bug 33783
49                                         ctrl.getDisplay().asyncExec(new Runnable() {
50                                                 public void run() {
51                                                         if (!ctrl.isDisposed())
52                                                                 fViewer.refresh(false);
53                                                 }
54                                         });
55                                 }
56                         }
57                 }
58         }
59 }