Multi-project connect to Git provider
[egit/imyousuf.git] / org.spearce.egit.core / src / org / spearce / egit / core / op / DisconnectProviderOperation.java
blobb63c69bca8e2a5104a34a498b6b80d2095c56631
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 * See LICENSE for the full license text, also available.
7 *******************************************************************************/
8 package org.spearce.egit.core.op;
10 import java.util.Collection;
12 import org.eclipse.core.resources.IContainer;
13 import org.eclipse.core.resources.IProject;
14 import org.eclipse.core.resources.IResource;
15 import org.eclipse.core.resources.IWorkspaceRunnable;
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.IAdaptable;
18 import org.eclipse.core.runtime.IProgressMonitor;
19 import org.eclipse.core.runtime.NullProgressMonitor;
20 import org.eclipse.core.runtime.SubProgressMonitor;
21 import org.eclipse.team.core.RepositoryProvider;
22 import org.spearce.egit.core.Activator;
23 import org.spearce.egit.core.CoreText;
25 /**
26 * Disconnects the Git team provider from a project.
27 * <p>
28 * Once disconnected, Git operations will no longer be available on the project.
29 * </p>
31 public class DisconnectProviderOperation implements IWorkspaceRunnable {
32 private final Collection projectList;
34 /**
35 * Create a new disconnect operation.
37 * @param projs
38 * the collection of {@link IProject}s which should be
39 * disconnected from the Git team provider, and returned to
40 * untracked/unmanaged status.
42 public DisconnectProviderOperation(final Collection projs) {
43 projectList = projs;
46 public void run(IProgressMonitor m) throws CoreException {
47 if (m == null) {
48 m = new NullProgressMonitor();
51 m.beginTask(CoreText.DisconnectProviderOperation_disconnecting,
52 projectList.size() * 200);
53 try {
54 for (Object obj : projectList) {
55 obj = ((IAdaptable)obj).getAdapter(IResource.class);
56 if (obj instanceof IProject) {
57 final IProject p = (IProject) obj;
59 Activator.trace("disconnect " + p.getName());
60 unmarkTeamPrivate(p);
61 RepositoryProvider.unmap(p);
62 m.worked(100);
64 p.refreshLocal(IResource.DEPTH_INFINITE,
65 new SubProgressMonitor(m, 100));
66 } else {
67 m.worked(200);
70 } finally {
71 m.done();
75 private void unmarkTeamPrivate(final IContainer p) throws CoreException {
76 final IResource[] c;
77 c = p.members(IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS);
78 if (c != null) {
79 for (int k = 0; k < c.length; k++) {
80 if (c[k] instanceof IContainer) {
81 unmarkTeamPrivate((IContainer) c[k]);
83 if (c[k].isTeamPrivateMember()) {
84 Activator.trace("notTeamPrivate " + c[k]);
85 c[k].setTeamPrivateMember(false);