Initial EGit contribution to eclipse.org
[egit.git] / org.eclipse.egit.core / src / org / eclipse / egit / core / op / DisconnectProviderOperation.java
blob6f2b9ee07a891de7c83b0a0970a71b0ed0d65165
1 /*******************************************************************************
2 * Copyright (C) 2007, Shawn O. Pearce <spearce@spearce.org>
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
9 package org.eclipse.egit.core.op;
11 import java.util.Collection;
13 import org.eclipse.core.resources.IContainer;
14 import org.eclipse.core.resources.IProject;
15 import org.eclipse.core.resources.IResource;
16 import org.eclipse.core.resources.IWorkspaceRunnable;
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.core.runtime.IAdaptable;
19 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.eclipse.core.runtime.NullProgressMonitor;
21 import org.eclipse.core.runtime.SubProgressMonitor;
22 import org.eclipse.egit.core.Activator;
23 import org.eclipse.egit.core.CoreText;
24 import org.eclipse.team.core.RepositoryProvider;
26 /**
27 * Disconnects the Git team provider from a project.
28 * <p>
29 * Once disconnected, Git operations will no longer be available on the project.
30 * </p>
32 public class DisconnectProviderOperation implements IWorkspaceRunnable {
33 private final Collection projectList;
35 /**
36 * Create a new disconnect operation.
38 * @param projs
39 * the collection of {@link IProject}s which should be
40 * disconnected from the Git team provider, and returned to
41 * untracked/unmanaged status.
43 public DisconnectProviderOperation(final Collection projs) {
44 projectList = projs;
47 public void run(IProgressMonitor m) throws CoreException {
48 if (m == null) {
49 m = new NullProgressMonitor();
52 m.beginTask(CoreText.DisconnectProviderOperation_disconnecting,
53 projectList.size() * 200);
54 try {
55 for (Object obj : projectList) {
56 obj = ((IAdaptable)obj).getAdapter(IResource.class);
57 if (obj instanceof IProject) {
58 final IProject p = (IProject) obj;
60 Activator.trace("disconnect " + p.getName());
61 unmarkTeamPrivate(p);
62 RepositoryProvider.unmap(p);
63 m.worked(100);
65 p.refreshLocal(IResource.DEPTH_INFINITE,
66 new SubProgressMonitor(m, 100));
67 } else {
68 m.worked(200);
71 } finally {
72 m.done();
76 private void unmarkTeamPrivate(final IContainer p) throws CoreException {
77 final IResource[] c;
78 c = p.members(IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS);
79 if (c != null) {
80 for (int k = 0; k < c.length; k++) {
81 if (c[k] instanceof IContainer) {
82 unmarkTeamPrivate((IContainer) c[k]);
84 if (c[k].isTeamPrivateMember()) {
85 Activator.trace("notTeamPrivate " + c[k]);
86 c[k].setTeamPrivateMember(false);