KickJava   Java API By Example, From Geeks To Geeks.

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


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.resources.IFile;
14 import org.eclipse.core.resources.IResource;
15 import org.eclipse.core.runtime.Assert;
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.team.core.variants.IResourceVariant;
18 import org.eclipse.team.internal.core.subscribers.ContentComparator;
19
20 /**
21  * A <code>SyncInfoFilter</code> tests a <code>SyncInfo</code> for inclusion,
22  * typically in a <code>SyncInfoSet</code>.
23  *
24  * @see SyncInfo
25  * @see SyncInfoSet
26  *
27  * @since 3.0
28  */

29 public abstract class SyncInfoFilter {
30     
31     /**
32      * Selects <code>SyncInfo</code> whose local and remote contents match.
33      * This filter makes use of the <code>IStorage</code> provided by
34      * an <code>IResourceVariant</code> to obtain the remote contents.
35      * This means that the comparison may contact the server unless the contents
36      * were cached locally by a previous operation. The caching of remote
37      * contents is subscriber specific.
38      * <p>
39      * For folders, the comparison always returns <code>true</code>.
40      */

41     public static class ContentComparisonSyncInfoFilter extends SyncInfoFilter {
42         ContentComparator criteria = new ContentComparator(false);
43         /**
44          * Create a filter that does not ignore whitespace.
45          */

46         public ContentComparisonSyncInfoFilter() {
47             this(false);
48         }
49         /**
50          * Create a filter and configure how whitespace is handled.
51          * @param ignoreWhitespace whether whitespace should be ignored
52          */

53         public ContentComparisonSyncInfoFilter(boolean ignoreWhitespace) {
54             criteria = new ContentComparator(ignoreWhitespace);
55         }
56         
57         /* (non-Javadoc)
58          * @see org.eclipse.team.core.synchronize.SyncInfoFilter#select(org.eclipse.team.core.synchronize.SyncInfo, org.eclipse.core.runtime.IProgressMonitor)
59          */

60         public boolean select(SyncInfo info, IProgressMonitor monitor) {
61             IResourceVariant remote = info.getRemote();
62             IResource local = info.getLocal();
63             if (local.getType() != IResource.FILE) return true;
64             if (remote == null) return !local.exists();
65             if (!local.exists()) return false;
66             return compareContents((IFile)local, remote, monitor);
67         }
68         
69         /**
70          * Compare the contents of the local file and its variant.
71          * This is used by the <code>select</code> method to compare the
72          * contents of two non-null files.
73          * @param local a local file
74          * @param remote a resource variant of the file
75          * @param monitor a progress monitor
76          * @return whether the contents of the two files are equal
77          */

78         public boolean compareContents(IFile local, IResourceVariant remote, IProgressMonitor monitor) {
79             Assert.isNotNull(local);
80             Assert.isNotNull(remote);
81             return criteria.compare(local, remote, monitor);
82         }
83     }
84     
85     /**
86      * Return <code>true</code> if the provided <code>SyncInfo</code> matches the filter.
87      *
88      * @param info the <code>SyncInfo</code> to be tested
89      * @param monitor a progress monitor
90      * @return <code>true</code> if the <code>SyncInfo</code> matches the filter
91      */

92     public abstract boolean select(SyncInfo info, IProgressMonitor monitor);
93     
94 }
95
Popular Tags