Skip to main content
summaryrefslogtreecommitdiffstats
blob: 7df9ea35e1d5fc9b07b0b4631002fa7ee13e1000 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package org.eclipse.team.core.sync;
  
/*
 * (c) Copyright IBM Corp. 2000, 2001.
 * All Rights Reserved.
 */

import java.io.IOException;
import java.io.InputStream;

import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.team.core.TeamException;

/**
 * A standard abstract class that provides implementations for <code>ILocalSyncElement</code>
 * methods.
 */
public abstract class LocalSyncElement implements ILocalSyncElement {

	/**
	 * Creates a client specific sync element from a <b>local</b> and <b>base</b>
	 * resources. The <b>base</b> resource may be <code>null</code> and should be
	 * intialized by the client if available.
	 * 
	 * @param local the local resource in the workbench. Will never be <code>null</code>.
	 * @param base the base resource, may me <code>null</code>.
	 * @param data client specific data.
	 * 
	 * @return a client specific sync element.
	 */
	public abstract ILocalSyncElement create(IResource local, IRemoteResource base, Object data);
	
	/**
	 * Client data that is passed to every <code>create()</code> call.
	 * 
	 * @return client specific data that will be passed to create.
	 */
	protected abstract Object getData();
	
	/**
	 * Client can decide is a specific element should be ignored from this sync element's
	 * children.
	 * 
	 * @param resource the resource to be queried.
	 * 
	 * @return <code>true</code> if this element should be ignored and not considered an 
	 * immediate child of this element, and <code>false</code> otherwise.
	 */
	protected abstract boolean isIgnored(IResource resource);

	/*
	 * @see ILocalSyncElement#getSyncKind(int, IProgressMonitor)
	 */
	public int getSyncKind(int granularity, IProgressMonitor progress) {
				
		// XXX not sure how local sync will be used?
		int sync = IN_SYNC;		
		return sync;
	}
			
	/*
	 * @see ILocalSyncElement#getName()
	 */
	public String getName() {
		return getLocal().getName();
	}

	/*
	 * @see ILocalSyncElement#isContainer()
	 */
	public boolean isContainer() {
		return getLocal().getType() != IResource.FILE;
	}

	/*
	 * @see ILocalSyncElement#members(IProgressMonitor)
	 */
	public ILocalSyncElement[] members(IProgressMonitor monitor) throws TeamException {
		try {
			if(getLocal().getType() != IResource.FILE) {
				IResource[] members = ((IContainer)getLocal()).members();
				List syncElements = new ArrayList(5);
				for (int i = 0; i < members.length; i++) {
					IResource iResource = members[i];
					// the base is initialy set to null, however the concrete subclass should
					// initialize the base if one is available.
					if(!isIgnored(iResource)) {
						syncElements.add(create(iResource, null, getData()));
					}
				}
				return (ILocalSyncElement[]) syncElements.toArray(new ILocalSyncElement[syncElements.size()]);		
			} else {
				return new ILocalSyncElement[0];
			}
		} catch(CoreException e) {
			throw new TeamException(e.getStatus());
		}
	}
}

Back to the top