Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 5331a4b09044ff73f282490513c844df7e504693 (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
105
106
107
108
109
110
111
112
/*******************************************************************************
 * Copyright (c) 2000, 2017 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.internal.core.subscribers;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.resources.mapping.ResourceMapping;
import org.eclipse.core.resources.mapping.ResourceMappingContext;
import org.eclipse.core.resources.mapping.ResourceTraversal;
import org.eclipse.team.core.mapping.ISynchronizationScope;
import org.eclipse.team.internal.core.mapping.AbstractResourceMappingScope;

/**
 * A synchronization scope for a set of resources.
 */
public class RootResourceSynchronizationScope extends AbstractResourceMappingScope {

	private IResource[] roots;

	public RootResourceSynchronizationScope(IResource[] roots) {
		this.roots = roots;
	}

	@Override
	public ResourceTraversal[] getTraversals() {
		return new ResourceTraversal[] {new ResourceTraversal(roots, IResource.DEPTH_INFINITE, IResource.NONE)};
	}

	/**
	 * Set the traversal of this scope to a single traversal
	 * of infinite depth on the given resources.
	 * @param roots the new roots of the scope
	 */
	public void setRoots(IResource[] roots) {
		this.roots = roots;
		fireTraversalsChangedEvent(getTraversals(), getMappings());
	}

	@Override
	public ResourceMapping[] getInputMappings() {
		return getMappings();
	}

	@Override
	public ISynchronizationScope asInputScope() {
		return this;
	}

	@Override
	public ResourceMapping[] getMappings() {
		List<ResourceMapping> result = new ArrayList<>();
		for (int i = 0; i < roots.length; i++) {
			IResource resource = roots[i];
			Object o = resource.getAdapter(ResourceMapping.class);
			if (o instanceof ResourceMapping) {
				result.add((ResourceMapping) o);
			}
		}
		return result.toArray(new ResourceMapping[result.size()]);
	}

	@Override
	public ResourceTraversal[] getTraversals(ResourceMapping mapping) {
		Object object = mapping.getModelObject();
		if (object instanceof IResource) {
			IResource resource = (IResource) object;
			return new ResourceTraversal[] {new ResourceTraversal(new IResource[] { resource }, IResource.DEPTH_INFINITE, IResource.NONE)};
		}
		return null;
	}

	@Override
	public boolean hasAdditionalMappings() {
		return false;
	}

	@Override
	public boolean hasAdditonalResources() {
		return false;
	}

	@Override
	public IProject[] getProjects() {
		return ResourcesPlugin.getWorkspace().getRoot().getProjects();
	}

	@Override
	public ResourceMappingContext getContext() {
		return ResourceMappingContext.LOCAL_CONTEXT;
	}

	@Override
	public void refresh(ResourceMapping[] mappings) {
		// Not supported
	}

}

Back to the top