KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > core > synchronize > FastSyncInfoFilter


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.core.synchronize;
12
13 import org.eclipse.core.runtime.IProgressMonitor;
14
15 /**
16  * A specialized <code>SyncInfoFilter</code> that does not require a progress monitor.
17  * This enables these filters to be used when determining menu enablement or other
18  * operations that must be short running.
19  *
20  * @see SyncInfo
21  * @see SyncInfoSet
22  * @see SyncInfoFilter
23  * @since 3.0
24  */

25 public class FastSyncInfoFilter extends SyncInfoFilter {
26
27     /**
28      * Selects <code>SyncInfo</code> that match the given change type and direction.
29      *
30      * @param direction the change direction (<code>SyncInfo.OUTGOING</code>,
31      * <code>SyncInfo.INCOMING</code> and <code>SyncInfo.CONFLICTING</code>) that this filter matches
32      * @param change the change type (<code>SyncInfo.ADDITION</code>,
33      * <code>SyncInfo.DELETION</code> and <code>SyncInfo.CHANGE</code>) that this filter matches
34      * @return a <code>FastSyncInfoFilter</code> that selects <code>SyncInfo</code> that match the given
35      * change type and direction.
36      */

37     public static FastSyncInfoFilter getDirectionAndChangeFilter(int direction, int change) {
38         return new AndSyncInfoFilter(new FastSyncInfoFilter[]{new SyncInfoDirectionFilter(direction), new SyncInfoChangeTypeFilter(change)});
39     }
40
41     /**
42      * An abstract class which contains a set of <code>FastSyncInfoFilter</code> instances.
43      * Subclasses must provide the <code>select(SyncInfo)</code> method for determining
44      * matches.
45      */

46     public static abstract class CompoundSyncInfoFilter extends FastSyncInfoFilter {
47         /**
48          * Instance variable which contains all the child filters for this compound filter.
49          */

50         protected FastSyncInfoFilter[] filters;
51         /**
52          * Create a compound filter that contains the provided filters.
53          * @param filters the child filters
54          */

55         protected CompoundSyncInfoFilter(FastSyncInfoFilter[] filters) {
56             this.filters = filters;
57         }
58     }
59     
60     /**
61      * Selects <code>SyncInfo</code> which match all child filters.
62      */

63     public static class AndSyncInfoFilter extends CompoundSyncInfoFilter {
64         /**
65          * Create an AND filter from the given filters
66          * @param filters the filters to be ANDed
67          */

68         public AndSyncInfoFilter(FastSyncInfoFilter[] filters) {
69             super(filters);
70         }
71         /* (non-Javadoc)
72          * @see org.eclipse.team.core.synchronize.FastSyncInfoFilter#select(org.eclipse.team.core.synchronize.SyncInfo)
73          */

74         public boolean select(SyncInfo info) {
75             for (int i = 0; i < filters.length; i++) {
76                 FastSyncInfoFilter filter = filters[i];
77                 if (!filter.select(info)) {
78                     return false;
79                 }
80             }
81             return true;
82         }
83     }
84
85     /**
86      * Selects <code>SyncInfo</code> instances that are auto-mergable.
87      */

88     public static class AutomergableFilter extends FastSyncInfoFilter {
89         /* (non-Javadoc)
90          * @see org.eclipse.team.core.synchronize.FastSyncInfoFilter#select(org.eclipse.team.core.synchronize.SyncInfo)
91          */

92         public boolean select(SyncInfo info) {
93             return (info.getKind() & SyncInfo.AUTOMERGE_CONFLICT) != 0;
94         }
95     }
96
97     /**
98      * Selects <code>SyncInfo</code> instances that are pseudo-conflicts.
99      */

100     public static class PseudoConflictFilter extends FastSyncInfoFilter {
101         /* (non-Javadoc)
102          * @see org.eclipse.team.core.synchronize.FastSyncInfoFilter#select(org.eclipse.team.core.synchronize.SyncInfo)
103          */

104         public boolean select(SyncInfo info) {
105             return info.getKind() != 0 && (info.getKind() & SyncInfo.PSEUDO_CONFLICT) == 0;
106         }
107     }
108     
109     /**
110      * Selects <code>SyncInfo</code> that match any of the child filters.
111      */

112     public static class OrSyncInfoFilter extends CompoundSyncInfoFilter {
113         /**
114          * Create an OR filter from the given filters
115          * @param filters the filters to be ORed
116          */

117         public OrSyncInfoFilter(FastSyncInfoFilter[] filters) {
118             super(filters);
119         }
120         /* (non-Javadoc)
121          * @see org.eclipse.team.core.synchronize.FastSyncInfoFilter#select(org.eclipse.team.core.synchronize.SyncInfo)
122          */

123         public boolean select(SyncInfo info) {
124             for (int i = 0; i < filters.length; i++) {
125                 FastSyncInfoFilter filter = filters[i];
126                 if (filter.select(info)) {
127                     return true;
128                 }
129             }
130             return false;
131         }
132     }
133     
134     /**
135      * Selects <code>SyncInfo</code> whose change type match those of the filter.
136      */

137     public static class SyncInfoChangeTypeFilter extends FastSyncInfoFilter {
138         private int[] changeFilters = new int[]{SyncInfo.ADDITION, SyncInfo.DELETION, SyncInfo.CHANGE};
139         /**
140          * Create a filter that will match <code>SyncInfo</code> whose change type
141          * match those passed as arguments to this constructor.
142          * @param changeFilters the array of change types (<code>SyncInfo.ADDITION</code>,
143          * <code>SyncInfo.DELETION</code> and <code>SyncInfo.CHANGE</code>) that this filter match
144          */

145         public SyncInfoChangeTypeFilter(int[] changeFilters) {
146             this.changeFilters = changeFilters;
147         }
148         /**
149          * Create a filter that will match <code>SyncInfo</code> whose change type
150          * match that passed as an argument to this constructor.
151          * @param change the change type (<code>SyncInfo.ADDITION</code>,
152          * <code>SyncInfo.DELETION</code> and <code>SyncInfo.CHANGE</code>) that this filter matches
153          */

154         public SyncInfoChangeTypeFilter(int change) {
155             this(new int[]{change});
156         }
157         /* (non-Javadoc)
158          * @see org.eclipse.team.core.synchronize.FastSyncInfoFilter#select(org.eclipse.team.core.synchronize.SyncInfo)
159          */

160         public boolean select(SyncInfo info) {
161             int syncKind = info.getKind();
162             for (int i = 0; i < changeFilters.length; i++) {
163                 int filter = changeFilters[i];
164                 if ((syncKind & SyncInfo.CHANGE_MASK) == filter)
165                     return true;
166             }
167             return false;
168         }
169     }
170
171     /**
172      * Selects <code>SyncInfo</code> whose change direction match those of the filter.
173      */

174     public static class SyncInfoDirectionFilter extends FastSyncInfoFilter {
175         int[] directionFilters = new int[] {SyncInfo.OUTGOING, SyncInfo.INCOMING, SyncInfo.CONFLICTING};
176         /**
177          * Create a filter that will match <code>SyncInfo</code> whose change direction
178          * match those passed as arguments to this constructor.
179          * @param directionFilters the array of change directions (<code>SyncInfo.OUTGOING</code>,
180          * <code>SyncInfo.INCOMING</code> and <code>SyncInfo.CONFLICTING</code>) that this filter match
181          */

182         public SyncInfoDirectionFilter(int[] directionFilters) {
183             this.directionFilters = directionFilters;
184         }
185         /**
186          * Create a filter that will match <code>SyncInfo</code> whose change direction
187          * match that passed as arguments to this constructor.
188          * @param direction the change direction (<code>SyncInfo.OUTGOING</code>,
189          * <code>SyncInfo.INCOMING</code> and <code>SyncInfo.CONFLICTING</code>) that this filter matches
190          */

191         public SyncInfoDirectionFilter(int direction) {
192             this(new int[] { direction });
193         }
194         /* (non-Javadoc)
195          * @see org.eclipse.team.core.synchronize.FastSyncInfoFilter#select(org.eclipse.team.core.synchronize.SyncInfo)
196          */

197         public boolean select(SyncInfo info) {
198             int syncKind = info.getKind();
199             for (int i = 0; i < directionFilters.length; i++) {
200                 int filter = directionFilters[i];
201                 if ((syncKind & SyncInfo.DIRECTION_MASK) == filter)
202                     return true;
203             }
204             return false;
205         }
206     }
207
208     /**
209      * Return whether the provided <code>SyncInfo</code> matches the filter. The default
210      * behavior it to include resources whose syncKind is non-zero.
211      *
212      * @param info the <code>SyncInfo</code> being tested
213      * @return <code>true</code> if the <code>SyncInfo</code> matches the filter
214      */

215     public boolean select(SyncInfo info) {
216         return info.getKind() != 0;
217     }
218     
219     /* (non-Javadoc)
220      * @see org.eclipse.team.core.subscribers.SyncInfoFilter#select(org.eclipse.team.core.subscribers.SyncInfo, org.eclipse.core.runtime.IProgressMonitor)
221      */

222     public final boolean select(SyncInfo info, IProgressMonitor monitor) {
223         return select(info);
224     }
225 }
226
Popular Tags