Skip to main content
summaryrefslogtreecommitdiffstats
blob: b5e277a762e52d678e7dd60f83bcaf291af66c1b (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
/*******************************************************************************
 * Copyright (c) 2015 Obeo.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     Obeo - initial API and implementation
 *******************************************************************************/
package org.eclipse.emf.compare.ide.ui.internal.logical.resolver;

import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.concurrent.Callable;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.compare.ide.utils.StorageTraversal;

/**
 * This will be called by Team in order to determine whether a given file can be compared alone, or if it
 * needs to be compared along with others (and, thus, compared from the synchronize view). Note that only
 * local data is available here.
 * 
 * @author <a href="mailto:laurent.delaigue@obeo.fr">Laurent Delaigue</a>
 */
public class LocalModelResolution extends AbstractResolution {
	/** The local resolver. */
	private final IResourceDependencyLocalResolver resolver;

	/**
	 * Constructor.
	 * 
	 * @param dependencyProvider
	 *            The dependency provider
	 * @param scheduler
	 *            multi-thread support to use
	 * @param eventBus
	 *            The event bus
	 * @param monitor
	 *            Progress monitor to use
	 */
	public LocalModelResolution(IResolutionContext context, IProgressMonitor monitor) {
		super(context, monitor);
		this.resolver = context.getLocalResolver();
	}

	/**
	 * Executes this treatment.
	 * 
	 * @param start
	 *            Resource for which we want the traversal
	 * @return The {@link StorageTraversal} for the given resource, never null but possibly empty.
	 * @throws InterruptedException
	 *             If the computation is interrupted.
	 */
	public StorageTraversal run(final IResource start) throws InterruptedException {
		if (logger.isDebugEnabled()) {
			logger.debug("run() - START"); //$NON-NLS-1$
		}
		if (!(start instanceof IFile)) {
			if (logger.isDebugEnabled()) {
				logger.debug("run() - FINISH"); //$NON-NLS-1$
			}
			return new StorageTraversal(new LinkedHashSet<IStorage>());
		}
		return call(new Callable<StorageTraversal>() {
			public StorageTraversal call() throws InterruptedException {
				resolver.updateDependencies(monitor, diagnostic, (IFile)start);

				if (monitor.isCanceled()) {
					throw new OperationCanceledException();
				}

				final Set<IStorage> traversalSet = resolveTraversal((IFile)start, Collections
						.<URI> emptySet());
				StorageTraversal traversal = new StorageTraversal(traversalSet, diagnostic.getDiagnostic());
				if (logger.isDebugEnabled()) {
					logger.debug("run() - FINISH"); //$NON-NLS-1$
				}
				return traversal;
			}
		});
	}
}

Back to the top