aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDariusz Luksza2010-08-12 12:23:00 (EDT)
committerDariusz Luksza2010-08-12 12:52:52 (EDT)
commitf23feb5dea9e892a7de17c12b0d01808b86ec435 (patch)
tree7bb0535b6c894a251bed013d78d40088c640ea97
parentfa8447c55c1bd8817df91aea86a6762029fad040 (diff)
downloadegit-f23feb5dea9e892a7de17c12b0d01808b86ec435.zip
egit-f23feb5dea9e892a7de17c12b0d01808b86ec435.tar.gz
egit-f23feb5dea9e892a7de17c12b0d01808b86ec435.tar.bz2
Fire model synchornization in Repositories viewrefs/changes/94/1294/2
Fire Git Model Synchronization instead of Git Synchronization in Repositories view. Change-Id: Ia966df740f80b2799aecd45a2d37c9aae178e917 Signed-off-by: Dariusz Luksza <dariusz@luksza.org>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SynchronizeWithActionHandler.java100
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/SynchronizeCommand.java12
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/GitModelSynchronize.java148
3 files changed, 160 insertions, 100 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SynchronizeWithActionHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SynchronizeWithActionHandler.java
index f869539..3aa129a 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SynchronizeWithActionHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SynchronizeWithActionHandler.java
@@ -17,18 +17,11 @@ import java.util.Set;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.mapping.RemoteResourceMappingContext;
-import org.eclipse.core.resources.mapping.ResourceMapping;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.egit.core.synchronize.GitResourceVariantTreeSubscriber;
-import org.eclipse.egit.core.synchronize.GitSubscriberMergeContext;
-import org.eclipse.egit.core.synchronize.GitSubscriberResourceMappingContext;
import org.eclipse.egit.core.synchronize.dto.GitSynchronizeData;
import org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.UIText;
-import org.eclipse.egit.ui.internal.synchronize.GitModelSynchronizeParticipant;
+import org.eclipse.egit.ui.internal.synchronize.GitModelSynchronize;
import org.eclipse.egit.ui.internal.synchronize.SelectSynchronizeResourceDialog;
import org.eclipse.egit.ui.internal.synchronize.SyncRepoEntity;
import org.eclipse.egit.ui.internal.synchronize.SyncRepoEntity.SyncRefEntity;
@@ -38,16 +31,6 @@ import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefDatabase;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.RemoteConfig;
-import org.eclipse.team.core.RepositoryProvider;
-import org.eclipse.team.core.mapping.provider.SynchronizationContext;
-import org.eclipse.team.core.subscribers.SubscriberScopeManager;
-import org.eclipse.team.internal.ui.TeamUIPlugin;
-import org.eclipse.team.internal.ui.Utils;
-import org.eclipse.team.internal.ui.actions.TeamAction;
-import org.eclipse.team.ui.TeamUI;
-import org.eclipse.team.ui.synchronize.ISynchronizeParticipant;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchPart;
/**
* An action that launch synchronization with selected repository
@@ -84,18 +67,7 @@ public class SynchronizeWithActionHandler extends RepositoryActionHandler {
}
}
- GitResourceVariantTreeSubscriber subscriber = new GitResourceVariantTreeSubscriber(
- gsdSet);
- ResourceMapping[] mappings = getSelectedResourceMappings(event);
- RemoteResourceMappingContext remoteContext = new GitSubscriberResourceMappingContext(gsdSet);
- SubscriberScopeManager manager = new SubscriberScopeManager(
- subscriber.getName(), mappings, subscriber, remoteContext, true);
- SynchronizationContext context = new GitSubscriberMergeContext(
- subscriber, manager, gsdSet);
- GitModelSynchronizeParticipant participant = new GitModelSynchronizeParticipant(context);
- TeamUI.getSynchronizeManager().addSynchronizeParticipants(
- new ISynchronizeParticipant[] { participant });
- participant.run(getTargetPart());
+ GitModelSynchronize.launch(gsdSet, getSelectedResources(event));
return null;
}
@@ -150,72 +122,4 @@ public class SynchronizeWithActionHandler extends RepositoryActionHandler {
return refDb.getRefs(Constants.R_REMOTES + remoteName + "/").values(); //$NON-NLS-1$
}
-
- /**
- * Based on {@link TeamAction#getSelectedResourceMappings}
- *
- * @param event
- * @return the resource mappings that contain resources associated with the given provider
- * @throws ExecutionException
- */
- private ResourceMapping[] getSelectedResourceMappings(ExecutionEvent event) throws ExecutionException {
- Object[] elements = getSelectedResources(event);
- ArrayList providerMappings = new ArrayList();
- for (int i = 0; i < elements.length; i++) {
- Object object = elements[i];
- Object adapted = getResourceMapping(object);
- if (adapted instanceof ResourceMapping) {
- ResourceMapping mapping = (ResourceMapping) adapted;
- if (isMappedToProvider(mapping, "org.eclipse.egit.core.GitProvider")) { //$NON-NLS-1$
- providerMappings.add(mapping);
- }
- }
- }
- return (ResourceMapping[]) providerMappings.toArray(new ResourceMapping[providerMappings.size()]);
- }
-
- /**
- * Copied from TeamAction#getResourceMapping(Object)
- *
- * @param object
- * @return resource mapping
- */
- private Object getResourceMapping(Object object) {
- if (object instanceof ResourceMapping)
- return object;
-
- if (object instanceof IAdaptable)
- return ((IAdaptable) object).getAdapter(ResourceMapping.class);
-
- return Utils.getResourceMapping(object);
- }
-
- /**
- * Copied from TeamAction#isMappedToProvider(ResourceMapping, String)
- *
- * @param element
- * @param providerId
- * @return TODO
- */
- private boolean isMappedToProvider(ResourceMapping element, String providerId) {
- IProject[] projects = element.getProjects();
- for (int k = 0; k < projects.length; k++) {
- IProject project = projects[k];
- RepositoryProvider provider = RepositoryProvider.getProvider(project);
- if (provider != null && provider.getID().equals(providerId)) {
- return true;
- }
- }
- return false;
- }
-
- private IWorkbenchPart getTargetPart() {
- IWorkbenchPart targetPart = null;
- IWorkbenchPage page = TeamUIPlugin.getActivePage();
- if (page != null) {
- targetPart = page.getActivePart();
- }
- return targetPart;
- }
-
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/SynchronizeCommand.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/SynchronizeCommand.java
index e447452..8473566 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/SynchronizeCommand.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/SynchronizeCommand.java
@@ -12,9 +12,12 @@
package org.eclipse.egit.ui.internal.repository.tree.command;
import java.io.IOException;
+import java.util.Set;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
@@ -23,7 +26,7 @@ import org.eclipse.egit.core.Activator;
import org.eclipse.egit.core.synchronize.dto.GitSynchronizeData;
import org.eclipse.egit.ui.UIText;
import org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode;
-import org.eclipse.egit.ui.internal.synchronize.GitSynchronize;
+import org.eclipse.egit.ui.internal.synchronize.GitModelSynchronize;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
@@ -54,7 +57,11 @@ public class SynchronizeCommand extends
data = new GitSynchronizeData(node
.getRepository(), Constants.HEAD, ref.getName(), false);
- new GitSynchronize(data);
+ Set<IProject> projects = data.getProjects();
+ IResource[] resources = projects
+ .toArray(new IResource[projects.size()]);
+
+ GitModelSynchronize.launch(data, resources);
} catch (IOException e) {
Activator.logError(e.getMessage(), e);
}
@@ -67,4 +74,5 @@ public class SynchronizeCommand extends
return null;
}
+
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/GitModelSynchronize.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/GitModelSynchronize.java
new file mode 100644
index 0000000..9521e4e
--- /dev/null
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/GitModelSynchronize.java
@@ -0,0 +1,148 @@
+/*******************************************************************************
+ * Copyright (C) 2010, Dariusz Luksza <dariusz@luksza.org>
+ *
+ * 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
+ *******************************************************************************/
+package org.eclipse.egit.ui.internal.synchronize;
+
+import java.util.ArrayList;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.mapping.RemoteResourceMappingContext;
+import org.eclipse.core.resources.mapping.ResourceMapping;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.egit.core.synchronize.GitResourceVariantTreeSubscriber;
+import org.eclipse.egit.core.synchronize.GitSubscriberMergeContext;
+import org.eclipse.egit.core.synchronize.GitSubscriberResourceMappingContext;
+import org.eclipse.egit.core.synchronize.dto.GitSynchronizeData;
+import org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet;
+import org.eclipse.team.core.RepositoryProvider;
+import org.eclipse.team.core.mapping.provider.SynchronizationContext;
+import org.eclipse.team.core.subscribers.SubscriberScopeManager;
+import org.eclipse.team.internal.ui.TeamUIPlugin;
+import org.eclipse.team.internal.ui.Utils;
+import org.eclipse.team.internal.ui.actions.TeamAction;
+import org.eclipse.team.ui.TeamUI;
+import org.eclipse.team.ui.synchronize.ISynchronizeParticipant;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+
+/**
+ * Utility class that launches model synchronization action
+ */
+public class GitModelSynchronize {
+
+ private GitModelSynchronize() {
+ // non instantiable class
+ }
+
+ /**
+ * Launches Git Model synchronization action
+ *
+ * @param data
+ * @param resources
+ */
+ public static final void launch(GitSynchronizeData data, IResource[] resources) {
+ launch(new GitSynchronizeDataSet(data), resources);
+ }
+
+ /**
+ * Launches Git Model synchronization action
+ *
+ * @param gsdSet
+ * @param resources
+ */
+ public static final void launch(GitSynchronizeDataSet gsdSet,
+ IResource[] resources) {
+ ResourceMapping[] mappings = getSelectedResourceMappings(resources);
+
+ GitResourceVariantTreeSubscriber subscriber = new GitResourceVariantTreeSubscriber(
+ gsdSet);
+ RemoteResourceMappingContext remoteContext = new GitSubscriberResourceMappingContext(
+ gsdSet);
+ SubscriberScopeManager manager = new SubscriberScopeManager(
+ subscriber.getName(), mappings, subscriber, remoteContext, true);
+ SynchronizationContext context = new GitSubscriberMergeContext(
+ subscriber, manager, gsdSet);
+ GitModelSynchronizeParticipant participant = new GitModelSynchronizeParticipant(
+ context);
+
+ TeamUI.getSynchronizeManager().addSynchronizeParticipants(
+ new ISynchronizeParticipant[] { participant });
+ participant.run(getTargetPart());
+ }
+
+ private static IWorkbenchPart getTargetPart() {
+ IWorkbenchPart targetPart = null;
+ IWorkbenchPage page = TeamUIPlugin.getActivePage();
+ if (page != null) {
+ targetPart = page.getActivePart();
+ }
+ return targetPart;
+ }
+
+ /**
+ * Based on {@link TeamAction#getSelectedResourceMappings}
+ *
+ * @param elements
+ * @return the resource mappings that contain resources associated with the
+ * given provider
+ */
+ private static ResourceMapping[] getSelectedResourceMappings(IResource[] elements) {
+ ArrayList providerMappings = new ArrayList();
+ for (int i = 0; i < elements.length; i++) {
+ Object object = elements[i];
+ Object adapted = getResourceMapping(object);
+ if (adapted instanceof ResourceMapping) {
+ ResourceMapping mapping = (ResourceMapping) adapted;
+ if (isMappedToProvider(mapping,
+ "org.eclipse.egit.core.GitProvider")) { //$NON-NLS-1$
+ providerMappings.add(mapping);
+ }
+ }
+ }
+ return (ResourceMapping[]) providerMappings
+ .toArray(new ResourceMapping[providerMappings.size()]);
+ }
+
+ /**
+ * Copied from TeamAction#getResourceMapping(Object)
+ *
+ * @param object
+ * @return resource mapping
+ */
+ private static Object getResourceMapping(Object object) {
+ if (object instanceof ResourceMapping)
+ return object;
+
+ if (object instanceof IAdaptable)
+ return ((IAdaptable) object).getAdapter(ResourceMapping.class);
+
+ return Utils.getResourceMapping(object);
+ }
+
+ /**
+ * Copied from TeamAction#isMappedToProvider(ResourceMapping, String)
+ *
+ * @param element
+ * @param providerId
+ * @return TODO
+ */
+ private static boolean isMappedToProvider(ResourceMapping element,
+ String providerId) {
+ IProject[] projects = element.getProjects();
+ for (int k = 0; k < projects.length; k++) {
+ IProject project = projects[k];
+ RepositoryProvider provider = RepositoryProvider
+ .getProvider(project);
+ if (provider != null && provider.getID().equals(providerId)) {
+ return true;
+ }
+ }
+ return false;
+ }
+}