KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > viewsupport > JavaViewerFilter


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.jdt.internal.ui.viewsupport;
13
14 import org.eclipse.jface.viewers.Viewer;
15 import org.eclipse.jface.viewers.ViewerFilter;
16
17 /**
18  * filter with a live cycle
19  */

20 public abstract class JavaViewerFilter extends ViewerFilter {
21
22     private int fCount= 0;
23     
24     /**
25      * To be overridden by implement
26      */

27     protected abstract void initFilter();
28     
29     protected abstract void freeFilter();
30     
31     public final void filteringStart() {
32         if (fCount == 0)
33             initFilter();
34         fCount++;
35     }
36     
37     public final void filteringEnd() {
38         fCount--;
39         if (fCount == 0)
40             freeFilter();
41     }
42     
43     /*
44      * Overrides method from ViewerFilter
45      */

46     public Object JavaDoc[] filter(Viewer viewer, Object JavaDoc parent, Object JavaDoc[] elements) {
47         try {
48             filteringStart();
49             return super.filter(viewer, parent, elements);
50         } finally {
51             filteringEnd();
52         }
53     }
54
55
56 }
57
Popular Tags