KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > core > subscribers > ContentComparisonDiffFilter


1 /*******************************************************************************
2  * Copyright (c) 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.core.subscribers;
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.diff.DiffFilter;
18 import org.eclipse.team.core.diff.IDiff;
19 import org.eclipse.team.core.history.IFileRevision;
20 import org.eclipse.team.core.mapping.provider.ResourceDiffTree;
21 import org.eclipse.team.internal.core.mapping.SyncInfoToDiffConverter;
22
23 public class ContentComparisonDiffFilter extends DiffFilter {
24     ContentComparator criteria = new ContentComparator(false);
25     
26     /**
27      * Create a filter that does not ignore whitespace.
28      */

29     public ContentComparisonDiffFilter() {
30         this(false);
31     }
32     /**
33      * Create a filter and configure how whitespace is handled.
34      * @param ignoreWhitespace whether whitespace should be ignored
35      */

36     public ContentComparisonDiffFilter(boolean ignoreWhitespace) {
37         criteria = new ContentComparator(ignoreWhitespace);
38     }
39     
40     /**
41      * Compare the contents of the local file and its variant.
42      * This is used by the <code>select</code> method to compare the
43      * contents of two non-null files.
44      * @param local a local file
45      * @param remote a resource variant of the file
46      * @param monitor a progress monitor
47      * @return whether the contents of the two files are equal
48      */

49     public boolean compareContents(IFile local, IFileRevision remote, IProgressMonitor monitor) {
50         Assert.isNotNull(local);
51         Assert.isNotNull(remote);
52         return criteria.compare(local, remote, monitor);
53     }
54     
55     public boolean select(IDiff diff, IProgressMonitor monitor) {
56         IFileRevision remote = SyncInfoToDiffConverter.getRemote(diff);
57         IResource local = ResourceDiffTree.getResourceFor(diff);
58         if (local == null || local.getType() != IResource.FILE) return true;
59         if (remote == null) return !local.exists();
60         if (!local.exists()) return false;
61         return compareContents((IFile)local, remote, monitor);
62     }
63 }
Popular Tags