KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > tags > FilteredTagList


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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 package org.eclipse.team.internal.ccvs.ui.tags;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
15
16 import org.eclipse.core.runtime.IAdaptable;
17 import org.eclipse.jface.resource.ImageDescriptor;
18 import org.eclipse.team.internal.ccvs.core.CVSTag;
19 import org.eclipse.team.internal.ccvs.core.util.StringMatcher;
20 import org.eclipse.ui.model.IWorkbenchAdapter;
21
22 /**
23  * Workbench model element that returns a filtered list of tags
24  */

25 public class FilteredTagList implements IWorkbenchAdapter, IAdaptable {
26
27     private final TagSource tagSource;
28     private final int[] types;
29     private StringMatcher matcher;
30
31     public FilteredTagList(TagSource tagSource, int[] types) {
32         this.tagSource = tagSource;
33         this.types = types;
34     }
35     
36     /* (non-Javadoc)
37      * @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(java.lang.Object)
38      */

39     public Object JavaDoc[] getChildren(Object JavaDoc o) {
40         CVSTag[] tags = getTags();
41         List JavaDoc filtered = new ArrayList JavaDoc();
42         for (int i = 0; i < tags.length; i++) {
43             CVSTag tag = tags[i];
44             if (select(tag)) {
45                 filtered.add(new TagElement(this, tag));
46             }
47         }
48         return filtered.toArray(new Object JavaDoc[filtered.size()]);
49     }
50
51     private boolean select(CVSTag tag) {
52         if (matcher == null) return true;
53         return matcher.match(tag.getName());
54     }
55
56     private CVSTag[] getTags() {
57         return tagSource.getTags(types);
58     }
59
60     /* (non-Javadoc)
61      * @see org.eclipse.ui.model.IWorkbenchAdapter#getImageDescriptor(java.lang.Object)
62      */

63     public ImageDescriptor getImageDescriptor(Object JavaDoc object) {
64         return null;
65     }
66
67     /* (non-Javadoc)
68      * @see org.eclipse.ui.model.IWorkbenchAdapter#getLabel(java.lang.Object)
69      */

70     public String JavaDoc getLabel(Object JavaDoc o) {
71         return null;
72     }
73
74     /* (non-Javadoc)
75      * @see org.eclipse.ui.model.IWorkbenchAdapter#getParent(java.lang.Object)
76      */

77     public Object JavaDoc getParent(Object JavaDoc o) {
78         return null;
79     }
80
81     /* (non-Javadoc)
82      * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
83      */

84     public Object JavaDoc getAdapter(Class JavaDoc adapter) {
85         if (adapter == IWorkbenchAdapter.class) return this;
86         return null;
87     }
88     
89     public void setPattern(String JavaDoc pattern) {
90         if (!pattern.endsWith("*")) { //$NON-NLS-1$
91
pattern += "*"; //$NON-NLS-1$
92
}
93         matcher = new StringMatcher(pattern, true, false);
94     }
95
96     public CVSTag[] getMatchingTags() {
97         CVSTag[] tags = getTags();
98         List JavaDoc filtered = new ArrayList JavaDoc();
99         for (int i = 0; i < tags.length; i++) {
100             CVSTag tag = tags[i];
101             if (select(tag)) {
102                 filtered.add(tag);
103             }
104         }
105         return (CVSTag[])filtered.toArray(new CVSTag[filtered.size()]);
106     }
107
108 }
109
Popular Tags