Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjames2002-05-18 14:14:24 -0400
committerjames2002-05-18 14:14:24 -0400
commit977489f80f83325967bacb68cc2cd341432f423d (patch)
treecbf333908e5f7ffb99a7f2860f435f946ab6124d
parent156238c4a701cb1c0061f3e9a1a2074885237ad0 (diff)
downloadeclipse.platform.team-977489f80f83325967bacb68cc2cd341432f423d.tar.gz
eclipse.platform.team-977489f80f83325967bacb68cc2cd341432f423d.tar.xz
eclipse.platform.team-977489f80f83325967bacb68cc2cd341432f423d.zip
Initial release
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/target/GetSyncAction.java92
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/target/PutSyncAction.java88
2 files changed, 180 insertions, 0 deletions
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/target/GetSyncAction.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/target/GetSyncAction.java
new file mode 100644
index 000000000..451186a8d
--- /dev/null
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/target/GetSyncAction.java
@@ -0,0 +1,92 @@
+package org.eclipse.team.internal.ui.target;
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.team.core.TeamException;
+import org.eclipse.team.core.target.TargetManager;
+import org.eclipse.team.core.target.TargetProvider;
+import org.eclipse.team.internal.ui.Policy;
+import org.eclipse.team.internal.ui.TeamUIPlugin;
+import org.eclipse.team.internal.ui.sync.ITeamNode;
+import org.eclipse.team.internal.ui.sync.SyncSet;
+
+public class GetSyncAction extends TargetSyncAction {
+
+ public GetSyncAction(TargetSyncCompareInput model, ISelectionProvider sp, String label, Shell shell) {
+ super(model, sp, label, shell);
+ }
+
+ /**
+ * @see TargetSyncAction#isEnabled(ITeamNode)
+ */
+ protected boolean isEnabled(ITeamNode node) {
+ // The update action is enabled only for non-conflicting incoming changes
+ return new SyncSet(new StructuredSelection(node)).hasIncomingChanges();
+ }
+
+ /**
+ * @see TargetSyncAction#removeNonApplicableNodes(SyncSet, int)
+ */
+ protected void removeNonApplicableNodes(SyncSet set, int syncMode) {
+ set.removeConflictingNodes();
+ set.removeOutgoingNodes();
+ }
+
+ /**
+ * @see TargetSyncAction#run(SyncSet, IProgressMonitor)
+ */
+ protected SyncSet run(SyncSet syncSet, IProgressMonitor monitor) {
+ try {
+ ITeamNode[] changed = syncSet.getChangedNodes();
+ if (changed.length == 0) {
+ return syncSet;
+ }
+ List resources = new ArrayList();
+ for (int i = 0; i < changed.length; i++) {
+ resources.add(changed[i].getResource());
+ }
+ get((IResource[])resources.toArray(new IResource[resources.size()]), monitor);
+ } catch (final TeamException e) {
+ getShell().getDisplay().syncExec(new Runnable() {
+ public void run() {
+ ErrorDialog.openError(getShell(), null, null, e.getStatus());
+ }
+ });
+ return null;
+ }
+ return syncSet;
+ }
+
+ /**
+ * Put the given resources to their associated providers.
+ *
+ * @param resources the resources to commit
+ * @param monitor the progress monitor
+ */
+ public void get(IResource[] resources, IProgressMonitor monitor) throws TeamException {
+ Hashtable table = getTargetProviderMapping(resources);
+ Set keySet = table.keySet();
+ monitor.beginTask("", keySet.size() * 1000); //$NON-NLS-1$
+ monitor.setTaskName("Getting...");
+ Iterator iterator = keySet.iterator();
+ while (iterator.hasNext()) {
+ IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1000);
+ TargetProvider provider = (TargetProvider)iterator.next();
+ List list = (List)table.get(provider);
+ IResource[] providerResources = (IResource[])list.toArray(new IResource[list.size()]);
+ provider.get(providerResources, subMonitor);
+ }
+ }
+}
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/target/PutSyncAction.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/target/PutSyncAction.java
new file mode 100644
index 000000000..e34ed7ec5
--- /dev/null
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/target/PutSyncAction.java
@@ -0,0 +1,88 @@
+package org.eclipse.team.internal.ui.target;
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.team.core.TeamException;
+import org.eclipse.team.core.target.TargetProvider;
+import org.eclipse.team.internal.ui.sync.ITeamNode;
+import org.eclipse.team.internal.ui.sync.SyncSet;
+
+public class PutSyncAction extends TargetSyncAction {
+
+ public PutSyncAction(TargetSyncCompareInput model, ISelectionProvider sp, String label, Shell shell) {
+ super(model, sp, label, shell);
+ }
+
+ /**
+ * @see TargetSyncAction#isEnabled(ITeamNode)
+ */
+ protected boolean isEnabled(ITeamNode node) {
+ // The update action is enabled only for non-conflicting incoming changes
+ return new SyncSet(new StructuredSelection(node)).hasOutgoingChanges();
+ }
+
+ /**
+ * @see TargetSyncAction#removeNonApplicableNodes(SyncSet, int)
+ */
+ protected void removeNonApplicableNodes(SyncSet set, int syncMode) {
+ set.removeConflictingNodes();
+ set.removeIncomingNodes();
+ }
+
+ /**
+ * @see TargetSyncAction#run(SyncSet, IProgressMonitor)
+ */
+ protected SyncSet run(SyncSet syncSet, IProgressMonitor monitor) {
+ try {
+ ITeamNode[] changed = syncSet.getChangedNodes();
+ if (changed.length == 0) {
+ return syncSet;
+ }
+ List resources = new ArrayList();
+ for (int i = 0; i < changed.length; i++) {
+ resources.add(changed[i].getResource());
+ }
+ put((IResource[])resources.toArray(new IResource[resources.size()]), monitor);
+ } catch (final TeamException e) {
+ getShell().getDisplay().syncExec(new Runnable() {
+ public void run() {
+ ErrorDialog.openError(getShell(), null, null, e.getStatus());
+ }
+ });
+ return null;
+ }
+ return syncSet;
+ }
+
+ /**
+ * Put the given resources to their associated providers.
+ *
+ * @param resources the resources to commit
+ * @param monitor the progress monitor
+ */
+ public void put(IResource[] resources, IProgressMonitor monitor) throws TeamException {
+ Hashtable table = getTargetProviderMapping(resources);
+ Set keySet = table.keySet();
+ monitor.beginTask("", keySet.size() * 1000); //$NON-NLS-1$
+ monitor.setTaskName("Putting...");
+ Iterator iterator = keySet.iterator();
+ while (iterator.hasNext()) {
+ IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1000);
+ TargetProvider provider = (TargetProvider)iterator.next();
+ List list = (List)table.get(provider);
+ IResource[] providerResources = (IResource[])list.toArray(new IResource[list.size()]);
+ provider.put(providerResources, subMonitor);
+ }
+ }
+}

Back to the top