Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2004-03-09 21:59:42 +0000
committerMichael Valenta2004-03-09 21:59:42 +0000
commitbe1ecfd92fd599cfa15d9a1fe127d049852796f5 (patch)
treea644d319de2479c72d15042159c4cba1c04eb9aa
parent70d8db4a04629905c0aefa376adfc27566b12c73 (diff)
downloadeclipse.platform.team-be1ecfd92fd599cfa15d9a1fe127d049852796f5.tar.gz
eclipse.platform.team-be1ecfd92fd599cfa15d9a1fe127d049852796f5.tar.xz
eclipse.platform.team-be1ecfd92fd599cfa15d9a1fe127d049852796f5.zip
Refactoring SubscriberActionRoot_branch_I20040315
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIPlugin.java1
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/CompareWithRevisionAction.java6
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/operations/CVSOperation.java12
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/CVSSubscriberOperation.java (renamed from bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/CVSSubscriberAction.java)107
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/CompareRevertAction.java87
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/CompareRevertOperation.java105
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/MergeUpdateAction.java145
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/MergeUpdateOperation.java157
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/OverrideAndCommitAction.java33
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/OverrideAndUpdateAction.java56
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/OverrideAndUpdateSubscriberOperation.java65
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/SafeUpdateOperation.java (renamed from bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/SafeUpdateAction.java)118
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/SubscriberCommitAction.java269
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/SubscriberCommitOperation.java314
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/SubscriberConfirmMergedAction.java78
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/SubscriberConfirmMergedOperation.java90
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/WorkspaceUpdateAction.java86
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/WorkspaceUpdateOperation.java99
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/wizards/SharingWizard.java33
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/Utils.java18
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/ITeamRunnableContext.java8
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/JobRunnableContext.java119
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/ProgressDialogRunnableContext.java97
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/SubscriberAction.java228
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/SubscriberOperation.java103
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/TeamOperation.java154
-rw-r--r--tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/CVSMergeSubscriberTest.java13
-rw-r--r--tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/CVSSyncSubscriberTest.java15
-rw-r--r--tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/CVSWorkspaceSubscriberTest.java40
-rw-r--r--tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/TestCommitAction.java35
-rw-r--r--tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/TestCommitOperation.java (renamed from tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/TestOverrideAndCommit.java)45
-rw-r--r--tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/TestMarkAsMergedAction.java25
-rw-r--r--tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/TestMergeUpdateOperation.java (renamed from tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/TestMergeUpdateAction.java)24
-rw-r--r--tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/TestOverrideAndUpdateOperation.java (renamed from tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/TestOverrideAndUpdate.java)36
-rw-r--r--tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/TestUpdateOperation.java (renamed from tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/TestUpdateAction.java)30
-rw-r--r--tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/HeadlessCVSRunnableContext.java10
36 files changed, 1658 insertions, 1203 deletions
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIPlugin.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIPlugin.java
index 4205d12c1..57b773c11 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIPlugin.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIPlugin.java
@@ -42,7 +42,6 @@ import org.eclipse.team.internal.ui.TeamUIPlugin;
import org.eclipse.team.internal.ui.Utils;
import org.eclipse.team.ui.TeamUI;
import org.eclipse.team.ui.synchronize.ISynchronizeParticipant;
-import org.eclipse.team.ui.synchronize.ISynchronizeView;
import org.eclipse.ui.*;
import org.eclipse.ui.console.ConsolePlugin;
import org.eclipse.ui.console.IConsole;
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/CompareWithRevisionAction.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/CompareWithRevisionAction.java
index dd474d785..deff2334f 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/CompareWithRevisionAction.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/actions/CompareWithRevisionAction.java
@@ -12,7 +12,6 @@ package org.eclipse.team.internal.ccvs.ui.actions;
import java.lang.reflect.InvocationTargetException;
-import org.eclipse.compare.CompareUI;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -22,10 +21,7 @@ import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.team.core.TeamException;
-import org.eclipse.team.internal.ccvs.core.CVSException;
-import org.eclipse.team.internal.ccvs.core.ICVSRemoteFile;
-import org.eclipse.team.internal.ccvs.core.ICVSResource;
-import org.eclipse.team.internal.ccvs.core.ILogEntry;
+import org.eclipse.team.internal.ccvs.core.*;
import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
import org.eclipse.team.internal.ccvs.ui.CVSCompareRevisionsInput;
import org.eclipse.team.internal.ccvs.ui.Policy;
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/operations/CVSOperation.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/operations/CVSOperation.java
index b4a480786..f186ccc1d 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/operations/CVSOperation.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/operations/CVSOperation.java
@@ -66,7 +66,7 @@ public abstract class CVSOperation implements IRunnableWithProgress {
*/
public synchronized void run() throws CVSException, InterruptedException {
try {
- getCVSRunnableContext().run(getTaskName(), getSchedulingRule(), getPostponeBuild(), this);
+ getCVSRunnableContext().run(this);
} catch (InvocationTargetException e) {
throw CVSException.wrapException(e);
} catch (OperationCanceledException e) {
@@ -152,9 +152,15 @@ public abstract class CVSOperation implements IRunnableWithProgress {
private ITeamRunnableContext getCVSRunnableContext() {
if (cvsRunnableContext == null) {
if (canRunAsJob() && areJobsEnabled()) {
- return new JobRunnableContext();
+ JobRunnableContext context = new JobRunnableContext(getTaskName());
+ context.setPostponeBuild(getPostponeBuild());
+ context.setSchedulingRule(getSchedulingRule());
+ return context;
} else {
- return new ProgressDialogRunnableContext(shell);
+ ProgressDialogRunnableContext context = new ProgressDialogRunnableContext(shell);
+ context.setPostponeBuild(getPostponeBuild());
+ context.setSchedulingRule(getSchedulingRule());
+ return context;
}
}
return cvsRunnableContext;
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/CVSSubscriberAction.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/CVSSubscriberOperation.java
index 6463d0876..ee24e199c 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/CVSSubscriberAction.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/CVSSubscriberOperation.java
@@ -11,16 +11,16 @@
package org.eclipse.team.internal.ccvs.ui.subscriber;
import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.*;
+import org.eclipse.compare.structuremergeviewer.IDiffElement;
import org.eclipse.core.resources.*;
import org.eclipse.core.runtime.*;
import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.team.core.TeamException;
-import org.eclipse.team.core.synchronize.*;
-import org.eclipse.team.core.variants.*;
+import org.eclipse.team.core.synchronize.SyncInfo;
+import org.eclipse.team.core.synchronize.SyncInfoSet;
+import org.eclipse.team.core.variants.IResourceVariant;
import org.eclipse.team.internal.ccvs.core.*;
import org.eclipse.team.internal.ccvs.core.client.PruneFolderVisitor;
import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
@@ -28,10 +28,51 @@ import org.eclipse.team.internal.ccvs.core.resources.EclipseSynchronizer;
import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
import org.eclipse.team.internal.ccvs.ui.Policy;
import org.eclipse.team.internal.ui.TeamUIPlugin;
-import org.eclipse.team.internal.ui.actions.SubscriberAction;
+import org.eclipse.team.internal.ui.actions.SubscriberOperation;
+import org.eclipse.ui.IWorkbenchPart;
-public abstract class CVSSubscriberAction extends SubscriberAction {
+public abstract class CVSSubscriberOperation extends SubscriberOperation {
+ protected CVSSubscriberOperation(IWorkbenchPart part, IDiffElement[] elements) {
+ super(part, elements);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ // Divide the sync info by project
+ final Map projectSyncInfos = getProjectSyncInfoSetMap();
+ for (Iterator iter = projectSyncInfos.keySet().iterator(); iter.hasNext(); ) {
+ final IProject project = (IProject) iter.next();
+ try {
+ // Pass the scheduling rule to the synchronizer so that sync change events
+ // and cache commits to disk are batched
+ EclipseSynchronizer.getInstance().run(
+ project,
+ new ICVSRunnable() {
+ public void run(IProgressMonitor monitor) throws CVSException {
+ try {
+ CVSSubscriberOperation.this.run((SyncInfoSet)projectSyncInfos.get(project), monitor);
+ } catch (TeamException e) {
+ throw CVSException.wrapException(e);
+ }
+ }
+ }, monitor);
+ } catch (TeamException e) {
+ throw new InvocationTargetException(e);
+ }
+ }
+ }
+
+ /**
+ * Run the operation on the sync info in the given set. The sync info will be all
+ * from the same project.
+ * @param set the sync info set
+ * @param monitor a progress monitor
+ */
+ protected abstract void run(SyncInfoSet set, IProgressMonitor monitor) throws TeamException;
+
/*
* Indicate that the resource is out of sync if the sync state is not IN_SYNC
* or if the local doesn't exist but the remote does.
@@ -135,38 +176,6 @@ public abstract class CVSSubscriberAction extends SubscriberAction {
return null;
}
- /**
- * Return an IRunnableWithProgress that will operate on the given sync set.
- * This method is invoked by <code>run(IAction)</code> when the action is
- * executed from a menu. The default implementation invokes the method
- * <code>run(SyncInfoSet, IProgressMonitor)</code>.
- * @param syncSet
- * @return
- */
- public IRunnableWithProgress getRunnable(final SyncInfoSet syncSet) {
- return new IRunnableWithProgress() {
- public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
- try {
- // Pass the scheduling rule to the synchronizer so that sync change events
- // and cache commits to disk are batched
- EclipseSynchronizer.getInstance().run(
- getSchedulingRule(syncSet),
- new ICVSRunnable() {
- public void run(IProgressMonitor monitor) throws CVSException {
- try {
- CVSSubscriberAction.this.run(syncSet, monitor);
- } catch (TeamException e) {
- throw CVSException.wrapException(e);
- }
- }
- }, monitor);
- } catch (TeamException e) {
- throw new InvocationTargetException(e);
- }
- }
- };
- }
-
protected boolean canRunAsJob() {
return true;
}
@@ -282,4 +291,24 @@ public abstract class CVSSubscriberAction extends SubscriberAction {
}
return true;
}
+
+ /*
+ * Divide the sync info for the operation by project
+ */
+ private Map getProjectSyncInfoSetMap() {
+ Map map = new HashMap();
+ SyncInfoSet all = getSyncInfoSet();
+ SyncInfo[] infos = all.getSyncInfos();
+ for (int i = 0; i < infos.length; i++) {
+ SyncInfo info = infos[i];
+ IProject project = info.getLocal().getProject();
+ SyncInfoSet set = (SyncInfoSet)map.get(project);
+ if (set == null) {
+ set = new SyncInfoSet();
+ map.put(project, set);
+ }
+ set.add(info);
+ }
+ return map;
+ }
}
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/CompareRevertAction.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/CompareRevertAction.java
index d4ac7fe78..1612e89b0 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/CompareRevertAction.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/CompareRevertAction.java
@@ -10,92 +10,21 @@
*******************************************************************************/
package org.eclipse.team.internal.ccvs.ui.subscriber;
-import java.util.*;
-
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.team.core.TeamException;
-import org.eclipse.team.core.synchronize.SyncInfo;
-import org.eclipse.team.core.synchronize.SyncInfoSet;
-import org.eclipse.team.internal.ccvs.ui.Policy;
+import org.eclipse.compare.structuremergeviewer.IDiffElement;
+import org.eclipse.team.internal.ui.actions.SubscriberAction;
+import org.eclipse.team.internal.ui.actions.SubscriberOperation;
+import org.eclipse.ui.IWorkbenchPart;
/**
* Action in compare editor that reverts the local contents to match the contents on the server.
*/
-public class CompareRevertAction extends CVSSubscriberAction {
+public class CompareRevertAction extends SubscriberAction {
/* (non-Javadoc)
- * @see org.eclipse.team.internal.ccvs.ui.subscriber.CVSSubscriberAction#run(org.eclipse.team.core.subscribers.MutableSyncInfoSet, org.eclipse.core.runtime.IProgressMonitor)
+ * @see org.eclipse.team.internal.ui.actions.SubscriberAction#getSubscriberOperation(org.eclipse.compare.structuremergeviewer.IDiffElement[])
*/
- protected void run(SyncInfoSet syncSet, IProgressMonitor monitor) throws TeamException {
- SyncInfo[] changed = syncSet.getSyncInfos();
- if (changed.length == 0) return;
-
- // The list of sync resources to be updated using "cvs update"
- List updateShallow = new ArrayList();
- // A list of sync resource folders which need to be created locally
- // (incoming addition or previously pruned)
- Set parentCreationElements = new HashSet();
-
- for (int i = 0; i < changed.length; i++) {
- SyncInfo changedNode = changed[i];
-
- // Make sure that parent folders exist
- SyncInfo parent = getParent(changedNode);
- if (parent != null && isOutOfSync(parent)) {
- // We need to ensure that parents that are either incoming folder additions
- // or previously pruned folders are recreated.
- parentCreationElements.add(parent);
- }
-
- IResource resource = changedNode.getLocal();
- if (resource.getType() == IResource.FILE) {
- if (changedNode.getLocal().exists()) {
- updateShallow.add(changedNode);
- } else if (changedNode.getRemote() != null) {
- updateShallow.add(changedNode);
- }
- } else {
- // Special handling for folders to support shallow operations on files
- // (i.e. folder operations are performed using the sync info already
- // contained in the sync info.
- if (isOutOfSync(changedNode)) {
- parentCreationElements.add(changedNode);
- }
- }
-
- }
- try {
- // Calculate the total amount of work needed
- int work = updateShallow.size() * 100;
- monitor.beginTask(null, work);
-
- if (parentCreationElements.size() > 0) {
- makeInSync((SyncInfo[]) parentCreationElements.toArray(new SyncInfo[parentCreationElements.size()]));
- }
- if (updateShallow.size() > 0) {
- runUpdate((SyncInfo[])updateShallow.toArray(new SyncInfo[updateShallow.size()]), Policy.subMonitorFor(monitor, updateShallow.size() * 100));
- }
- } finally {
- monitor.done();
- }
- return;
- }
-
- private void runUpdate(SyncInfo[] infos, IProgressMonitor monitor) throws TeamException {
- monitor.beginTask(null, 100 * infos.length);
- for (int i = 0; i < infos.length; i++) {
- SyncInfo info = infos[i];
- makeRemoteLocal(info, Policy.subMonitorFor(monitor, 100));
- }
- monitor.done();
+ protected SubscriberOperation getSubscriberOperation(IWorkbenchPart part, IDiffElement[] elements) {
+ return new CompareRevertOperation(part, elements);
}
-
- /* (non-Javadoc)
- * @see org.eclipse.team.internal.ccvs.ui.subscriber.CVSSubscriberAction#getJobName(org.eclipse.team.core.subscribers.SyncInfoSet)
- */
- protected String getJobName(SyncInfoSet syncSet) {
- return Policy.bind("CompareRevertAction.0", new Integer(syncSet.size()).toString()); //$NON-NLS-1$
- }
}
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/CompareRevertOperation.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/CompareRevertOperation.java
new file mode 100644
index 000000000..12f54b6d4
--- /dev/null
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/CompareRevertOperation.java
@@ -0,0 +1,105 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.team.internal.ccvs.ui.subscriber;
+
+import java.util.*;
+
+import org.eclipse.compare.structuremergeviewer.IDiffElement;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.core.TeamException;
+import org.eclipse.team.core.synchronize.SyncInfo;
+import org.eclipse.team.core.synchronize.SyncInfoSet;
+import org.eclipse.team.internal.ccvs.ui.Policy;
+import org.eclipse.ui.IWorkbenchPart;
+
+
+public class CompareRevertOperation extends CVSSubscriberOperation {
+ protected CompareRevertOperation(IWorkbenchPart part, IDiffElement[] elements) {
+ super(part, elements);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ccvs.ui.subscriber.CVSSubscriberAction#getJobName()
+ */
+ protected String getJobName() {
+ SyncInfoSet syncSet = getSyncInfoSet();
+ return Policy.bind("CompareRevertAction.0", new Integer(syncSet.size()).toString()); //$NON-NLS-1$
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ccvs.ui.subscriber.CVSSubscriberAction#run(org.eclipse.team.core.subscribers.MutableSyncInfoSet, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ protected void run(SyncInfoSet syncSet, IProgressMonitor monitor) throws TeamException {
+ SyncInfo[] changed = syncSet.getSyncInfos();
+ if (changed.length == 0) return;
+
+ // The list of sync resources to be updated using "cvs update"
+ List updateShallow = new ArrayList();
+ // A list of sync resource folders which need to be created locally
+ // (incoming addition or previously pruned)
+ Set parentCreationElements = new HashSet();
+
+ for (int i = 0; i < changed.length; i++) {
+ SyncInfo changedNode = changed[i];
+
+ // Make sure that parent folders exist
+ SyncInfo parent = getParent(changedNode);
+ if (parent != null && isOutOfSync(parent)) {
+ // We need to ensure that parents that are either incoming folder additions
+ // or previously pruned folders are recreated.
+ parentCreationElements.add(parent);
+ }
+
+ IResource resource = changedNode.getLocal();
+ if (resource.getType() == IResource.FILE) {
+ if (changedNode.getLocal().exists()) {
+ updateShallow.add(changedNode);
+ } else if (changedNode.getRemote() != null) {
+ updateShallow.add(changedNode);
+ }
+ } else {
+ // Special handling for folders to support shallow operations on files
+ // (i.e. folder operations are performed using the sync info already
+ // contained in the sync info.
+ if (isOutOfSync(changedNode)) {
+ parentCreationElements.add(changedNode);
+ }
+ }
+
+ }
+ try {
+ // Calculate the total amount of work needed
+ int work = updateShallow.size() * 100;
+ monitor.beginTask(null, work);
+
+ if (parentCreationElements.size() > 0) {
+ makeInSync((SyncInfo[]) parentCreationElements.toArray(new SyncInfo[parentCreationElements.size()]));
+ }
+ if (updateShallow.size() > 0) {
+ runUpdate((SyncInfo[])updateShallow.toArray(new SyncInfo[updateShallow.size()]), Policy.subMonitorFor(monitor, updateShallow.size() * 100));
+ }
+ } finally {
+ monitor.done();
+ }
+ return;
+ }
+
+ private void runUpdate(SyncInfo[] infos, IProgressMonitor monitor) throws TeamException {
+ monitor.beginTask(null, 100 * infos.length);
+ for (int i = 0; i < infos.length; i++) {
+ SyncInfo info = infos[i];
+ makeRemoteLocal(info, Policy.subMonitorFor(monitor, 100));
+ }
+ monitor.done();
+ }
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/MergeUpdateAction.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/MergeUpdateAction.java
index 7294626e8..bda5b226c 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/MergeUpdateAction.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/MergeUpdateAction.java
@@ -10,37 +10,19 @@
*******************************************************************************/
package org.eclipse.team.internal.ccvs.ui.subscriber;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.team.core.TeamException;
-import org.eclipse.team.core.subscribers.Subscriber;
-import org.eclipse.team.core.synchronize.*;
+import org.eclipse.compare.structuremergeviewer.IDiffElement;
+import org.eclipse.team.core.synchronize.FastSyncInfoFilter;
+import org.eclipse.team.core.synchronize.SyncInfo;
import org.eclipse.team.core.synchronize.FastSyncInfoFilter.OrSyncInfoFilter;
import org.eclipse.team.core.synchronize.FastSyncInfoFilter.SyncInfoDirectionFilter;
-import org.eclipse.team.internal.ccvs.core.*;
-import org.eclipse.team.internal.ccvs.core.client.Command;
-import org.eclipse.team.internal.ccvs.core.client.Update;
-import org.eclipse.team.internal.ccvs.ui.Policy;
+import org.eclipse.team.internal.ui.actions.SubscriberAction;
+import org.eclipse.team.internal.ui.actions.SubscriberOperation;
+import org.eclipse.ui.IWorkbenchPart;
-/**
- * This action performs a "cvs update -j start -j end ..." to merge changes
- * into the local workspace.
- */
-public class MergeUpdateAction extends SafeUpdateAction {
-
- Subscriber currentSubcriber = null;
+
+public class MergeUpdateAction extends SubscriberAction {
- /* (non-Javadoc)
- * @see org.eclipse.team.internal.ccvs.ui.subscriber.SafeUpdateAction#getOverwriteLocalChanges()
- */
- protected boolean getOverwriteLocalChanges() {
- return true;
- }
+ private boolean promptBeforeUpdate;
/* (non-Javadoc)
* @see org.eclipse.team.ui.sync.SubscriberAction#getSyncInfoFilter()
@@ -52,110 +34,15 @@ public class MergeUpdateAction extends SafeUpdateAction {
new SyncInfoDirectionFilter(SyncInfo.CONFLICTING)
});
}
-
- protected void updated(IResource[] resources) throws TeamException {
- // Mark all succesfully updated resources as merged
- if(resources.length > 0 && currentSubcriber != null) {
- ((CVSMergeSubscriber)currentSubcriber).merged(resources);
- }
- }
-
+
/* (non-Javadoc)
- * @see org.eclipse.team.internal.ccvs.ui.subscriber.SafeUpdateAction#runUpdateDeletions(org.eclipse.team.internal.ui.sync.views.SyncInfo[], org.eclipse.team.internal.ccvs.ui.repo.RepositoryManager, org.eclipse.core.runtime.IProgressMonitor)
+ * @see org.eclipse.team.internal.ui.actions.SubscriberAction#getSubscriberOperation(org.eclipse.compare.structuremergeviewer.IDiffElement[])
*/
- protected void runUpdateDeletions(SyncInfo[] nodes, IProgressMonitor monitor) throws TeamException {
- // When merging, update deletions become outgoing deletions so just delete
- // the files locally without unmanaging (so the sync info is kept to
- // indicate an outgoing deletion
- try {
- monitor.beginTask(null, 100 * nodes.length);
- for (int i = 0; i < nodes.length; i++) {
- IResource resource = nodes[i].getLocal();
- if (resource.getType() == IResource.FILE) {
- ((IFile)resource).delete(false /* force */, true /* keep local history */, Policy.subMonitorFor(monitor, 100));
- }
- }
- } catch (CoreException e) {
- throw CVSException.wrapException(e);
- } finally {
- monitor.done();
- }
+ protected SubscriberOperation getSubscriberOperation(IWorkbenchPart part, IDiffElement[] elements) {
+ return new MergeUpdateOperation(part, elements, promptBeforeUpdate);
}
-
- /* (non-Javadoc)
- * @see org.eclipse.team.internal.ccvs.ui.subscriber.SubscriberUpdateAction#runUpdateShallow(org.eclipse.team.internal.ui.sync.views.SyncInfo[], org.eclipse.team.internal.ccvs.ui.repo.RepositoryManager, org.eclipse.core.runtime.IProgressMonitor)
- */
- protected void runSafeUpdate(SyncInfo[] nodes, IProgressMonitor monitor) throws TeamException {
- if(nodes.length > 0) {
- // Assumption that all nodes are from the same subscriber.
- currentSubcriber = ((CVSSyncInfo)nodes[0]).getSubscriber();
- if (!(currentSubcriber instanceof CVSMergeSubscriber)) {
- throw new CVSException(Policy.bind("MergeUpdateAction.invalidSubscriber", currentSubcriber.toString())); //$NON-NLS-1$
- }
- CVSTag startTag = ((CVSMergeSubscriber)currentSubcriber).getStartTag();
- CVSTag endTag = ((CVSMergeSubscriber)currentSubcriber).getEndTag();
- // Incoming additions require different handling then incoming changes and deletions
- List additions = new ArrayList();
- List changes = new ArrayList();
- for (int i = 0; i < nodes.length; i++) {
- SyncInfo resource = nodes[i];
- int kind = resource.getKind();
- if ((kind & SyncInfo.CHANGE_MASK) == SyncInfo.ADDITION) {
- additions.add(resource);
- } else {
- changes.add(resource);
- }
- }
-
- try {
- monitor.beginTask(null, (additions.size() + changes.size()) * 100);
- if (!additions.isEmpty()) {
- safeUpdate(
- getIResourcesFrom((SyncInfo[]) additions.toArray(new SyncInfo[additions.size()])),
- new Command.LocalOption[] {
- Command.DO_NOT_RECURSE,
- Update.makeArgumentOption(Update.JOIN, endTag.getName())
- },
- Policy.subMonitorFor(monitor, additions.size() * 100));
- }
- if (!changes.isEmpty()) {
- safeUpdate(
- getIResourcesFrom((SyncInfo[]) changes.toArray(new SyncInfo[changes.size()])),
- new Command.LocalOption[] {
- Command.DO_NOT_RECURSE,
- Update.makeArgumentOption(Update.JOIN, startTag.getName()),
- Update.makeArgumentOption(Update.JOIN, endTag.getName())
- },
- Policy.subMonitorFor(monitor, changes.size() * 100));
- }
- } finally {
- monitor.done();
- }
- }
- }
-
- /*
- * @see UpdateSyncAction#runUpdateDeep(IProgressMonitor, List, RepositoryManager)
- * incoming-change
- * incoming-deletion
- */
- protected void overwriteUpdate(SyncInfoSet set, IProgressMonitor monitor) throws TeamException {
- SyncInfo[] nodes = set.getSyncInfos();
- monitor.beginTask(null, 1000 * nodes.length);
- try {
- for (int i = 0; i < nodes.length; i++) {
- makeRemoteLocal(nodes[i], Policy.subMonitorFor(monitor, 1000));
- }
- } finally {
- monitor.done();
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.team.internal.ccvs.ui.subscriber.CVSSubscriberAction#getJobName(org.eclipse.team.ui.sync.SyncInfoSet)
- */
- protected String getJobName(SyncInfoSet syncSet) {
- return Policy.bind("MergeUpdateAction.jobName", new Integer(syncSet.size()).toString()); //$NON-NLS-1$
+ public void setPromptBeforeUpdate(boolean prompt) {
+ promptBeforeUpdate = prompt;
}
-}
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/MergeUpdateOperation.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/MergeUpdateOperation.java
new file mode 100644
index 000000000..edc233579
--- /dev/null
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/MergeUpdateOperation.java
@@ -0,0 +1,157 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.team.internal.ccvs.ui.subscriber;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.compare.structuremergeviewer.IDiffElement;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.core.TeamException;
+import org.eclipse.team.core.subscribers.Subscriber;
+import org.eclipse.team.core.synchronize.SyncInfo;
+import org.eclipse.team.core.synchronize.SyncInfoSet;
+import org.eclipse.team.internal.ccvs.core.*;
+import org.eclipse.team.internal.ccvs.core.client.Command;
+import org.eclipse.team.internal.ccvs.core.client.Update;
+import org.eclipse.team.internal.ccvs.ui.Policy;
+import org.eclipse.ui.IWorkbenchPart;
+
+/**
+ * This action performs a "cvs update -j start -j end ..." to merge changes
+ * into the local workspace.
+ */
+public class MergeUpdateOperation extends SafeUpdateOperation {
+
+ Subscriber currentSubcriber = null;
+
+ protected MergeUpdateOperation(IWorkbenchPart part, IDiffElement[] elements, boolean promptBeforeUpdate) {
+ super(part, elements, promptBeforeUpdate);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ccvs.ui.subscriber.CVSSubscriberAction#getJobName(org.eclipse.team.ui.sync.SyncInfoSet)
+ */
+ protected String getJobName() {
+ SyncInfoSet syncSet = getSyncInfoSet();
+ return Policy.bind("MergeUpdateAction.jobName", new Integer(syncSet.size()).toString()); //$NON-NLS-1$
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ccvs.ui.subscriber.SafeUpdateOperation#getOverwriteLocalChanges()
+ */
+ protected boolean getOverwriteLocalChanges() {
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ccvs.ui.subscriber.SafeUpdateOperation#updated(org.eclipse.core.resources.IResource[])
+ */
+ protected void updated(IResource[] resources) throws TeamException {
+ // Mark all succesfully updated resources as merged
+ if(resources.length > 0 && currentSubcriber != null) {
+ ((CVSMergeSubscriber)currentSubcriber).merged(resources);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ccvs.ui.subscriber.SafeUpdateOperation#runUpdateDeletions(org.eclipse.team.core.synchronize.SyncInfo[], org.eclipse.core.runtime.IProgressMonitor)
+ */
+ protected void runUpdateDeletions(SyncInfo[] nodes, IProgressMonitor monitor) throws TeamException {
+ // When merging, update deletions become outgoing deletions so just delete
+ // the files locally without unmanaging (so the sync info is kept to
+ // indicate an outgoing deletion
+ try {
+ monitor.beginTask(null, 100 * nodes.length);
+ for (int i = 0; i < nodes.length; i++) {
+ IResource resource = nodes[i].getLocal();
+ if (resource.getType() == IResource.FILE) {
+ ((IFile)resource).delete(false /* force */, true /* keep local history */, Policy.subMonitorFor(monitor, 100));
+ }
+ }
+ } catch (CoreException e) {
+ throw CVSException.wrapException(e);
+ } finally {
+ monitor.done();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ccvs.ui.subscriber.SafeUpdateOperation#runSafeUpdate(org.eclipse.team.core.synchronize.SyncInfo[], org.eclipse.core.runtime.IProgressMonitor)
+ */
+ protected void runSafeUpdate(SyncInfo[] nodes, IProgressMonitor monitor) throws TeamException {
+ if(nodes.length > 0) {
+ // Assumption that all nodes are from the same subscriber.
+ currentSubcriber = ((CVSSyncInfo)nodes[0]).getSubscriber();
+ if (!(currentSubcriber instanceof CVSMergeSubscriber)) {
+ throw new CVSException(Policy.bind("MergeUpdateAction.invalidSubscriber", currentSubcriber.toString())); //$NON-NLS-1$
+ }
+ CVSTag startTag = ((CVSMergeSubscriber)currentSubcriber).getStartTag();
+ CVSTag endTag = ((CVSMergeSubscriber)currentSubcriber).getEndTag();
+
+ // Incoming additions require different handling then incoming changes and deletions
+ List additions = new ArrayList();
+ List changes = new ArrayList();
+ for (int i = 0; i < nodes.length; i++) {
+ SyncInfo resource = nodes[i];
+ int kind = resource.getKind();
+ if ((kind & SyncInfo.CHANGE_MASK) == SyncInfo.ADDITION) {
+ additions.add(resource);
+ } else {
+ changes.add(resource);
+ }
+ }
+
+ try {
+ monitor.beginTask(null, (additions.size() + changes.size()) * 100);
+ if (!additions.isEmpty()) {
+ safeUpdate(
+ getIResourcesFrom((SyncInfo[]) additions.toArray(new SyncInfo[additions.size()])),
+ new Command.LocalOption[] {
+ Command.DO_NOT_RECURSE,
+ Command.makeArgumentOption(Update.JOIN, endTag.getName())
+ },
+ Policy.subMonitorFor(monitor, additions.size() * 100));
+ }
+ if (!changes.isEmpty()) {
+ safeUpdate(
+ getIResourcesFrom((SyncInfo[]) changes.toArray(new SyncInfo[changes.size()])),
+ new Command.LocalOption[] {
+ Command.DO_NOT_RECURSE,
+ Command.makeArgumentOption(Update.JOIN, startTag.getName()),
+ Command.makeArgumentOption(Update.JOIN, endTag.getName())
+ },
+ Policy.subMonitorFor(monitor, changes.size() * 100));
+ }
+ } finally {
+ monitor.done();
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ccvs.ui.subscriber.SafeUpdateOperation#overwriteUpdate(org.eclipse.team.core.synchronize.SyncInfoSet, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ protected void overwriteUpdate(SyncInfoSet set, IProgressMonitor monitor) throws TeamException {
+ SyncInfo[] nodes = set.getSyncInfos();
+ monitor.beginTask(null, 1000 * nodes.length);
+ try {
+ for (int i = 0; i < nodes.length; i++) {
+ makeRemoteLocal(nodes[i], Policy.subMonitorFor(monitor, 1000));
+ }
+ } finally {
+ monitor.done();
+ }
+ }
+}
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/OverrideAndCommitAction.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/OverrideAndCommitAction.java
index be2ac3278..e29de8118 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/OverrideAndCommitAction.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/OverrideAndCommitAction.java
@@ -10,34 +10,27 @@
*******************************************************************************/
package org.eclipse.team.internal.ccvs.ui.subscriber;
+import org.eclipse.compare.structuremergeviewer.IDiffElement;
import org.eclipse.team.core.synchronize.*;
import org.eclipse.team.core.synchronize.FastSyncInfoFilter.SyncInfoDirectionFilter;
+import org.eclipse.team.internal.ui.actions.SubscriberAction;
+import org.eclipse.team.internal.ui.actions.SubscriberOperation;
+import org.eclipse.ui.IWorkbenchPart;
-public class OverrideAndCommitAction extends SubscriberCommitAction {
+public class OverrideAndCommitAction extends SubscriberAction {
/* (non-Javadoc)
- * @see org.eclipse.team.ui.sync.SubscriberAction#getSyncInfoFilter()
+ * @see org.eclipse.team.internal.ui.actions.SubscriberAction#getSyncInfoFilter()
*/
protected FastSyncInfoFilter getSyncInfoFilter() {
return new SyncInfoDirectionFilter(new int[] {SyncInfo.CONFLICTING, SyncInfo.INCOMING});
}
-
- protected boolean promptForConflictHandling(SyncInfoSet syncSet) {
- // If there is a conflict in the syncSet, we need to prompt the user before proceeding.
- if (syncSet.hasConflicts() || syncSet.hasIncomingChanges()) {
- switch (promptForConflicts(syncSet)) {
- case 0:
- // Yes, synchronize conflicts as well
- break;
- case 1:
- // No, stop here
- return false;
- case 2:
- default:
- // Cancel
- return false;
- }
- }
- return true;
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ui.actions.SubscriberAction#getSubscriberOperation(org.eclipse.compare.structuremergeviewer.IDiffElement[])
+ */
+ protected SubscriberOperation getSubscriberOperation(IWorkbenchPart part, IDiffElement[] elements) {
+ return new SubscriberCommitOperation(part, elements, true /* override */);
}
+
}
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/OverrideAndUpdateAction.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/OverrideAndUpdateAction.java
index 09207c4f4..c479ab049 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/OverrideAndUpdateAction.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/OverrideAndUpdateAction.java
@@ -10,25 +10,21 @@
*******************************************************************************/
package org.eclipse.team.internal.ccvs.ui.subscriber;
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.team.core.TeamException;
-import org.eclipse.team.core.synchronize.*;
+import org.eclipse.compare.structuremergeviewer.IDiffElement;
+import org.eclipse.team.core.synchronize.FastSyncInfoFilter;
+import org.eclipse.team.core.synchronize.SyncInfo;
import org.eclipse.team.core.synchronize.FastSyncInfoFilter.SyncInfoDirectionFilter;
-import org.eclipse.team.internal.ccvs.core.CVSException;
-import org.eclipse.team.internal.ccvs.ui.Policy;
-import org.eclipse.team.internal.ccvs.ui.operations.OverrideAndUpdateOperation;
+import org.eclipse.team.internal.ui.actions.SubscriberAction;
+import org.eclipse.team.internal.ui.actions.SubscriberOperation;
+import org.eclipse.ui.IWorkbenchPart;
/**
* Runs an update command that will prompt the user for overwritting local
* changes to files that have non-mergeable conflicts. All the prompting logic
* is in the super class.
*/
-public class OverrideAndUpdateAction extends CVSSubscriberAction {
+public class OverrideAndUpdateAction extends SubscriberAction {
+
/* (non-Javadoc)
* @see org.eclipse.team.ui.sync.SubscriberAction#getSyncInfoFilter()
*/
@@ -36,39 +32,7 @@ public class OverrideAndUpdateAction extends CVSSubscriberAction {
return new SyncInfoDirectionFilter(new int[] {SyncInfo.CONFLICTING, SyncInfo.OUTGOING});
}
- private FastSyncInfoFilter getConflictingAdditionFilter() {
- return new FastSyncInfoFilter.AndSyncInfoFilter(
- new FastSyncInfoFilter[] {
- new FastSyncInfoFilter.SyncInfoDirectionFilter(new int[] {SyncInfo.CONFLICTING}),
- new FastSyncInfoFilter.SyncInfoChangeTypeFilter(new int[] {SyncInfo.ADDITION})
- });
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.team.internal.ccvs.ui.subscriber.CVSSubscriberAction#run(org.eclipse.team.ui.sync.SyncInfoSet, org.eclipse.core.runtime.IProgressMonitor)
- */
- protected void run(SyncInfoSet syncSet, IProgressMonitor monitor) throws TeamException {
- try {
- if(promptForOverwrite(syncSet)) {
- SyncInfo[] conflicts = syncSet.getNodes(getConflictingAdditionFilter());
- List conflictingResources = new ArrayList();
- for (int i = 0; i < conflicts.length; i++) {
- SyncInfo info = conflicts[i];
- conflictingResources.add(info.getLocal());
- }
- new OverrideAndUpdateOperation(getShell(), syncSet.getResources(), (IResource[]) conflictingResources.toArray(new IResource[conflictingResources.size()]), null /* tag */, false /* recurse */).run(monitor);
- }
- } catch (InvocationTargetException e) {
- throw CVSException.wrapException(e);
- } catch (InterruptedException e) {
- Policy.cancelOperation();
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.team.internal.ccvs.ui.subscriber.CVSSubscriberAction#getJobName(org.eclipse.team.ui.synchronize.actions.SyncInfoSet)
- */
- protected String getJobName(SyncInfoSet syncSet) {
- return Policy.bind("OverrideAndUpdateAction.jobName", new Integer(syncSet.size()).toString()); //$NON-NLS-1$
+ protected SubscriberOperation getSubscriberOperation(IWorkbenchPart part, IDiffElement[] elements) {
+ return new OverrideAndUpdateSubscriberOperation(part, elements);
}
}
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/OverrideAndUpdateSubscriberOperation.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/OverrideAndUpdateSubscriberOperation.java
new file mode 100644
index 000000000..1b440f0d5
--- /dev/null
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/OverrideAndUpdateSubscriberOperation.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.team.internal.ccvs.ui.subscriber;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.compare.structuremergeviewer.IDiffElement;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.core.TeamException;
+import org.eclipse.team.core.synchronize.*;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.ui.Policy;
+import org.eclipse.team.internal.ccvs.ui.operations.OverrideAndUpdateOperation;
+import org.eclipse.ui.IWorkbenchPart;
+
+public class OverrideAndUpdateSubscriberOperation extends CVSSubscriberOperation {
+ protected OverrideAndUpdateSubscriberOperation(IWorkbenchPart part, IDiffElement[] elements) {
+ super(part, elements);
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ccvs.ui.subscriber.CVSSubscriberOperation#run(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ SyncInfoSet syncSet = getSyncInfoSet();
+ if(promptForOverwrite(syncSet)) {
+ super.run(monitor);
+ }
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ccvs.ui.subscriber.CVSSubscriberOperation#run(org.eclipse.team.core.synchronize.SyncInfoSet, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ protected void run(SyncInfoSet set, IProgressMonitor monitor) throws TeamException {
+ try {
+ SyncInfo[] conflicts = set.getNodes(getConflictingAdditionFilter());
+ List conflictingResources = new ArrayList();
+ for (int i = 0; i < conflicts.length; i++) {
+ SyncInfo info = conflicts[i];
+ conflictingResources.add(info.getLocal());
+ }
+ new OverrideAndUpdateOperation(getShell(), set.getResources(), (IResource[]) conflictingResources.toArray(new IResource[conflictingResources.size()]), null /* tag */, false /* recurse */).run(monitor);
+ } catch (InvocationTargetException e) {
+ throw CVSException.wrapException(e);
+ } catch (InterruptedException e) {
+ Policy.cancelOperation();
+ }
+ }
+ private FastSyncInfoFilter getConflictingAdditionFilter() {
+ return new FastSyncInfoFilter.AndSyncInfoFilter(
+ new FastSyncInfoFilter[] {
+ new FastSyncInfoFilter.SyncInfoDirectionFilter(new int[] {SyncInfo.CONFLICTING}),
+ new FastSyncInfoFilter.SyncInfoChangeTypeFilter(new int[] {SyncInfo.ADDITION})
+ });
+ }
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/SafeUpdateAction.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/SafeUpdateOperation.java
index 2a7d63f16..c53e670e9 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/SafeUpdateAction.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/SafeUpdateOperation.java
@@ -13,6 +13,7 @@ package org.eclipse.team.internal.ccvs.ui.subscriber;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
+import org.eclipse.compare.structuremergeviewer.IDiffElement;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -21,7 +22,7 @@ import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.core.synchronize.*;
import org.eclipse.team.core.synchronize.FastSyncInfoFilter.*;
-import org.eclipse.team.core.variants.*;
+import org.eclipse.team.core.variants.IResourceVariant;
import org.eclipse.team.internal.ccvs.core.*;
import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption;
import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
@@ -29,6 +30,7 @@ import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo;
import org.eclipse.team.internal.ccvs.ui.Policy;
import org.eclipse.team.internal.ccvs.ui.operations.UpdateOnlyMergableOperation;
import org.eclipse.team.internal.ui.TeamUIPlugin;
+import org.eclipse.ui.IWorkbenchPart;
/**
* This update action will update all mergable resources first and then prompt the
@@ -37,63 +39,94 @@ import org.eclipse.team.internal.ui.TeamUIPlugin;
* Subclasses should determine how the update should handle conflicts by implementing
* the getOverwriteLocalChanges() method.
*/
-public abstract class SafeUpdateAction extends CVSSubscriberAction {
+public abstract class SafeUpdateOperation extends CVSSubscriberOperation {
- private List skippedFiles = new ArrayList();
private boolean promptBeforeUpdate = false;
+ private SyncInfoSet skipped = new SyncInfoSet();
+
+ protected SafeUpdateOperation(IWorkbenchPart part, IDiffElement[] elements, boolean promptBeforeUpdate) {
+ super(part, elements);
+ this.promptBeforeUpdate = promptBeforeUpdate;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ccvs.ui.subscriber.CVSSubscriberOperation#run(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ if(! promptIfNeeded()) return;
+ skipped.clear();
+ super.run(monitor);
+ try {
+ handleFailedUpdates(monitor);
+ } catch (TeamException e) {
+ throw new InvocationTargetException(e);
+ }
+ }
+
/* (non-Javadoc)
* @see org.eclipse.team.internal.ccvs.ui.subscriber.CVSSubscriberAction#run(org.eclipse.team.ui.sync.SyncInfoSet, org.eclipse.core.runtime.IProgressMonitor)
*/
public void run(SyncInfoSet syncSet, IProgressMonitor monitor) throws TeamException {
try {
- if(! promptIfNeeded(syncSet)) return;
- // First, remove any known failure cases
- FastSyncInfoFilter failFilter = getKnownFailureCases();
- SyncInfo[] willFail = syncSet.getNodes(failFilter);
- syncSet.rejectNodes(failFilter);
- skippedFiles.clear();
+ monitor.beginTask(null, 100);
- monitor.beginTask(null, (syncSet.size() + willFail.length) * 100);
+ // Remove the cases that are known to fail (adding them to skipped list)
+ removeKnownFailureCases(syncSet);
// Run the update on the remaining nodes in the set
// The update will fail for conflicts that turn out to be non-automergable
- safeUpdate(syncSet, Policy.subMonitorFor(monitor, syncSet.size() * 100));
-
- // It is possible that some of the conflicting changes were not auto-mergable.
- // Accumulate all resources that have not been updated so far
- final SyncInfoSet failedSet = createFailedSet(syncSet, willFail, (IFile[]) skippedFiles.toArray(new IFile[skippedFiles.size()]));
+ safeUpdate(syncSet, Policy.subMonitorFor(monitor, 00));
- // Remove all these from the original sync set
+ // Remove all failed conflicts from the original sync set
syncSet.rejectNodes(new FastSyncInfoFilter() {
public boolean select(SyncInfo info) {
- return failedSet.getSyncInfo(info.getLocal()) != null;
+ return skipped.getSyncInfo(info.getLocal()) != null;
}
});
-
- // Handle conflicting files that can't be merged, ask the user what should be done.
- if(! failedSet.isEmpty()) {
- if(getOverwriteLocalChanges()) {
- // Ask the user if a replace should be performed on the remaining nodes
- if(promptForOverwrite(failedSet)) {
- overwriteUpdate(failedSet, Policy.subMonitorFor(monitor, willFail.length * 100));
- if (!failedSet.isEmpty()) {
- syncSet.addAll(failedSet);
- }
- }
- } else {
- // Warn the user that some nodes could not be updated. This can happen if there are
- // files with conflicts that are not auto-mergeable.
- warnAboutFailedResources(failedSet);
- }
- }
+ // Signal for the ones that were updated
updated(syncSet.getResources());
} finally {
monitor.done();
}
}
+ /**
+ * @param syncSet
+ * @return
+ */
+ private SyncInfoSet removeKnownFailureCases(SyncInfoSet syncSet) {
+ // First, remove any known failure cases
+ FastSyncInfoFilter failFilter = getKnownFailureCases();
+ SyncInfo[] willFail = syncSet.getNodes(failFilter);
+ syncSet.rejectNodes(failFilter);
+ for (int i = 0; i < willFail.length; i++) {
+ SyncInfo info = willFail[i];
+ skipped.add(info);
+ }
+ return syncSet;
+ }
+
+ private void handleFailedUpdates(IProgressMonitor monitor) throws TeamException {
+ // Handle conflicting files that can't be merged, ask the user what should be done.
+ if(! skipped.isEmpty()) {
+ if(getOverwriteLocalChanges()) {
+ // Ask the user if a replace should be performed on the remaining nodes
+ if(promptForOverwrite(skipped)) {
+ overwriteUpdate(skipped, monitor);
+ if (!skipped.isEmpty()) {
+ updated(skipped.getResources());
+ }
+ }
+ } else {
+ // Warn the user that some nodes could not be updated. This can happen if there are
+ // files with conflicts that are not auto-mergeable.
+ warnAboutFailedResources(skipped);
+ }
+ }
+ }
+
protected boolean getOverwriteLocalChanges(){
return false;
}
@@ -160,7 +193,7 @@ public abstract class SafeUpdateAction extends CVSSubscriberAction {
break;
}
if (!willBeAttempted) {
- skippedFiles.add(resource);
+ skipped.add(syncSet.getSyncInfo(resource));
}
} else {
// Special handling for folders to support shallow operations on files
@@ -194,6 +227,9 @@ public abstract class SafeUpdateAction extends CVSSubscriberAction {
/**
* Perform an overwrite (unsafe) update on the resources in the provided set.
+ * The passed sync set may containe resources from multiple projects and
+ * it cannot be assumed that any scheduling rule is held when this method
+ * is invoked.
* @param syncSet the set containing the resources to be updated
* @param monitor
*/
@@ -330,7 +366,11 @@ public abstract class SafeUpdateAction extends CVSSubscriberAction {
protected abstract void updated(IResource[] resources) throws TeamException;
private void addSkippedFiles(IFile[] files) {
- skippedFiles.addAll(Arrays.asList(files));
+ SyncInfoSet set = getSyncInfoSet();
+ for (int i = 0; i < files.length; i++) {
+ IFile file = files[i];
+ skipped.add(set.getSyncInfo(file));
+ }
}
protected String getErrorTitle() {
@@ -340,7 +380,8 @@ public abstract class SafeUpdateAction extends CVSSubscriberAction {
/* (non-Javadoc)
* @see org.eclipse.team.internal.ccvs.ui.subscriber.CVSSubscriberAction#getJobName(org.eclipse.team.ui.sync.SyncInfoSet)
*/
- protected String getJobName(SyncInfoSet syncSet) {
+ protected String getJobName() {
+ SyncInfoSet syncSet = getSyncInfoSet();
return Policy.bind("UpdateAction.jobName", new Integer(syncSet.size()).toString()); //$NON-NLS-1$
}
@@ -352,7 +393,8 @@ public abstract class SafeUpdateAction extends CVSSubscriberAction {
* @return <code>true</code> if the update operation can continue, and <code>false</code>
* if the update has been cancelled by the user.
*/
- private boolean promptIfNeeded(final SyncInfoSet set) {
+ private boolean promptIfNeeded() {
+ final SyncInfoSet set = getSyncInfoSet();
final boolean[] result = new boolean[] {true};
if(getPromptBeforeUpdate()) {
TeamUIPlugin.getStandardDisplay().syncExec(new Runnable() {
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/SubscriberCommitAction.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/SubscriberCommitAction.java
index 9d1376ce3..d3347e2b4 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/SubscriberCommitAction.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/SubscriberCommitAction.java
@@ -10,29 +10,15 @@
*******************************************************************************/
package org.eclipse.team.internal.ccvs.ui.subscriber;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.team.core.TeamException;
-import org.eclipse.team.core.synchronize.*;
+import org.eclipse.compare.structuremergeviewer.IDiffElement;
+import org.eclipse.team.core.synchronize.FastSyncInfoFilter;
+import org.eclipse.team.core.synchronize.SyncInfo;
import org.eclipse.team.core.synchronize.FastSyncInfoFilter.SyncInfoDirectionFilter;
-import org.eclipse.team.internal.ccvs.core.*;
-import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
-import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo;
-import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
-import org.eclipse.team.internal.ccvs.ui.Policy;
-import org.eclipse.team.internal.ccvs.ui.repo.RepositoryManager;
-import org.eclipse.team.internal.ccvs.ui.sync.ToolTipMessageDialog;
-import org.eclipse.team.internal.ui.Utils;
-
-public class SubscriberCommitAction extends CVSSubscriberAction {
+import org.eclipse.team.internal.ui.actions.SubscriberAction;
+import org.eclipse.team.internal.ui.actions.SubscriberOperation;
+import org.eclipse.ui.IWorkbenchPart;
- private String comment;
+public class SubscriberCommitAction extends SubscriberAction {
/* (non-Javadoc)
* @see org.eclipse.team.ui.sync.SubscriberAction#getSyncInfoFilter()
@@ -42,242 +28,9 @@ public class SubscriberCommitAction extends CVSSubscriberAction {
}
/* (non-Javadoc)
- * @see org.eclipse.team.ui.synchronize.subscriber.SubscriberAction#makeSyncInfoSetFromSelection(org.eclipse.team.core.synchronize.SyncInfo[])
- */
- protected SyncInfoSet makeSyncInfoSetFromSelection(SyncInfo[] infos) {
- SyncInfoSet syncSet = new SyncInfoSet(infos);
- if (!promptForConflictHandling(syncSet)) return null;
- try {
- if (!promptForUnaddedHandling(syncSet)) return null;
- } catch (CVSException e) {
- Utils.handle(e);
- }
- return syncSet;
- }
-
- protected boolean promptForConflictHandling(SyncInfoSet syncSet) {
- // If there is a conflict in the syncSet, remove from sync set.
- if (syncSet.hasConflicts() || syncSet.hasIncomingChanges()) {
- syncSet.removeConflictingNodes();
- syncSet.removeIncomingNodes();
- }
- return true;
- }
-
- private boolean promptForUnaddedHandling(SyncInfoSet syncSet) throws CVSException {
- if (syncSet.isEmpty()) return false;
-
- // accumulate any resources that are not under version control
- IResource[] unadded = getUnaddedResources(syncSet);
-
- // prompt to get comment and any resources to be added to version control
- RepositoryManager manager = CVSUIPlugin.getPlugin().getRepositoryManager();
- IResource[] toBeAdded = promptForResourcesToBeAdded(manager, unadded);
- if (toBeAdded == null) return false; // User cancelled.
- comment = promptForComment(manager, syncSet.getResources());
- if (comment == null) return false; // User cancelled.
-
- // remove unshared resources that were not selected by the user
- if (unadded != null && unadded.length > 0) {
- List resourcesToRemove = new ArrayList(unadded.length);
- for (int i = 0; i < unadded.length; i++) {
- IResource unaddedResource = unadded[i];
- boolean included = false;
- for (int j = 0; j < toBeAdded.length; j++) {
- IResource resourceToAdd = toBeAdded[j];
- if (unaddedResource.equals(resourceToAdd)) {
- included = true;
- break;
- }
- }
- if (!included)
- resourcesToRemove.add(unaddedResource);
- }
- syncSet.removeAll((IResource[]) resourcesToRemove.toArray(new IResource[resourcesToRemove.size()]));
- }
- return true;
- }
-
- private IResource[] getUnaddedResources(SyncInfoSet syncSet) throws CVSException {
- // TODO: Should only get outgoing additions (since conflicting additions
- // could be considered to be under version control already)
- IResource[] resources = syncSet.getResources();
- List result = new ArrayList();
- for (int i = 0; i < resources.length; i++) {
- IResource resource = resources[i];
- if (!isAdded(resource)) {
- result.add(resource);
- }
- }
- return (IResource[]) result.toArray(new IResource[result.size()]);
- }
-
- private boolean isAdded(IResource resource) throws CVSException {
- ICVSResource cvsResource = CVSWorkspaceRoot.getCVSResourceFor(resource);
- if (cvsResource.isFolder()) {
- return ((ICVSFolder)cvsResource).isCVSFolder();
- } else {
- return cvsResource.isManaged();
- }
- }
-
- private boolean isRemoved(IResource resource) throws CVSException {
- ICVSResource cvsResource = CVSWorkspaceRoot.getCVSResourceFor(resource);
- if (!cvsResource.isFolder()) {
- byte[] syncBytes = ((ICVSFile)cvsResource).getSyncBytes();
- if (syncBytes == null) return true;
- return ResourceSyncInfo.isDeletion(syncBytes);
- }
- return true;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.team.internal.ccvs.ui.subscriber.CVSSubscriberAction#run(org.eclipse.team.ui.sync.SyncInfoSet, org.eclipse.core.runtime.IProgressMonitor)
- */
- public void run(SyncInfoSet syncSet, IProgressMonitor monitor) throws TeamException {
-
- final SyncInfo[] changed = syncSet.getSyncInfos();
- if (changed.length == 0) return;
-
- // A list of files to be committed
- final List commits = new ArrayList(); // of IResource
- // New resources that are not yet under CVS control and need a "cvs add"
- final List additions = new ArrayList(); // of IResource
- // Deleted resources that need a "cvs remove"
- final List deletions = new ArrayList(); // of IResource
- // A list of incoming or conflicting file changes to be made outgoing changes
- final List makeOutgoing = new ArrayList(); // of SyncInfo
- // A list of out-of-sync folders that must be made in-sync
- final List makeInSync = new ArrayList(); // of SyncInfo
-
- for (int i = 0; i < changed.length; i++) {
- SyncInfo changedNode = changed[i];
- int kind = changedNode.getKind();
- IResource resource = changedNode.getLocal();
-
- // Any parent folders should be made in-sync.
- // Steps will be taken after the commit to prune any empty folders
- SyncInfo parent = getParent(changedNode);
- if (parent != null) {
- if (isOutOfSync(parent)) {
- makeInSync.add(parent);
- }
- }
-
- if (resource.getType() == IResource.FILE) {
- // By default, all files are committed
- commits.add(resource);
- // Determine what other work needs to be done for the file
- switch (kind & SyncInfo.DIRECTION_MASK) {
- case SyncInfo.INCOMING:
- // Convert the incoming change to an outgoing change
- makeOutgoing.add(changedNode);
- break;
- case SyncInfo.OUTGOING:
- switch (kind & SyncInfo.CHANGE_MASK) {
- case SyncInfo.ADDITION:
- // Outgoing addition. 'add' it before committing.
- if (!isAdded(resource))
- additions.add(resource);
- break;
- case SyncInfo.DELETION:
- // Outgoing deletion. 'delete' it before committing.
- if (!isRemoved(resource))
- deletions.add(resource);
- break;
- case SyncInfo.CHANGE:
- // Outgoing change. Just commit it.
- break;
- }
- break;
- case SyncInfo.CONFLICTING:
- // Convert the conflicting change to an outgoing change
- makeOutgoing.add(changedNode);
- break;
- }
- } else {
- if (((kind & SyncInfo.DIRECTION_MASK) == SyncInfo.OUTGOING)
- && ((kind & SyncInfo.CHANGE_MASK) == SyncInfo.ADDITION)) {
- // Outgoing folder additions must be added
- additions.add(changedNode.getLocal());
- } else if (isOutOfSync(changedNode)) {
- // otherwise, make any out-of-sync folders in-sync using the remote info
- makeInSync.add(changedNode);
- }
- }
- }
- try {
- // Calculate the total amount of work needed
- int work = (makeOutgoing.size() + additions.size() + deletions.size() + commits.size()) * 100;
- monitor.beginTask(null, work);
-
- if (makeInSync.size() > 0) {
- makeInSync((SyncInfo[]) makeInSync.toArray(new SyncInfo[makeInSync.size()]));
- }
-
- if (makeOutgoing.size() > 0) {
- makeOutgoing((SyncInfo[]) makeOutgoing.toArray(new SyncInfo[makeInSync.size()]), Policy.subMonitorFor(monitor, makeOutgoing.size() * 100));
- }
-
- RepositoryManager manager = CVSUIPlugin.getPlugin().getRepositoryManager();
- if (additions.size() != 0) {
- manager.add((IResource[])additions.toArray(new IResource[0]), Policy.subMonitorFor(monitor, additions.size() * 100));
- }
- if (deletions.size() != 0) {
- manager.delete((IResource[])deletions.toArray(new IResource[0]), Policy.subMonitorFor(monitor, deletions.size() * 100));
- }
- manager.commit((IResource[])commits.toArray(new IResource[commits.size()]), comment, Policy.subMonitorFor(monitor, commits.size() * 100));
-
- } catch (TeamException e) {
- throw CVSException.wrapException(e);
- }
- }
-
- /**
- * Prompts the user to determine how conflicting changes should be handled.
- * Note: This method is designed to be overridden by test cases.
- * @return 0 to sync conflicts, 1 to sync all non-conflicts, 2 to cancel
- */
- protected int promptForConflicts(SyncInfoSet syncSet) {
- String[] buttons = new String[] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL};
- String question = Policy.bind("CommitSyncAction.questionRelease"); //$NON-NLS-1$
- String title = Policy.bind("CommitSyncAction.titleRelease"); //$NON-NLS-1$
- String[] tips = new String[] {
- Policy.bind("CommitSyncAction.releaseAll"), //$NON-NLS-1$
- Policy.bind("CommitSyncAction.releasePart"), //$NON-NLS-1$
- Policy.bind("CommitSyncAction.cancelRelease") //$NON-NLS-1$
- };
- Shell shell = getShell();
- final ToolTipMessageDialog dialog = new ToolTipMessageDialog(shell, title, null, question, MessageDialog.QUESTION, buttons, tips, 0);
- shell.getDisplay().syncExec(new Runnable() {
- public void run() {
- dialog.open();
- }
- });
- return dialog.getReturnCode();
- }
-
- /**
- * Prompts the user for a release comment.
- * Note: This method is designed to be overridden by test cases.
- * @return the comment, or null to cancel
- */
- protected String promptForComment(RepositoryManager manager, IResource[] resourcesToCommit) {
- return manager.promptForComment(getShell(), resourcesToCommit);
- }
-
- protected IResource[] promptForResourcesToBeAdded(RepositoryManager manager, IResource[] unadded) {
- return manager.promptForResourcesToBeAdded(getShell(), unadded);
- }
-
- protected String getErrorTitle() {
- return Policy.bind("CommitAction.commitFailed"); //$NON-NLS-1$
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.team.internal.ccvs.ui.subscriber.CVSSubscriberAction#getJobName(org.eclipse.team.ui.sync.SyncInfoSet)
+ * @see org.eclipse.team.internal.ui.actions.SubscriberAction#getSubscriberOperation(org.eclipse.compare.structuremergeviewer.IDiffElement[])
*/
- protected String getJobName(SyncInfoSet syncSet) {
- return Policy.bind("CommitAction.jobName", new Integer(syncSet.size()).toString()); //$NON-NLS-1$
+ protected SubscriberOperation getSubscriberOperation(IWorkbenchPart part, IDiffElement[] elements) {
+ return new SubscriberCommitOperation(part, elements, false /* override */);
}
-}
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/SubscriberCommitOperation.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/SubscriberCommitOperation.java
new file mode 100644
index 000000000..78f87bd4f
--- /dev/null
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/SubscriberCommitOperation.java
@@ -0,0 +1,314 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.team.internal.ccvs.ui.subscriber;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.compare.structuremergeviewer.IDiffElement;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.team.core.TeamException;
+import org.eclipse.team.core.synchronize.SyncInfo;
+import org.eclipse.team.core.synchronize.SyncInfoSet;
+import org.eclipse.team.internal.ccvs.core.*;
+import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
+import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo;
+import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
+import org.eclipse.team.internal.ccvs.ui.Policy;
+import org.eclipse.team.internal.ccvs.ui.repo.RepositoryManager;
+import org.eclipse.team.internal.ccvs.ui.sync.ToolTipMessageDialog;
+import org.eclipse.team.internal.ui.Utils;
+import org.eclipse.ui.IWorkbenchPart;
+
+public class SubscriberCommitOperation extends CVSSubscriberOperation {
+
+ private String comment;
+ private SyncInfoSet syncSet;
+ private boolean override;
+
+ public SubscriberCommitOperation(IWorkbenchPart part, IDiffElement[] elements, boolean override) {
+ super(part, elements);
+ this.override = override;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ccvs.ui.subscriber.CVSSubscriberOperation#getErrorTitle()
+ */
+ protected String getErrorTitle() {
+ return Policy.bind("CommitAction.commitFailed"); //$NON-NLS-1$
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ui.actions.TeamOperation#getJobName()
+ */
+ protected String getJobName() {
+ SyncInfoSet syncSet = getSyncInfoSet();
+ return Policy.bind("CommitAction.jobName", new Integer(syncSet.size()).toString()); //$NON-NLS-1$
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ui.actions.SubscriberOperation#getSyncInfoSet()
+ */
+ protected SyncInfoSet getSyncInfoSet() {
+ syncSet = super.getSyncInfoSet();
+ if (!promptForConflictHandling(syncSet)) {
+ syncSet.clear();
+ return syncSet;
+ }
+ try {
+ if (!promptForUnaddedHandling(syncSet)) {
+ syncSet.clear();
+ return syncSet;
+ }
+ } catch (CVSException e) {
+ Utils.handle(e);
+ syncSet.clear();
+ }
+ return syncSet;
+ }
+
+ protected boolean promptForConflictHandling(SyncInfoSet syncSet) {
+ if (syncSet.hasConflicts() || syncSet.hasIncomingChanges()) {
+ if (override) {
+ // If overriding, prompt to ensure that is what the user wants
+ switch (promptForConflicts(syncSet)) {
+ case 0:
+ // Yes, synchronize conflicts as well
+ break;
+ case 1:
+ // No, stop here
+ return false;
+ case 2:
+ default:
+ // Cancel
+ return false;
+ }
+ } else {
+ // If there is a conflict in the syncSet, remove from sync set.
+ syncSet.removeConflictingNodes();
+ syncSet.removeIncomingNodes();
+ }
+ }
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.team.internal.ccvs.ui.subscriber.CVSSubscriberOperation#run(org.eclipse.team.core.synchronize.SyncInfoSet, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public void run(SyncInfoSet syncSet, IProgressMonitor monitor) throws TeamException {
+
+ final SyncInfo[] changed = syncSet.getSyncInfos();
+ if (changed.length == 0) return;
+
+ // A list of files to be committed
+ final List commits = new ArrayList(); // of IResource
+ // New resources that are not yet under CVS control and need a "cvs add"
+ final List additions = new ArrayList(); // of IResource
+ // Deleted resources that need a "cvs remove"
+ final List deletions = new ArrayList(); // of IResource
+ // A list of incoming or conflicting file changes to be made outgoing changes
+ final List makeOutgoing = new ArrayList(); // of SyncInfo
+ // A list of out-of-sync folders that must be made in-sync
+ final List makeInSync = new ArrayList(); // of SyncInfo
+
+ for (int i = 0; i < changed.length; i++) {
+ SyncInfo changedNode = changed[i];
+ int kind = changedNode.getKind();
+ IResource resource = changedNode.getLocal();
+
+ // Any parent folders should be made in-sync.
+ // Steps will be taken after the commit to prune any empty folders
+ SyncInfo parent = getParent(changedNode);
+ if (parent != null) {
+ if (isOutOfSync(parent)) {
+ makeInSync.add(parent);
+ }
+ }
+
+ if (resource.getType() == IResource.FILE) {
+ // By default, all files are committed
+ commits.add(resource);
+ // Determine what other work needs to be done for the file
+ switch (kind & SyncInfo.DIRECTION_MASK) {
+ case SyncInfo.INCOMING:
+ // Convert the incoming change to an outgoing change
+ makeOutgoing.add(changedNode);
+ break;
+ case SyncInfo.OUTGOING:
+ switch (kind & SyncInfo.CHANGE_MASK) {
+ case SyncInfo.ADDITION:
+ // Outgoing addition. 'add' it before committing.
+ if (!isAdded(resource))
+ additions.add(resource);
+ break;
+ case SyncInfo.DELETION:
+ // Outgoing deletion. 'delete' it before committing.
+ if (!isRemoved(resource))
+ deletions.add(resource);
+ break;
+ case SyncInfo.CHANGE:
+ // Outgoing change. Just commit it.
+ break;
+ }
+ break;
+ case SyncInfo.CONFLICTING:
+ // Convert the conflicting change to an outgoing change
+ makeOutgoing.add(changedNode);
+ break;
+ }
+ } else {
+ if (((kind & SyncInfo.DIRECTION_MASK) == SyncInfo.OUTGOING)
+ && ((kind & SyncInfo.CHANGE_MASK) == SyncInfo.ADDITION)) {
+ // Outgoing folder additions must be added
+ additions.add(changedNode.getLocal());
+ } else if (isOutOfSync(changedNode)) {
+ // otherwise, make any out-of-sync folders in-sync using the remote info
+ makeInSync.add(changedNode);
+ }
+ }
+ }
+ try {
+ // Calculate the total amount of work needed
+ int work = (makeOutgoing.size() + additions.size() + deletions.size() + commits.size()) * 100;
+ monitor.beginTask(null, work);
+
+ if (makeInSync.size() > 0) {
+ makeInSync((SyncInfo[]) makeInSync.toArray(new SyncInfo[makeInSync.size()]));
+ }
+
+ if (makeOutgoing.size() > 0) {
+ makeOutgoing((SyncInfo[]) makeOutgoing.toArray(new SyncInfo[makeInSync.size()]), Policy.subMonitorFor(monitor, makeOutgoing.size() * 100));
+ }
+
+ RepositoryManager manager = CVSUIPlugin.getPlugin().getRepositoryManager();
+ if (additions.size() != 0) {
+ manager.add((IResource[])additions.toArray(new IResource[0]), Policy.subMonitorFor(monitor, additions.size() * 100));
+ }
+ if (deletions.size() != 0) {
+ manager.delete((IResource[])deletions.toArray(new IResource[0]), Policy.subMonitorFor(monitor, deletions.size() * 100));
+ }
+ manager.commit((IResource[])commits.toArray(new IResource[commits.size()]), comment, Policy.subMonitorFor(monitor, commits.size() * 100));
+
+ } catch (TeamException e) {
+ throw CVSException.wrapException(e);
+ }
+ }
+
+ /**
+ * Prompts the user to determine how conflicting changes should be handled.
+ * Note: This method is designed to be overridden by test cases.
+ * @return 0 to sync conflicts, 1 to sync all non-conflicts, 2 to cancel
+ */
+ protected int promptForConflicts(SyncInfoSet syncSet) {
+ String[] buttons = new String[] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL};
+ String question = Policy.bind("CommitSyncAction.questionRelease"); //$NON-NLS-1$
+ String title = Policy.bind("CommitSyncAction.titleRelease"); //$NON-NLS-1$
+ String[] tips = new String[] {
+ Policy.bind("CommitSyncAction.releaseAll"), //$NON-NLS-1$
+ Policy.bind("CommitSyncAction.releasePart"), //$NON-NLS-1$
+ Policy.bind("CommitSyncAction.cancelRelease") //$NON-NLS-1$
+ };
+ Shell shell = getShell();
+ final ToolTipMessageDialog dialog = new ToolTipMessageDialog(shell, title, null, question, MessageDialog.QUESTION, buttons, tips, 0);
+ shell.getDisplay().syncExec(new Runnable() {
+ public void run() {
+ dialog.open();
+ }
+ });
+ return dialog.getReturnCode();
+ }
+
+ /**
+ * Prompts the user for a release comment.
+ * Note: This method is designed to be overridden by test cases.
+ * @return the comment, or null to cancel
+ */
+ protected String promptForComment(RepositoryManager manager, IResource[] resourcesToCommit) {
+ return manager.promptForComment(getShell(), resourcesToCommit);
+ }
+
+ protected IResource[] promptForResourcesToBeAdded(RepositoryManager manager, IResource[] unadded) {
+ return manager.promptForResourcesToBeAdded(getShell(), unadded);
+ }
+
+ private boolean promptForUnaddedHandling(SyncInfoSet syncSet) throws CVSException {
+ if (syncSet.isEmpty()) return false;
+
+ // accumulate any resources that are not under version control
+ IResource[] unadded = getUnaddedResources(syncSet);
+
+ // prompt to get comment and any resources to be added to version control
+ RepositoryManager manager = CVSUIPlugin.getPlugin().getRepositoryManager();
+ IResource[] toBeAdded = promptForResourcesToBeAdded(manager, unadded);
+ if (toBeAdded == null) return false; // User cancelled.
+ comment = promptForComment(manager, syncSet.getResources());
+ if (comment == null) return false; // User cancelled.
+
+ // remove unshared resources that were not selected by the user
+ if (unadded != null && unadded.length > 0) {
+ List resourcesToRemove = new ArrayList(unadded.length);
+ for (int i = 0; i < unadded.length; i++) {
+ IResource unaddedResource = unadded[i];
+ boolean included = false;
+ for (int j = 0; j < toBeAdded.length; j++) {
+ IResource resourceToAdd = toBeAdded[j];
+ if (unaddedResource.equals(resourceToAdd)) {
+ included = true;
+ break;
+ }
+ }
+ if (!included)
+ resourcesToRemove.add(unaddedResource);
+ }
+ syncSet.removeAll((IResource[]) resourcesToRemove.toArray(new IResource[resourcesToRemove.size()]));
+ }
+ return true;
+ }
+
+ private IResource[] getUnaddedResources(SyncInfoSet syncSet) throws CVSException {
+ // TODO: Should only get outgoing additions (since conflicting additions
+ // could be considered to be under version control already)
+ IResource[] resources = syncSet.getResources();
+ List result = new ArrayList();
+ for (int i = 0; i < resources.length; i++) {
+ IResource resource = resources[i];
+ if (!isAdded(resource)) {
+ result.add(resource);
+ }
+ }
+ return (IResource[]) result.toArray(new IResource[result.size()]);
+ }
+
+ private boolean isAdded(IResource resource) throws CVSException {
+ ICVSResource cvsResource = CVSWorkspaceRoot.getCVSResourceFor(resource);
+ if (cvsResource.isFolder()) {
+ return ((ICVSFolder)cvsResource).isCVSFolder();
+ } else {
+ return cvsResource.isManaged();
+ }
+ }
+
+ private boolean isRemoved(IResource resource) throws CVSException {
+ ICVSResource cvsResource = CVSWorkspaceRoot.getCVSResourceFor(resource);
+ if (!cvsResource.isFolder()) {
+ byte[] syncBytes = ((ICVSFile)cvsResource).getSyncBytes();
+ if (syncBytes == null) return true;
+ return ResourceSyncInfo.isDeletion(syncBytes);
+ }
+ return true;
+ }
+
+}
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/SubscriberConfirmMergedAction.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/SubscriberConfirmMergedAction.java
index b75860fdc..1370985cc 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/SubscriberConfirmMergedAction.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/SubscriberConfirmMergedAction.java
@@ -10,22 +10,16 @@
*******************************************************************************/
package org.eclipse.team.internal.ccvs.ui.subscriber;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.team.core.TeamException;
-import org.eclipse.team.core.synchronize.*;
+import org.eclipse.compare.structuremergeviewer.IDiffElement;
+import org.eclipse.team.core.synchronize.FastSyncInfoFilter;
+import org.eclipse.team.core.synchronize.SyncInfo;
import org.eclipse.team.core.synchronize.FastSyncInfoFilter.SyncInfoDirectionFilter;
-import org.eclipse.team.internal.ccvs.core.*;
-import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
-import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
-import org.eclipse.team.internal.ccvs.ui.Policy;
-
-/**
- * This action marks the local resource as merged by updating the base
- * resource revision to match the remote resource revision
- */
-public class SubscriberConfirmMergedAction extends CVSSubscriberAction {
+import org.eclipse.team.internal.ui.actions.SubscriberAction;
+import org.eclipse.team.internal.ui.actions.SubscriberOperation;
+import org.eclipse.ui.IWorkbenchPart;
+public class SubscriberConfirmMergedAction extends SubscriberAction {
+
/* (non-Javadoc)
* @see org.eclipse.team.ui.sync.SubscriberAction#getSyncInfoFilter()
*/
@@ -34,57 +28,9 @@ public class SubscriberConfirmMergedAction extends CVSSubscriberAction {
}
/* (non-Javadoc)
- * @see org.eclipse.team.internal.ccvs.ui.subscriber.CVSSubscriberAction#run(org.eclipse.team.ui.sync.SyncInfoSet, org.eclipse.core.runtime.IProgressMonitor)
- */
- protected void run(SyncInfoSet syncSet, IProgressMonitor monitor) throws CVSException {
- SyncInfo[] syncResources = syncSet.getSyncInfos();
- monitor.beginTask(null, 100 * syncResources.length);
- try {
- for (int i = 0; i < syncResources.length; i++) {
- SyncInfo info = syncResources[i];
- if (!makeOutgoing(info, Policy.subMonitorFor(monitor, 100))) {
- // Failure was logged in makeOutgoing
- }
- }
- } catch (TeamException e) {
- handle(e);
- } finally {
- monitor.done();
- }
- }
-
- private boolean makeOutgoing(SyncInfo info, IProgressMonitor monitor) throws CVSException, TeamException {
- monitor.beginTask(null, 100);
- try {
- CVSSyncInfo cvsInfo = getCVSSyncInfo(info);
- if (cvsInfo == null) {
- CVSUIPlugin.log(IStatus.ERROR, Policy.bind("SubscriberConfirmMergedAction.0", cvsInfo.getLocal().getFullPath().toString()), null); //$NON-NLS-1$
- return false;
- }
- // Make sure the parent is managed
- ICVSFolder parent = CVSWorkspaceRoot.getCVSFolderFor(cvsInfo.getLocal().getParent());
- if (!parent.isCVSFolder()) {
- // the parents must be made outgoing before the child can
- SyncInfo parentInfo = cvsInfo.getSubscriber().getSyncInfo(parent.getIResource());
- if (!makeOutgoing(parentInfo, Policy.subMonitorFor(monitor, 20))) {
- return false;
- }
- }
- IStatus status = cvsInfo.makeOutgoing(Policy.subMonitorFor(monitor, 80));
- if (status.getSeverity() == IStatus.ERROR) {
- logError(status);
- return false;
- }
- return true;
- } finally {
- monitor.done();
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.team.internal.ccvs.ui.subscriber.CVSSubscriberAction#getJobName(org.eclipse.team.ui.synchronize.actions.SyncInfoSet)
+ * @see org.eclipse.team.internal.ui.actions.SubscriberAction#getSubscriberOperation(org.eclipse.compare.structuremergeviewer.IDiffElement[])
*/
- protected String getJobName(SyncInfoSet syncSet) {
- return Policy.bind("SubscriberConfirmMergedAction.jobName", new Integer(syncSet.size()).toString()); //$NON-NLS-1$
+ protected SubscriberOperation getSubscriberOperation(IWorkbenchPart part, IDiffElement[] elements) {
+ return new SubscriberConfirmMergedOperation(part, elements);
}
-}
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/SubscriberConfirmMergedOperation.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/SubscriberConfirmMergedOperation.java
new file mode 100644
index 000000000..ff789f64d
--- /dev/null
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/SubscriberConfirmMergedOperation.java
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.team.internal.ccvs.ui.subscriber;
+
+import org.eclipse.compare.structuremergeviewer.IDiffElement;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.team.core.TeamException;
+import org.eclipse.team.core.synchronize.SyncInfo;
+import org.eclipse.team.core.synchronize.SyncInfoSet;
+import org.eclipse.team.internal.ccvs.core.*;
+import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
+import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
+import org.eclipse.team.internal.ccvs.ui.Policy;
+import org.eclipse.ui.IWorkbenchPart;
+
+/**
+ * This action marks the local resource as merged by updating the base
+ * resource revision to match the remote resource revision
+ */
+public class SubscriberConfirmMergedOperation extends CVSSubscriberOperation {
+
+ public SubscriberConfirmMergedOperation(IWorkbenchPart part, IDiffElement[] elements) {
+ super(part, elements);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ui.actions.TeamOperation#getJobName()
+ */
+ protected String getJobName() {
+ SyncInfoSet syncSet = getSyncInfoSet();
+ return Policy.bind("SubscriberConfirmMergedAction.jobName", new Integer(syncSet.size()).toString()); //$NON-NLS-1$
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ccvs.ui.subscriber.CVSSubscriberOperation#run(org.eclipse.team.core.synchronize.SyncInfoSet, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ protected void run(SyncInfoSet syncSet, IProgressMonitor monitor) throws CVSException {
+ SyncInfo[] syncResources = syncSet.getSyncInfos();
+ monitor.beginTask(null, 100 * syncResources.length);
+ try {
+ for (int i = 0; i < syncResources.length; i++) {
+ SyncInfo info = syncResources[i];
+ if (!makeOutgoing(info, Policy.subMonitorFor(monitor, 100))) {
+ // Failure was logged in makeOutgoing
+ }
+ }
+ } catch (TeamException e) {
+ handle(e);
+ } finally {
+ monitor.done();
+ }
+ }
+
+ private boolean makeOutgoing(SyncInfo info, IProgressMonitor monitor) throws CVSException, TeamException {
+ monitor.beginTask(null, 100);
+ try {
+ CVSSyncInfo cvsInfo = getCVSSyncInfo(info);
+ if (cvsInfo == null) {
+ CVSUIPlugin.log(IStatus.ERROR, Policy.bind("SubscriberConfirmMergedAction.0", cvsInfo.getLocal().getFullPath().toString()), null); //$NON-NLS-1$
+ return false;
+ }
+ // Make sure the parent is managed
+ ICVSFolder parent = CVSWorkspaceRoot.getCVSFolderFor(cvsInfo.getLocal().getParent());
+ if (!parent.isCVSFolder()) {
+ // the parents must be made outgoing before the child can
+ SyncInfo parentInfo = cvsInfo.getSubscriber().getSyncInfo(parent.getIResource());
+ if (!makeOutgoing(parentInfo, Policy.subMonitorFor(monitor, 20))) {
+ return false;
+ }
+ }
+ IStatus status = cvsInfo.makeOutgoing(Policy.subMonitorFor(monitor, 80));
+ if (status.getSeverity() == IStatus.ERROR) {
+ logError(status);
+ return false;
+ }
+ return true;
+ } finally {
+ monitor.done();
+ }
+ }
+}
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/WorkspaceUpdateAction.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/WorkspaceUpdateAction.java
index 0ec55baf5..a0ef952d9 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/WorkspaceUpdateAction.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/WorkspaceUpdateAction.java
@@ -10,25 +10,17 @@
*******************************************************************************/
package org.eclipse.team.internal.ccvs.ui.subscriber;
-import java.lang.reflect.InvocationTargetException;
-
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.team.core.TeamException;
-import org.eclipse.team.core.synchronize.*;
+import org.eclipse.compare.structuremergeviewer.IDiffElement;
+import org.eclipse.team.core.synchronize.FastSyncInfoFilter;
+import org.eclipse.team.core.synchronize.SyncInfo;
import org.eclipse.team.core.synchronize.FastSyncInfoFilter.SyncInfoDirectionFilter;
-import org.eclipse.team.internal.ccvs.core.CVSException;
-import org.eclipse.team.internal.ccvs.core.client.Command;
-import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption;
-import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
-import org.eclipse.team.internal.ccvs.ui.Policy;
-import org.eclipse.team.internal.ccvs.ui.operations.ReplaceOperation;
+import org.eclipse.team.internal.ui.actions.SubscriberAction;
+import org.eclipse.team.internal.ui.actions.SubscriberOperation;
+import org.eclipse.ui.IWorkbenchPart;
-/**
- * This action performs an update for the CVSWorkspaceSubscriber.
- */
-public class WorkspaceUpdateAction extends SafeUpdateAction {
+public class WorkspaceUpdateAction extends SubscriberAction {
+
+ private boolean promptBeforeUpdate;
/* (non-Javadoc)
* @see org.eclipse.team.ui.sync.SubscriberAction#getSyncInfoFilter()
@@ -38,61 +30,13 @@ public class WorkspaceUpdateAction extends SafeUpdateAction {
}
/* (non-Javadoc)
- * @see org.eclipse.team.internal.ccvs.ui.subscriber.SafeUpdateAction#runUpdateDeletions(org.eclipse.team.core.subscribers.SyncInfo[], org.eclipse.core.runtime.IProgressMonitor)
- */
- protected void runUpdateDeletions(SyncInfo[] nodes, IProgressMonitor monitor) throws TeamException {
- monitor.beginTask(null, nodes.length * 100);
- for (int i = 0; i < nodes.length; i++) {
- SyncInfo node = nodes[i];
- unmanage(node, Policy.subMonitorFor(monitor, 50));
- deleteAndKeepHistory(node.getLocal(), Policy.subMonitorFor(monitor, 50));
- }
- pruneEmptyParents(nodes);
- monitor.done();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.team.internal.ccvs.ui.subscriber.SafeUpdateAction#runSafeUpdate(org.eclipse.team.core.subscribers.SyncInfo[], org.eclipse.core.runtime.IProgressMonitor)
+ * @see org.eclipse.team.internal.ui.actions.SubscriberAction#getSubscriberOperation(org.eclipse.compare.structuremergeviewer.IDiffElement[])
*/
- protected void runSafeUpdate(SyncInfo[] nodes, IProgressMonitor monitor) throws TeamException {
- safeUpdate(getIResourcesFrom(nodes), new LocalOption[] { Command.DO_NOT_RECURSE }, monitor);
+ protected SubscriberOperation getSubscriberOperation(IWorkbenchPart part, IDiffElement[] elements) {
+ return new WorkspaceUpdateOperation(part, elements, promptBeforeUpdate);
}
- /* (non-Javadoc)
- * @see org.eclipse.team.internal.ccvs.ui.subscriber.SafeUpdateAction#overwriteUpdate(org.eclipse.team.ui.sync.SyncInfoSet, org.eclipse.core.runtime.IProgressMonitor)
- */
- protected void overwriteUpdate(SyncInfoSet syncSet, IProgressMonitor monitor) throws TeamException {
- try {
- new ReplaceOperation(getShell(), syncSet.getResources(), null /* tag */, false /* recurse */)
- .run(monitor);
- } catch (InvocationTargetException e) {
- throw CVSException.wrapException(e);
- } catch (InterruptedException e) {
- Policy.cancelOperation();
- }
-
+ public void setPromptBeforeUpdate(boolean prompt) {
+ promptBeforeUpdate = prompt;
}
-
- private void unmanage(SyncInfo element, IProgressMonitor monitor) throws CVSException {
- CVSWorkspaceRoot.getCVSResourceFor(element.getLocal()).unmanage(monitor);
- }
-
- private void deleteAndKeepHistory(IResource resource, IProgressMonitor monitor) throws CVSException {
- try {
- if (!resource.exists()) return;
- if (resource.getType() == IResource.FILE)
- ((IFile)resource).delete(false /* force */, true /* keep history */, monitor);
- else if (resource.getType() == IResource.FOLDER)
- ((IFolder)resource).delete(false /* force */, true /* keep history */, monitor);
- } catch (CoreException e) {
- throw CVSException.wrapException(e);
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.team.internal.ccvs.ui.subscriber.SafeUpdateAction#updated(org.eclipse.core.resources.IResource[])
- */
- protected void updated(IResource[] resources) throws TeamException {
- // Do nothing
- }
-}
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/WorkspaceUpdateOperation.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/WorkspaceUpdateOperation.java
new file mode 100644
index 000000000..3cdc653cb
--- /dev/null
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/WorkspaceUpdateOperation.java
@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.team.internal.ccvs.ui.subscriber;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.compare.structuremergeviewer.IDiffElement;
+import org.eclipse.core.resources.*;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.core.TeamException;
+import org.eclipse.team.core.synchronize.SyncInfo;
+import org.eclipse.team.core.synchronize.SyncInfoSet;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.client.Command;
+import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption;
+import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
+import org.eclipse.team.internal.ccvs.ui.Policy;
+import org.eclipse.team.internal.ccvs.ui.operations.ReplaceOperation;
+import org.eclipse.ui.IWorkbenchPart;
+
+/**
+ * This action performs an update for the CVSWorkspaceSubscriber.
+ */
+public class WorkspaceUpdateOperation extends SafeUpdateOperation {
+
+ protected WorkspaceUpdateOperation(IWorkbenchPart part, IDiffElement[] elements, boolean promptBeforeUpdate) {
+ super(part, elements, promptBeforeUpdate);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ccvs.ui.subscriber.SafeUpdateOperation#runUpdateDeletions(org.eclipse.team.core.synchronize.SyncInfo[], org.eclipse.core.runtime.IProgressMonitor)
+ */
+ protected void runUpdateDeletions(SyncInfo[] nodes, IProgressMonitor monitor) throws TeamException {
+ monitor.beginTask(null, nodes.length * 100);
+ for (int i = 0; i < nodes.length; i++) {
+ SyncInfo node = nodes[i];
+ unmanage(node, Policy.subMonitorFor(monitor, 50));
+ deleteAndKeepHistory(node.getLocal(), Policy.subMonitorFor(monitor, 50));
+ }
+ pruneEmptyParents(nodes);
+ monitor.done();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ccvs.ui.subscriber.SafeUpdateOperation#runSafeUpdate(org.eclipse.team.core.synchronize.SyncInfo[], org.eclipse.core.runtime.IProgressMonitor)
+ */
+ protected void runSafeUpdate(SyncInfo[] nodes, IProgressMonitor monitor) throws TeamException {
+ safeUpdate(getIResourcesFrom(nodes), new LocalOption[] { Command.DO_NOT_RECURSE }, monitor);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ccvs.ui.subscriber.SafeUpdateOperation#overwriteUpdate(org.eclipse.team.core.synchronize.SyncInfoSet, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ protected void overwriteUpdate(SyncInfoSet syncSet, IProgressMonitor monitor) throws TeamException {
+ try {
+ new ReplaceOperation(getShell(), syncSet.getResources(), null /* tag */, false /* recurse */)
+ .run(monitor);
+ } catch (InvocationTargetException e) {
+ throw CVSException.wrapException(e);
+ } catch (InterruptedException e) {
+ Policy.cancelOperation();
+ }
+
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ccvs.ui.subscriber.SafeUpdateOperation#updated(org.eclipse.core.resources.IResource[])
+ */
+ protected void updated(IResource[] resources) throws TeamException {
+ // Do nothing
+ }
+
+ private void unmanage(SyncInfo element, IProgressMonitor monitor) throws CVSException {
+ CVSWorkspaceRoot.getCVSResourceFor(element.getLocal()).unmanage(monitor);
+ }
+
+ private void deleteAndKeepHistory(IResource resource, IProgressMonitor monitor) throws CVSException {
+ try {
+ if (!resource.exists()) return;
+ if (resource.getType() == IResource.FILE)
+ ((IFile)resource).delete(false /* force */, true /* keep history */, monitor);
+ else if (resource.getType() == IResource.FOLDER)
+ ((IFolder)resource).delete(false /* force */, true /* keep history */, monitor);
+ } catch (CoreException e) {
+ throw CVSException.wrapException(e);
+ }
+ }
+
+}
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/wizards/SharingWizard.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/wizards/SharingWizard.java
index 754044ca1..a11012c5b 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/wizards/SharingWizard.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/wizards/SharingWizard.java
@@ -11,51 +11,30 @@
package org.eclipse.team.internal.ccvs.ui.wizards;
-import java.io.ByteArrayInputStream;
-import java.io.DataInputStream;
-import java.io.IOException;
+import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.util.Properties;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.QualifiedName;
-import org.eclipse.core.runtime.SubProgressMonitor;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.dialogs.IDialogSettings;
-import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.core.resources.*;
+import org.eclipse.core.runtime.*;
+import org.eclipse.jface.dialogs.*;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.team.core.TeamException;
-import org.eclipse.team.internal.ccvs.core.CVSException;
-import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin;
-import org.eclipse.team.internal.ccvs.core.CVSTag;
-import org.eclipse.team.internal.ccvs.core.ICVSFile;
-import org.eclipse.team.internal.ccvs.core.ICVSFolder;
-import org.eclipse.team.internal.ccvs.core.ICVSRemoteFolder;
-import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation;
-import org.eclipse.team.internal.ccvs.core.ICVSResourceVisitor;
+import org.eclipse.team.internal.ccvs.core.*;
import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
import org.eclipse.team.internal.ccvs.core.resources.RemoteFolder;
import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo;
-import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
-import org.eclipse.team.internal.ccvs.ui.ICVSUIConstants;
-import org.eclipse.team.internal.ccvs.ui.IHelpContextIds;
+import org.eclipse.team.internal.ccvs.ui.*;
import org.eclipse.team.internal.ccvs.ui.Policy;
-import org.eclipse.team.internal.ccvs.ui.TagSelectionDialog;
import org.eclipse.team.internal.ccvs.ui.operations.ReconcileProjectOperation;
import org.eclipse.team.internal.ccvs.ui.operations.ShareProjectOperation;
import org.eclipse.team.internal.ccvs.ui.subscriber.WorkspaceSynchronizeParticipant;
import org.eclipse.team.ui.IConfigurationWizard;
import org.eclipse.team.ui.TeamUI;
-import org.eclipse.team.ui.synchronize.subscriber.SubscriberParticipant;
import org.eclipse.ui.IWorkbench;
/**
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/Utils.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/Utils.java
index a02f4537b..1a942e1c2 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/Utils.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/Utils.java
@@ -222,6 +222,24 @@ public class Utils {
new ProgressMonitorDialog(parent).run(cancelable, cancelable, runnable);
}
+ public static Shell getShell(IWorkbenchSite site) {
+ if(site != null) {
+ Shell shell = site.getShell();
+ if (!shell.isDisposed())
+ return shell;
+ }
+ IWorkbench workbench = TeamUIPlugin.getPlugin().getWorkbench();
+ if (workbench != null) {
+ IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
+ if (window != null) {
+ return window.getShell();
+ }
+ }
+ // Fallback to using the display
+ Display display = Display.getDefault();
+ if (display.isDisposed()) return null;
+ return new Shell(display);
+ }
/*
* This method is only for use by the Target Management feature (see bug
* 16509). @param t
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/ITeamRunnableContext.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/ITeamRunnableContext.java
index 36218fc9a..184b68241 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/ITeamRunnableContext.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/ITeamRunnableContext.java
@@ -12,7 +12,6 @@ package org.eclipse.team.internal.ui.actions;
import java.lang.reflect.InvocationTargetException;
-import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.swt.widgets.Shell;
@@ -31,12 +30,7 @@ public interface ITeamRunnableContext {
* override this to provide progress in some other way (Progress Monitor or
* job).
*/
- public abstract void run(
- String title,
- ISchedulingRule schedulingRule,
- boolean postponeBuild,
- IRunnableWithProgress runnable)
- throws InvocationTargetException, InterruptedException;
+ public abstract void run(IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException;
/**
* Get a shell that can be used to prompt the user.
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/JobRunnableContext.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/JobRunnableContext.java
index 806a46a8a..2ee0a9034 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/JobRunnableContext.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/JobRunnableContext.java
@@ -20,61 +20,38 @@ import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.internal.ui.Utils;
-import org.eclipse.ui.*;
+import org.eclipse.ui.IWorkbenchSite;
/**
* This runnable context executes it's operation in the context of a background job.
*/
-public class JobRunnableContext implements ITeamRunnableContext {
+public final class JobRunnableContext implements ITeamRunnableContext {
private IJobChangeListener listener;
private IWorkbenchSite site;
+ private String jobName;
+ private ISchedulingRule schedulingRule;
+ private boolean postponeBuild;
- public JobRunnableContext() {
- this(null, null);
+ public JobRunnableContext(String jobName) {
+ this(jobName, null, null);
}
- public JobRunnableContext(IJobChangeListener listener, IWorkbenchSite site) {
+ public JobRunnableContext(String jobName, IJobChangeListener listener, IWorkbenchSite site) {
+ this.jobName = jobName;
this.listener = listener;
this.site = site;
}
- protected IStatus run(IRunnableWithProgress runnable, IProgressMonitor monitor) {
- try {
- runnable.run(monitor);
- } catch (InvocationTargetException e) {
- return TeamException.asTeamException(e).getStatus();
- } catch (InterruptedException e) {
- return Status.OK_STATUS;
- }
- return Status.OK_STATUS;
- }
-
- protected Job getBasicJob(String title, final IRunnableWithProgress runnable) {
- return new Job(title) {
- public IStatus run(IProgressMonitor monitor) {
- return JobRunnableContext.this.run(runnable, monitor);
- }
- };
- }
-
- protected Job getWorkspaceJob(String title, final IRunnableWithProgress runnable) {
- return new WorkspaceJob(title) {
- public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
- return JobRunnableContext.this.run(runnable, monitor);
- }
- };
- }
-
/* (non-Javadoc)
* @see org.eclipse.team.internal.ccvs.ui.operations.ITeamRunnableContext#run(java.lang.String, boolean, org.eclipse.jface.operation.IRunnableWithProgress)
*/
- public void run(String title, ISchedulingRule schedulingRule, boolean postponeBuild, IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException {
+ public void run(IRunnableWithProgress runnable) {
Job job;
if (schedulingRule == null && !postponeBuild) {
- job = getBasicJob(title, runnable);
+ job = getBasicJob(runnable);
} else {
- job = getWorkspaceJob(title, runnable);
+ job = getWorkspaceJob(runnable);
if (schedulingRule != null) {
job.setRule(schedulingRule);
}
@@ -93,15 +70,73 @@ public class JobRunnableContext implements ITeamRunnableContext {
Display.getDefault().syncExec(
new Runnable() {
public void run() {
- IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
- if (window == null) {
- Display display = Display.getDefault();
- newShell[0] = new Shell(display);
- } else {
- newShell[0] = window.getShell();
- }
+ newShell[0] = Utils.getShell(site);
}
});
return newShell[0];
}
+
+ /**
+ * Returns whether the auto-build will be postponed while this
+ * context is executing a runnable.
+ * @return whether the auto-build will be postponed while this
+ * context is executing a runnable.
+ */
+ public boolean isPostponeBuild() {
+ return postponeBuild;
+ }
+
+ /**
+ * Set whether the auto-build will be postponed while this
+ * context is executing a runnable.
+ * @param postponeBuild whether to postpone the auto-build.
+ */
+ public void setPostponeBuild(boolean postponeBuild) {
+ this.postponeBuild = postponeBuild;
+ }
+
+ /**
+ * Return the scheduling rule that will be obtained before the context
+ * executes a runnable or <code>null</code> if no scheduling rule is to be onbtained.
+ * @return the schedulingRule to be obtained or <code>null</code>.
+ */
+ public ISchedulingRule getSchedulingRule() {
+ return schedulingRule;
+ }
+
+ /**
+ * Set the scheduling rule that will be obtained before the context
+ * executes a runnable or <code>null</code> if no scheduling rule is to be onbtained.
+ * @param schedulingRule The schedulingRule to be obtained or <code>null</code>.
+ */
+ public void setSchedulingRule(ISchedulingRule schedulingRule) {
+ this.schedulingRule = schedulingRule;
+ }
+
+ /* private */ IStatus run(IRunnableWithProgress runnable, IProgressMonitor monitor) {
+ try {
+ runnable.run(monitor);
+ } catch (InvocationTargetException e) {
+ return TeamException.asTeamException(e).getStatus();
+ } catch (InterruptedException e) {
+ return Status.OK_STATUS;
+ }
+ return Status.OK_STATUS;
+ }
+
+ private Job getBasicJob(final IRunnableWithProgress runnable) {
+ return new Job(jobName) {
+ public IStatus run(IProgressMonitor monitor) {
+ return JobRunnableContext.this.run(runnable, monitor);
+ }
+ };
+ }
+
+ private Job getWorkspaceJob(final IRunnableWithProgress runnable) {
+ return new WorkspaceJob(jobName) {
+ public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
+ return JobRunnableContext.this.run(runnable, monitor);
+ }
+ };
+ }
}
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/ProgressDialogRunnableContext.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/ProgressDialogRunnableContext.java
index 8ad5daffc..0896533b1 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/ProgressDialogRunnableContext.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/ProgressDialogRunnableContext.java
@@ -20,7 +20,6 @@ import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.team.internal.ui.Policy;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.progress.IProgressService;
@@ -32,22 +31,74 @@ public class ProgressDialogRunnableContext implements ITeamRunnableContext {
private Shell shell;
private IRunnableContext runnableContext;
+ private ISchedulingRule schedulingRule;
+ private boolean postponeBuild;
public ProgressDialogRunnableContext(Shell shell) {
this.shell = shell;
}
/**
- * Run the given runnable in the context of the receiver. By default, the
- * progress is provided by the active workbench windows but subclasses may
- * override this to provide progress in some other way (Progress Monitor or
- * job).
+ * Returns whether the auto-build will be postponed while this
+ * context is executing a runnable.
+ * @return whether the auto-build will be postponed while this
+ * context is executing a runnable.
*/
- public void run(String title, ISchedulingRule schedulingRule, boolean postponeBuild, IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException {
- getRunnableContext().run(true /* fork */, true /* cancelable */, wrapRunnable(title, schedulingRule, postponeBuild, runnable));
+ public boolean isPostponeBuild() {
+ return postponeBuild;
+ }
+
+ /**
+ * Set whether the auto-build will be postponed while this
+ * context is executing a runnable.
+ * @param postponeBuild whether to postpone the auto-build.
+ */
+ public void setPostponeBuild(boolean postponeBuild) {
+ this.postponeBuild = postponeBuild;
+ }
+
+ /**
+ * Return the scheduling rule that will be obtained before the context
+ * executes a runnable or <code>null</code> if no scheduling rule is to be onbtained.
+ * @return the schedulingRule to be obtained or <code>null</code>.
+ */
+ public ISchedulingRule getSchedulingRule() {
+ return schedulingRule;
+ }
+
+ /**
+ * Set the scheduling rule that will be obtained before the context
+ * executes a runnable or <code>null</code> if no scheduling rule is to be onbtained.
+ * @param schedulingRule The schedulingRule to be obtained or <code>null</code>.
+ */
+ public void setSchedulingRule(ISchedulingRule schedulingRule) {
+ this.schedulingRule = schedulingRule;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ccvs.ui.operations.CVSRunnableContext#getShell()
+ */
+ public Shell getShell() {
+ return shell;
+ }
+
+ /**
+ * Set the runnable context that is used to execute the runnable. By default,
+ * the workbench's progress service is used by clients can provide their own.
+ * @param runnableContext the runnable contentx used to execute runnables.
+ */
+ public void setRunnableContext(IRunnableContext runnableContext) {
+ this.runnableContext = runnableContext;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ui.actions.ITeamRunnableContext#run(org.eclipse.jface.operation.IRunnableWithProgress)
+ */
+ public void run(IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException {
+ getRunnableContext().run(true /* fork */, true /* cancelable */, wrapRunnable(runnable));
}
- protected IRunnableContext getRunnableContext() {
+ private IRunnableContext getRunnableContext() {
if (runnableContext == null) {
return new IRunnableContext() {
public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable)
@@ -64,13 +115,12 @@ public class ProgressDialogRunnableContext implements ITeamRunnableContext {
* Return an IRunnableWithProgress that sets the task name for the progress monitor
* and runs in a workspace modify operation if requested.
*/
- private IRunnableWithProgress wrapRunnable(final String title, final ISchedulingRule schedulingRule, final boolean postponeBuild, final IRunnableWithProgress runnable) {
+ private IRunnableWithProgress wrapRunnable(final IRunnableWithProgress runnable) {
return new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
- monitor.beginTask(title, 100);
try {
if (schedulingRule == null && !postponeBuild) {
- runnable.run(Policy.subMonitorFor(monitor, 100));
+ runnable.run(monitor);
} else {
final Exception[] exception = new Exception[] { null };
ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
@@ -83,7 +133,7 @@ public class ProgressDialogRunnableContext implements ITeamRunnableContext {
exception[0] = e;
}
}
- }, schedulingRule, 0 /* allow updates */, Policy.subMonitorFor(monitor, 100));
+ }, schedulingRule, 0 /* allow updates */, monitor);
if (exception[0] != null) {
if (exception[0] instanceof InvocationTargetException) {
throw (InvocationTargetException)exception[0];
@@ -94,32 +144,9 @@ public class ProgressDialogRunnableContext implements ITeamRunnableContext {
}
} catch (CoreException e) {
throw new InvocationTargetException(e);
- } finally {
- monitor.done();
}
}
};
}
- /* (non-Javadoc)
- * @see org.eclipse.team.internal.ccvs.ui.operations.CVSRunnableContext#getShell()
- */
- public Shell getShell() {
- return shell;
- }
-
- /**
- * Set the shell to be used by the owner of this context to prompt the user.
- * @param shell
- */
- public void setShell(Shell shell) {
- this.shell = shell;
- }
-
- /**
- * @param runnableContext
- */
- public void setRunnableContext(IRunnableContext runnableContext) {
- this.runnableContext = runnableContext;
- }
}
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/SubscriberAction.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/SubscriberAction.java
index 6f0dc745b..58e456b03 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/SubscriberAction.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/SubscriberAction.java
@@ -11,39 +11,28 @@
package org.eclipse.team.internal.ui.actions;
import java.lang.reflect.InvocationTargetException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
import org.eclipse.compare.structuremergeviewer.IDiffElement;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.jobs.*;
import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.team.core.TeamException;
import org.eclipse.team.core.synchronize.*;
-import org.eclipse.team.internal.core.TeamPlugin;
-import org.eclipse.team.internal.ui.TeamUIPlugin;
import org.eclipse.team.internal.ui.Utils;
import org.eclipse.team.ui.synchronize.viewers.SyncInfoModelElement;
-import org.eclipse.team.ui.synchronize.viewers.SynchronizeModelElement;
import org.eclipse.ui.*;
/**
* This action provides utilities for performing operations on selections that
- * contain instances of {@link SyncInfoModelElement}. Subclasses can use this support
- * to:
- * <ul>
- * <li>provides easy filtering of selection
- * <li>provides scheduling action via workbench part (provide feedback via view)
- * <li>provides support for running action in background or foreground
- * <li>provides support for locking workspace resources
- * </ul>
+ * are obtained from a view populated by a
+ * {@link org.eclipse.team.ui.synchronize.viewers.SynchronizeModelProvider}.
+ * Subclasses can use this support to filter the selection in order to
+ * determine action enablement and generate the input to a {@link SubscriberOperation}.
* @see SyncInfo
* @see SyncInfoSet
- * @see SyncInfoModelElement
+ * @see org.eclipse.team.ui.synchronize.viewers.SynchronizeModelProvider
+ * @see org.eclipse.team.internal.ui.actions.SubscriberOperation
* @since 3.0
*/
public abstract class SubscriberAction implements IObjectActionDelegate, IViewActionDelegate, IEditorActionDelegate {
@@ -57,10 +46,8 @@ public abstract class SubscriberAction implements IObjectActionDelegate, IViewAc
public final void run(IAction action) {
// TODO: We used to prompt for unsaved changes in any editor. We don't anymore. Would
// it be better to prompt for unsaved changes to editors affected by this action?
- SyncInfoSet syncSet = makeSyncInfoSetFromSelection(getFilteredSyncInfos());
- if (syncSet == null || syncSet.isEmpty()) return;
try {
- getRunnableContext().run(getJobName(syncSet), getSchedulingRule(syncSet), true, getRunnable(syncSet));
+ getSubscriberOperation(part, getFilteredDiffElements()).run();
} catch (InvocationTargetException e) {
handle(e);
} catch (InterruptedException e) {
@@ -69,52 +56,49 @@ public abstract class SubscriberAction implements IObjectActionDelegate, IViewAc
}
/**
- * Subsclasses must override to provide behavior for the action.
- * @param syncSet the set of filtered sync info objects on which to perform the action.
- * @param monitor a progress monitor, or <code>null</code> if progress
- * reporting and cancellation are not desired
- * @throws TeamException if something went wrong running the action
+ * Return the subscriber operation associated with this action. This operation
+ * will be run when the action is run. Subclass may implement this method and provide
+ * an operation subclass or may override the <code>run(IAction)</code> method directly
+ * if they choose not to implement a <code>SubscriberOperation</code>.
+ * @param elements the selected diff element for which this action is enabled.
+ * @return the subscriber operation to be run by this action.
*/
- protected abstract void run(SyncInfoSet syncSet, IProgressMonitor monitor) throws TeamException;
+ protected abstract SubscriberOperation getSubscriberOperation(IWorkbenchPart part, IDiffElement[] elements);
- /**
- * Subsclasses may override to perform custom processing on the selection before
- * the action is run. This can be used to prompt the user for more information.
- * @param infos the
+ /**
+ * Generic error handling code that uses an error dialog to show the error to the
+ * user. Subclasses can use this method and/or override it.
+ * @param e the exception that occurred.
*/
- protected SyncInfoSet makeSyncInfoSetFromSelection(SyncInfo[] infos) {
- return new SyncInfoSet(infos);
- }
-
protected void handle(Exception e) {
Utils.handle(e);
}
/**
- * This method returns all instances of SyncInfo that are in the current
- * selection. For a tree view, this is any descendants of the selected resource that are
- * contained in the view.
+ * This method returns all instances of IDiffElement that are in the current
+ * selection.
*
- * @return the selected resources
+ * @return the selected elements
*/
- protected IDiffElement[] getDiffElements() {
- return Utils.getDiffNodes(((IStructuredSelection)selection).toArray());
+ protected final IDiffElement[] getSelectedDiffElements() {
+ return Utils.getDiffNodes(selection.toArray());
}
/**
* The default enablement behavior for subscriber actions is to enable
* the action if there is at least one SyncInfo in the selection
- * for which the action is enabled (determined by invoking
- * <code>isEnabled(SyncInfo)</code>).
+ * for which the action's filter passes.
* @see org.eclipse.team.internal.ui.actions.TeamAction#isEnabled()
*/
- protected boolean isEnabled() throws TeamException {
+ protected boolean isEnabled() {
return (getFilteredDiffElements().length > 0);
}
/**
+ * Filter uses to filter the user selection to contain only those
+ * elements for which this action is enabled.
* Default filter includes all out-of-sync elements in the current
- * selection.
+ * selection. Subsclasses may override.
* @return a sync info filter which selects all out-of-sync resources.
*/
protected FastSyncInfoFilter getSyncInfoFilter() {
@@ -125,8 +109,8 @@ public abstract class SubscriberAction implements IObjectActionDelegate, IViewAc
* Return the selected diff element for which this action is enabled.
* @return the list of selected diff elements for which this action is enabled.
*/
- protected IDiffElement[] getFilteredDiffElements() {
- IDiffElement[] elements = getDiffElements();
+ protected final IDiffElement[] getFilteredDiffElements() {
+ IDiffElement[] elements = getSelectedDiffElements();
List filtered = new ArrayList();
for (int i = 0; i < elements.length; i++) {
IDiffElement e = elements[i];
@@ -140,120 +124,6 @@ public abstract class SubscriberAction implements IObjectActionDelegate, IViewAc
return (IDiffElement[]) filtered.toArray(new IDiffElement[filtered.size()]);
}
- /**
- * Return the selected SyncInfo for which this action is enabled.
- * @return the selected SyncInfo for which this action is enabled.
- */
- protected SyncInfo[] getFilteredSyncInfos() {
- IDiffElement[] elements = getFilteredDiffElements();
- List filtered = new ArrayList();
- for (int i = 0; i < elements.length; i++) {
- IDiffElement e = elements[i];
- if (e instanceof SyncInfoModelElement) {
- filtered.add(((SyncInfoModelElement)e).getSyncInfo());
- }
- }
- return (SyncInfo[]) filtered.toArray(new SyncInfo[filtered.size()]);
- }
-
- private void markBusy(IDiffElement[] elements, boolean isBusy) {
- for (int i = 0; i < elements.length; i++) {
- IDiffElement element = elements[i];
- if (element instanceof SynchronizeModelElement) {
- ((SynchronizeModelElement)element).setPropertyToRoot(SynchronizeModelElement.BUSY_PROPERTY, isBusy);
- }
- }
- }
-
- /**
- * Uses the {@link #canRunAsJob()} hint to return a {@link ITeamRunnableContext}.
- *
- * @return the runnable context in which to run this action.
- */
- protected ITeamRunnableContext getRunnableContext() {
- if (canRunAsJob()) {
- // mark resources that will be affected by job
- final IDiffElement[] affectedElements = getFilteredDiffElements();
- markBusy(affectedElements, true);
-
- // register to unmark when job is finished
- IJobChangeListener listener = new JobChangeAdapter() {
- public void done(IJobChangeEvent event) {
- markBusy(affectedElements, false);
- }
- };
- return new JobRunnableContext(listener, getSite());
- } else {
- return new ProgressDialogRunnableContext(getShell());
- }
- }
-
- /**
- * If this action can safely be run in the background, then subclasses can
- * override this method and return <code>true</code>. This will make their
- * action run in a {@link Job}.
- *
- * @return <code>true</code> if this action can be run in the background and
- * <code>false</code> otherwise.
- */
- protected boolean canRunAsJob() {
- return false;
- }
-
- /**
- * Return the job name to be used if the action can run as a job.
- *
- * @param syncSet
- * @return
- */
- protected String getJobName(SyncInfoSet syncSet) {
- return ""; //$NON-NLS-1$
- }
-
- /**
- * Return a scheduling rule that includes all resources that will be operated
- * on by the subscriber action. The default behavior is to include all projects
- * effected by the operation. Subclasses may override.
- *
- * @param syncSet
- * @return
- */
- protected ISchedulingRule getSchedulingRule(SyncInfoSet syncSet) {
- IResource[] resources = syncSet.getResources();
- Set set = new HashSet();
- for (int i = 0; i < resources.length; i++) {
- IResource resource = resources[i];
- set.add(resource.getProject());
- }
- IProject[] projects = (IProject[]) set.toArray(new IProject[set.size()]);
- if (projects.length == 1) {
- return projects[0];
- } else {
- return new MultiRule(projects);
- }
- }
-
- protected IRunnableWithProgress getRunnable(final SyncInfoSet syncSet) {
- return new IRunnableWithProgress() {
- public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
- try {
- SubscriberAction.this.run(syncSet, monitor);
- } catch (TeamException e) {
- throw new InvocationTargetException(e);
- }
- }
- };
- }
-
- private IWorkbenchSite getSite() {
- IWorkbenchSite site = null;
- if(part != null) {
- site = part.getSite();
- }
- return site;
- }
-
-
/* (non-Javadoc)
* @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
*/
@@ -261,7 +131,6 @@ public abstract class SubscriberAction implements IObjectActionDelegate, IViewAc
this.part = targetPart;
}
-
/* (non-Javadoc)
* @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
*/
@@ -269,8 +138,8 @@ public abstract class SubscriberAction implements IObjectActionDelegate, IViewAc
this.part = view;
}
- /*
- * Method declared on IActionDelegate.
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
*/
public void selectionChanged(IAction action, ISelection selection) {
if (selection instanceof IStructuredSelection) {
@@ -291,18 +160,7 @@ public abstract class SubscriberAction implements IObjectActionDelegate, IViewAc
* This method can be overridden by subclasses but should not be invoked by them.
*/
protected void setActionEnablement(IAction action) {
- try {
- action.setEnabled(isEnabled());
- } catch (TeamException e) {
- if (e.getStatus().getCode() == IResourceStatus.OUT_OF_SYNC_LOCAL) {
- // Enable the action to allow the user to discover the problem
- action.setEnabled(true);
- } else {
- action.setEnabled(false);
- // We should not open a dialog when determining menu enablements so log it instead
- TeamPlugin.log(e);
- }
- }
+ action.setEnabled(isEnabled());
}
/* (non-Javadoc)
@@ -315,15 +173,11 @@ public abstract class SubscriberAction implements IObjectActionDelegate, IViewAc
// editor actions? Go figure...
}
- protected Shell getShell() {
- if(part != null) {
- return part.getSite().getShell();
- } else {
- IWorkbench workbench = TeamUIPlugin.getPlugin().getWorkbench();
- if (workbench == null) return null;
- IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
- if (window == null) return null;
- return window.getShell();
- }
+ /**
+ * Returns the workbench part assigned to this action or <code>null</code>.
+ * @return Returns the part.
+ */
+ public IWorkbenchPart getPart() {
+ return part;
}
} \ No newline at end of file
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/SubscriberOperation.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/SubscriberOperation.java
new file mode 100644
index 000000000..38777a7bb
--- /dev/null
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/SubscriberOperation.java
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.team.internal.ui.actions;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.compare.structuremergeviewer.IDiffElement;
+import org.eclipse.core.runtime.jobs.IJobChangeEvent;
+import org.eclipse.team.core.synchronize.SyncInfo;
+import org.eclipse.team.core.synchronize.SyncInfoSet;
+import org.eclipse.team.ui.synchronize.viewers.SyncInfoModelElement;
+import org.eclipse.team.ui.synchronize.viewers.SynchronizeModelElement;
+import org.eclipse.ui.IWorkbenchPart;
+
+
+/**
+ * A subscriber operation provides access to a SyncInfoSet generated
+ * from the selection of the elements generated by a
+ * {@link org.eclipse.team.ui.synchronize.viewers.SynchronizeModelProvider}.
+ * In addition, the elements in the view will show busy indication if this
+ * operation is run as a job.
+ *
+ * @see SyncInfoSet
+ */
+public abstract class SubscriberOperation extends TeamOperation {
+
+ private IDiffElement[] elements;
+
+ /**
+ * Create a subscriber operation that will operate on the given diff elements
+ * that were obtained from a view populated by a
+ * {@link org.eclipse.team.ui.synchronize.viewers.SynchronizeModelProvider}.
+ * @param elements
+ */
+ protected SubscriberOperation(IWorkbenchPart part, IDiffElement[] elements) {
+ super(part);
+ this.elements = elements;
+ }
+
+ /**
+ * Returns a sync info set that contains the {@link SyncInfo} for the
+ * elements of this operations.
+ */
+ protected SyncInfoSet getSyncInfoSet() {
+ return makeSyncInfoSetFromSelection(getSyncInfos());
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.jobs.JobChangeAdapter#scheduled(org.eclipse.core.runtime.jobs.IJobChangeEvent)
+ */
+ public void scheduled(IJobChangeEvent event) {
+ super.scheduled(event);
+ markBusy(elements, true);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.jobs.JobChangeAdapter#done(org.eclipse.core.runtime.jobs.IJobChangeEvent)
+ */
+ public void done(IJobChangeEvent event) {
+ markBusy(elements, false);
+ super.done(event);
+ }
+
+ private void markBusy(IDiffElement[] elements, boolean isBusy) {
+ for (int i = 0; i < elements.length; i++) {
+ IDiffElement element = elements[i];
+ if (element instanceof SynchronizeModelElement) {
+ ((SynchronizeModelElement)element).setPropertyToRoot(SynchronizeModelElement.BUSY_PROPERTY, isBusy);
+ }
+ }
+ }
+
+ /*
+ * Return the selected SyncInfo for which this action is enabled.
+ * @return the selected SyncInfo for which this action is enabled.
+ */
+ private SyncInfo[] getSyncInfos() {
+ List filtered = new ArrayList();
+ for (int i = 0; i < elements.length; i++) {
+ IDiffElement e = elements[i];
+ if (e instanceof SyncInfoModelElement) {
+ filtered.add(((SyncInfoModelElement)e).getSyncInfo());
+ }
+ }
+ return (SyncInfo[]) filtered.toArray(new SyncInfo[filtered.size()]);
+ }
+
+ /*
+ * Return a sync info set that contains the given sync info
+ */
+ private SyncInfoSet makeSyncInfoSetFromSelection(SyncInfo[] infos) {
+ return new SyncInfoSet(infos);
+ }
+}
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/TeamOperation.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/TeamOperation.java
new file mode 100644
index 000000000..ad3dfeece
--- /dev/null
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/TeamOperation.java
@@ -0,0 +1,154 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.team.internal.ui.actions;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
+import org.eclipse.core.runtime.jobs.JobChangeAdapter;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.team.internal.ui.Utils;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchSite;
+
+/**
+ * An operation that can be configured to run in the foreground using
+ * the {@link org.eclipse.ui.progress.IProgressService} or the background
+ * as a {@link org.eclipse.core.runtime.Job}. The executione context is determined
+ * by what is returned by the {@link #canRunAsJob()} hint which may be overriden by subclasses.
+ * Subsclass must override the <code>run(IProgressMonitor)</code> method to perform
+ * the behavior of the operation in the desired execution context.
+ * <p>
+ * If this operation is run as a job, it is registered with the job as a
+ * {@link org.eclipse.core.runtime.jobs.IJobChangeListener} and is scheduled with
+ * the part of this operation if it is not <code>null</code>.
+ * Subsclasses can override the methods of this
+ * interface to receive job change notificaton.
+ *
+ * @see org.eclipse.ui.progress.IProgressService
+ * @see org.eclipse.core.runtime.Job
+ * @see org.eclipse.core.runtime.ISchedulingRule
+ * @see org.eclipse.core.runtime.jobs.IJobChangeListener
+ */
+public abstract class TeamOperation extends JobChangeAdapter implements IRunnableWithProgress {
+
+ private IWorkbenchPart part;
+
+ /**
+ * Create an team operation associated with the given part.
+ * @param part the part the operation is associated with or <code>null</code>
+ */
+ protected TeamOperation(IWorkbenchPart part) {
+ this.part = part;
+ }
+
+ /**
+ * Run the operation in a context that is determined by the <code>canRunAsJob()</code>
+ * hint. If this operation can run as a job then it will be run in a background thread.
+ * Otherwise it will run in the foreground and block the caller.
+ */
+ public final void run() throws InvocationTargetException, InterruptedException {
+ getRunnableContext().run(this);
+ }
+
+ /**
+ * Returns the scheduling rule that is to be obtained before this
+ * operation is executed by it's context or <code>null</code> if
+ * no scheduling rule is to be obtained. If the operation is run
+ * as a job, the schdulin rule is used as the schduling rule of the
+ * job. Otherwise, it is obtained before execution of the operation
+ * occurs.
+ * <p>
+ * By default, no scheduling
+ * rule is obtained. Sublcasses can override to in order ot obtain a
+ * scheduling rule or can obtain schduling rules withing their operation
+ * if finer grained schduling is desired.
+ * @return the schduling rule to be obtained by this operation
+ * or <code>null</code>
+ */
+ protected ISchedulingRule getSchedulingRule() {
+ return null;
+ }
+
+ /**
+ * Return whether the auto-build should be postponed until after
+ * the operation is complete. The default is to postpone the auto-build.
+ * subclas can override.
+ * @return whether to postpone the auto-build while the operation is executing
+ */
+ protected boolean isPostponeAutobuild() {
+ return true;
+ }
+
+ /**
+ * If this operation can safely be run in the background, then subclasses can
+ * override this method and return <code>true</code>. This will make their
+ * action run in a {@link org.eclipse.core.runtime.Job}.
+ * Subsclass that override this method should
+ * also override the <code>getJobName()</code> method.
+ *
+ * @return <code>true</code> if this action can be run in the background and
+ * <code>false</code> otherwise.
+ */
+ protected boolean canRunAsJob() {
+ return false;
+ }
+
+ /**
+ * Return the job name to be used if the action can run as a job. (i.e.
+ * if <code>canRunAsJob()</code> returns <code>true</code>).
+ *
+ * @return the string to be used as the job name
+ */
+ protected String getJobName() {
+ return ""; //$NON-NLS-1$
+ }
+
+ /**
+ * Return a shell that can be used by the operation to display dialogs, etc.
+ * @return a shell
+ */
+ protected Shell getShell() {
+ return Utils.getShell(getSite());
+ }
+
+ /*
+ * Uses the {@link #canRunAsJob()} hint to return a {@link ITeamRunnableContext}
+ * that is used to execute the <code>run(SyncInfoSet, IProgressMonitor)</code>
+ * method of this action.
+ *
+ * @param syncSet the sync info set containing the selected elements for which this
+ * action is enabled.
+ * @return the runnable context in which to run this action.
+ */
+ private ITeamRunnableContext getRunnableContext() {
+ if (canRunAsJob()) {
+ JobRunnableContext context = new JobRunnableContext(getJobName(), this, getSite());
+ context.setPostponeBuild(isPostponeAutobuild());
+ context.setSchedulingRule(getSchedulingRule());
+ return context;
+ } else {
+ ProgressDialogRunnableContext context = new ProgressDialogRunnableContext(getShell());
+ context.setPostponeBuild(isPostponeAutobuild());
+ context.setSchedulingRule(getSchedulingRule());
+ return context;
+ }
+ }
+
+ private IWorkbenchSite getSite() {
+ IWorkbenchSite site = null;
+ if(part != null) {
+ site = part.getSite();
+ }
+ return site;
+ }
+}
diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/CVSMergeSubscriberTest.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/CVSMergeSubscriberTest.java
index 8b7ad2def..0b01cf083 100644
--- a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/CVSMergeSubscriberTest.java
+++ b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/CVSMergeSubscriberTest.java
@@ -16,18 +16,13 @@ import java.lang.reflect.InvocationTargetException;
import junit.framework.Test;
import junit.framework.TestSuite;
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.*;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.team.core.RepositoryProvider;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.core.subscribers.Subscriber;
import org.eclipse.team.core.synchronize.SyncInfo;
-import org.eclipse.team.core.synchronize.SyncInfoSet;
-import org.eclipse.team.internal.ccvs.core.CVSException;
-import org.eclipse.team.internal.ccvs.core.CVSMergeSubscriber;
-import org.eclipse.team.internal.ccvs.core.CVSTag;
+import org.eclipse.team.internal.ccvs.core.*;
import org.eclipse.team.internal.ccvs.core.client.Command;
import org.eclipse.team.tests.ccvs.core.CVSTestSetup;
@@ -71,8 +66,8 @@ public class CVSMergeSubscriberTest extends CVSSyncSubscriberTest {
}
private void mergeResources(Subscriber subscriber, SyncInfo[] infos, boolean allowOverwrite) throws TeamException, InvocationTargetException, InterruptedException {
- TestMergeUpdateAction action = new TestMergeUpdateAction(allowOverwrite);
- action.getRunnable(new SyncInfoSet(infos)).run(DEFAULT_MONITOR);
+ TestMergeUpdateOperation action = new TestMergeUpdateOperation(getElements(infos), allowOverwrite);
+ action.run(DEFAULT_MONITOR);
}
/**
diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/CVSSyncSubscriberTest.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/CVSSyncSubscriberTest.java
index 66caa4549..6d24e485b 100644
--- a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/CVSSyncSubscriberTest.java
+++ b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/CVSSyncSubscriberTest.java
@@ -15,16 +15,18 @@ import java.util.*;
import junit.framework.AssertionFailedError;
+import org.eclipse.compare.structuremergeviewer.IDiffElement;
import org.eclipse.core.resources.*;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.core.subscribers.*;
import org.eclipse.team.core.synchronize.SyncInfo;
-import org.eclipse.team.core.synchronize.SyncInfoSet;
import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin;
import org.eclipse.team.internal.ccvs.core.CVSSyncTreeSubscriber;
+import org.eclipse.team.internal.ccvs.ui.subscriber.SubscriberConfirmMergedOperation;
import org.eclipse.team.tests.ccvs.core.EclipseTest;
import org.eclipse.team.tests.ccvs.ui.SynchronizeViewTestAdapter;
+import org.eclipse.team.ui.synchronize.viewers.SyncInfoModelElement;
/**
* Provides test methods common to CVS sync subscribers
@@ -225,7 +227,14 @@ public abstract class CVSSyncSubscriberTest extends EclipseTest {
protected void markAsMerged(CVSSyncTreeSubscriber subscriber, IProject project, String[] resourcePaths) throws CoreException, TeamException, InvocationTargetException, InterruptedException {
IResource[] resources = getResources(project, resourcePaths);
SyncInfo[] infos = createSyncInfos(subscriber, resources);
- TestMarkAsMergedAction action = new TestMarkAsMergedAction();
- action.getRunnable(new SyncInfoSet(infos)).run(DEFAULT_MONITOR);
+ new SubscriberConfirmMergedOperation(null, getElements(infos)).run(DEFAULT_MONITOR);
+ }
+
+ protected IDiffElement[] getElements(SyncInfo[] infos) {
+ SyncInfoModelElement[] elements = new SyncInfoModelElement[infos.length];
+ for (int i = 0; i < elements.length; i++) {
+ elements[i] = new SyncInfoModelElement(null, infos[i]);
+ }
+ return elements;
}
}
diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/CVSWorkspaceSubscriberTest.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/CVSWorkspaceSubscriberTest.java
index 221a261c8..ebf74c5f7 100644
--- a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/CVSWorkspaceSubscriberTest.java
+++ b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/CVSWorkspaceSubscriberTest.java
@@ -18,19 +18,20 @@ import java.util.*;
import junit.framework.Test;
import junit.framework.TestSuite;
+import org.eclipse.compare.structuremergeviewer.IDiffElement;
import org.eclipse.core.resources.*;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Path;
import org.eclipse.team.core.RepositoryProvider;
import org.eclipse.team.core.TeamException;
-import org.eclipse.team.core.subscribers.*;
-import org.eclipse.team.core.synchronize.*;
+import org.eclipse.team.core.subscribers.ISubscriberChangeEvent;
+import org.eclipse.team.core.synchronize.SyncInfo;
import org.eclipse.team.internal.ccvs.core.*;
import org.eclipse.team.internal.ccvs.core.client.Command;
import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo;
import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo;
-import org.eclipse.team.internal.ccvs.ui.subscriber.CVSSubscriberAction;
+import org.eclipse.team.internal.ccvs.ui.subscriber.CVSSubscriberOperation;
import org.eclipse.team.tests.ccvs.core.CVSTestSetup;
/**
@@ -247,39 +248,46 @@ public class CVSWorkspaceSubscriberTest extends CVSSyncSubscriberTest {
}
public IResource[] update(IContainer container, String[] hierarchy) throws CoreException, TeamException, InvocationTargetException, InterruptedException {
- return runSubscriberAction(new TestUpdateAction(), container, hierarchy);
+ IResource[] resources = getResources(container, hierarchy);
+ runSubscriberOperation(new TestUpdateOperation(getElements(resources)));
+ return resources;
}
-
+
public IResource[] commit(IContainer container, String[] hierarchy) throws CoreException, TeamException {
- return runSubscriberAction(new TestCommitAction(), container, hierarchy);
+ IResource[] resources = getResources(container, hierarchy);
+ runSubscriberOperation(new TestCommitOperation(getElements(resources), false /* override */));
+ return resources;
}
public IResource[] overrideAndUpdate(IContainer container, String[] hierarchy, boolean shouldPrompt) throws CoreException, TeamException {
- TestOverrideAndUpdate action = new TestOverrideAndUpdate();
- IResource[] resources = runSubscriberAction(action, container, hierarchy);
+ IResource[] resources = getResources(container, hierarchy);
+ TestOverrideAndUpdateOperation action = new TestOverrideAndUpdateOperation(getElements(resources));
+ runSubscriberOperation(action);
assertTrue(shouldPrompt == action.isPrompted());
return resources;
}
public IResource[] overrideAndCommit(IContainer container, String[] hierarchy, boolean shouldPrompt) throws CoreException, TeamException {
- TestOverrideAndCommit action = new TestOverrideAndCommit();
- IResource[] resources = runSubscriberAction(action, container, hierarchy);
- assertTrue(shouldPrompt == action.isPrompted());
+ IResource[] resources = getResources(container, hierarchy);
+ TestCommitOperation action = new TestCommitOperation(getElements(resources), true /* override */);
+ runSubscriberOperation(action);
+ //assertTrue(shouldPrompt == action.isPrompted());
return resources;
}
- private IResource[] runSubscriberAction(CVSSubscriberAction action, IContainer container, String[] hierarchy) throws CoreException {
- IResource[] resources = getResources(container, hierarchy);
+ protected IDiffElement[] getElements(IResource[] resources) throws CoreException {
SyncInfo[] syncResources = createSyncInfos(resources);
+ return getElements(syncResources);
+ }
+
+ private void runSubscriberOperation(CVSSubscriberOperation op) throws CoreException {
try {
- action.getRunnable(new SyncInfoSet(syncResources)).run(DEFAULT_MONITOR);
- return resources;
+ op.run(DEFAULT_MONITOR);
} catch (InvocationTargetException e) {
throw CVSException.wrapException(e);
} catch (InterruptedException e) {
fail("Operation was interupted");
}
- return new IResource[0];
}
/******************************************************************
diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/TestCommitAction.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/TestCommitAction.java
deleted file mode 100644
index 48ff6566e..000000000
--- a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/TestCommitAction.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.team.tests.ccvs.core.subscriber;
-
-import org.eclipse.core.resources.IResource;
-import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.team.core.synchronize.SyncInfoSet;
-import org.eclipse.team.internal.ccvs.ui.repo.RepositoryManager;
-import org.eclipse.team.internal.ccvs.ui.subscriber.SubscriberCommitAction;
-
-class TestCommitAction extends SubscriberCommitAction {
-
- public IRunnableWithProgress getRunnable(SyncInfoSet syncSet) {
- return super.getRunnable(syncSet);
- }
-
- protected boolean canRunAsJob() {
- return false;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.team.internal.ccvs.ui.subscriber.SubscriberCommitAction#promptForComment(org.eclipse.team.internal.ccvs.ui.repo.RepositoryManager, org.eclipse.core.resources.IResource[])
- */
- protected String promptForComment(RepositoryManager manager, IResource[] resourcesToCommit) {
- return "dummy comment";
- }
-}
diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/TestOverrideAndCommit.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/TestCommitOperation.java
index 21a7817f6..40dc2a764 100644
--- a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/TestOverrideAndCommit.java
+++ b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/TestCommitOperation.java
@@ -10,38 +10,57 @@
*******************************************************************************/
package org.eclipse.team.tests.ccvs.core.subscriber;
+import org.eclipse.compare.structuremergeviewer.IDiffElement;
import org.eclipse.core.resources.IResource;
import org.eclipse.team.core.synchronize.SyncInfoSet;
import org.eclipse.team.internal.ccvs.ui.repo.RepositoryManager;
-import org.eclipse.team.internal.ccvs.ui.subscriber.OverrideAndCommitAction;
+import org.eclipse.team.internal.ccvs.ui.subscriber.SubscriberCommitOperation;
-public class TestOverrideAndCommit extends OverrideAndCommitAction {
+class TestCommitOperation extends SubscriberCommitOperation {
- private boolean prompted = false;
+ private boolean prompted;
+
+ public TestCommitOperation(IDiffElement[] elements, boolean override) {
+ super(null, elements, override);
+ }
/* (non-Javadoc)
- * @see org.eclipse.team.internal.ccvs.ui.subscriber.SubscriberCommitAction#promptForComment(org.eclipse.team.internal.ccvs.ui.repo.RepositoryManager, org.eclipse.core.resources.IResource[])
+ * @see org.eclipse.team.internal.ui.actions.TeamOperation#canRunAsJob()
*/
- protected String promptForComment(RepositoryManager manager, IResource[] resourcesToCommit) {
- return "test comments";
+ protected boolean canRunAsJob() {
+ return false;
}
/* (non-Javadoc)
- * @see org.eclipse.team.internal.ccvs.ui.subscriber.SubscriberCommitAction#promptForConflicts(org.eclipse.team.ui.sync.SyncInfoSet)
+ * @see org.eclipse.team.internal.ccvs.ui.subscriber.SubscriberCommitOperation#promptForComment(org.eclipse.team.internal.ccvs.ui.repo.RepositoryManager, org.eclipse.core.resources.IResource[])
+ */
+ protected String promptForComment(RepositoryManager manager, IResource[] resourcesToCommit) {
+ return "dummy comment";
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ccvs.ui.subscriber.SubscriberCommitOperation#promptForConflicts(org.eclipse.team.core.synchronize.SyncInfoSet)
*/
protected int promptForConflicts(SyncInfoSet syncSet) {
this.prompted = true;
return 0; // ok to commit all conflicts
}
- public boolean isPrompted() {
- return this.prompted;
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ccvs.ui.subscriber.SubscriberCommitOperation#promptForResourcesToBeAdded(org.eclipse.team.internal.ccvs.ui.repo.RepositoryManager, org.eclipse.core.resources.IResource[])
+ */
+ protected IResource[] promptForResourcesToBeAdded(RepositoryManager manager, IResource[] unadded) {
+ return unadded;
}
-
+
/* (non-Javadoc)
- * @see org.eclipse.team.internal.ccvs.ui.subscriber.CVSSubscriberAction#canRunAsJob()
+ * @see org.eclipse.team.internal.ccvs.ui.subscriber.SubscriberCommitOperation#promptForConflictHandling(org.eclipse.team.core.synchronize.SyncInfoSet)
*/
- protected boolean canRunAsJob() {
- return false;
+ protected boolean promptForConflictHandling(SyncInfoSet syncSet) {
+ return true;
+ }
+
+ public boolean isPrompted() {
+ return this.prompted;
}
}
diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/TestMarkAsMergedAction.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/TestMarkAsMergedAction.java
deleted file mode 100644
index 35d6e4212..000000000
--- a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/TestMarkAsMergedAction.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.team.tests.ccvs.core.subscriber;
-
-import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.team.core.synchronize.SyncInfoSet;
-import org.eclipse.team.internal.ccvs.ui.subscriber.SubscriberConfirmMergedAction;
-
-
-class TestMarkAsMergedAction extends SubscriberConfirmMergedAction {
- public IRunnableWithProgress getRunnable(SyncInfoSet syncSet) {
- return super.getRunnable(syncSet);
- }
- protected boolean canRunAsJob() {
- return false;
- }
-} \ No newline at end of file
diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/TestMergeUpdateAction.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/TestMergeUpdateOperation.java
index b6c5735ff..c82f0bb18 100644
--- a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/TestMergeUpdateAction.java
+++ b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/TestMergeUpdateOperation.java
@@ -10,32 +10,36 @@
*******************************************************************************/
package org.eclipse.team.tests.ccvs.core.subscriber;
+import junit.framework.Assert;
+
+import org.eclipse.compare.structuremergeviewer.IDiffElement;
import org.eclipse.core.resources.IResource;
-import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.team.core.synchronize.SyncInfoSet;
-import org.eclipse.team.internal.ccvs.ui.subscriber.MergeUpdateAction;
-import org.eclipse.team.tests.ccvs.core.EclipseTest;
+import org.eclipse.team.internal.ccvs.ui.subscriber.MergeUpdateOperation;
-class TestMergeUpdateAction extends MergeUpdateAction {
+class TestMergeUpdateOperation extends MergeUpdateOperation {
boolean allowOverwrite = false;
- public TestMergeUpdateAction(boolean allowOverwrite) {
+ public TestMergeUpdateOperation(IDiffElement[] elements, boolean allowOverwrite) {
+ super(null, elements, false /* prompt before update */);
this.allowOverwrite = allowOverwrite;
}
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ccvs.ui.subscriber.CVSSubscriberOperation#promptForOverwrite(org.eclipse.team.core.synchronize.SyncInfoSet)
+ */
protected boolean promptForOverwrite(SyncInfoSet syncSet) {
if (allowOverwrite) return true;
if (syncSet.isEmpty()) return true;
IResource[] resources = syncSet.getResources();
- EclipseTest.fail(resources[0].getFullPath().toString() + " failed to merge properly");
+ Assert.fail(resources[0].getFullPath().toString() + " failed to merge properly");
return false;
}
- public IRunnableWithProgress getRunnable(SyncInfoSet syncSet) {
- return super.getRunnable(syncSet);
- }
-
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ui.actions.TeamOperation#canRunAsJob()
+ */
protected boolean canRunAsJob() {
return false;
}
diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/TestOverrideAndUpdate.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/TestOverrideAndUpdateOperation.java
index 155c1166e..fbce4c751 100644
--- a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/TestOverrideAndUpdate.java
+++ b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/TestOverrideAndUpdateOperation.java
@@ -1,35 +1,33 @@
package org.eclipse.team.tests.ccvs.core.subscriber;
+import org.eclipse.compare.structuremergeviewer.IDiffElement;
import org.eclipse.team.core.synchronize.SyncInfoSet;
-import org.eclipse.team.internal.ccvs.ui.subscriber.OverrideAndUpdateAction;
+import org.eclipse.team.internal.ccvs.ui.subscriber.OverrideAndUpdateSubscriberOperation;
+
+public class TestOverrideAndUpdateOperation extends OverrideAndUpdateSubscriberOperation {
-public class TestOverrideAndUpdate extends OverrideAndUpdateAction {
-
private boolean prompted = false;
+ protected TestOverrideAndUpdateOperation(IDiffElement[] elements) {
+ super(null, elements);
+ }
+
/* (non-Javadoc)
- * @see org.eclipse.team.internal.ccvs.ui.subscriber.SafeUpdateAction#promptForOverwrite(org.eclipse.team.ui.sync.SyncInfoSet)
+ * @see org.eclipse.team.internal.ui.actions.TeamOperation#canRunAsJob()
*/
- protected boolean promptForOverwrite(SyncInfoSet syncSet) {
- this.prompted = true;
- return true;
+ protected boolean canRunAsJob() {
+ return false;
}
-
+
/* (non-Javadoc)
- * @see org.eclipse.team.internal.ccvs.ui.subscriber.SafeUpdateAction#warnAboutFailedResources(org.eclipse.team.ui.sync.SyncInfoSet)
+ * @see org.eclipse.team.internal.ccvs.ui.subscriber.CVSSubscriberOperation#promptForOverwrite(org.eclipse.team.core.synchronize.SyncInfoSet)
*/
- protected void warnAboutFailedResources(SyncInfoSet syncSet) {
- return;
+ protected boolean promptForOverwrite(SyncInfoSet syncSet) {
+ TestOverrideAndUpdateOperation.this.prompted = true;
+ return true;
}
-
+
public boolean isPrompted() {
return this.prompted;
}
-
- /* (non-Javadoc)
- * @see org.eclipse.team.internal.ccvs.ui.subscriber.CVSSubscriberAction#canRunAsJob()
- */
- protected boolean canRunAsJob() {
- return false;
- }
}
diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/TestUpdateAction.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/TestUpdateOperation.java
index 1bc36c774..3f072bbf6 100644
--- a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/TestUpdateAction.java
+++ b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/TestUpdateOperation.java
@@ -10,30 +10,36 @@
*******************************************************************************/
package org.eclipse.team.tests.ccvs.core.subscriber;
-import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.compare.structuremergeviewer.IDiffElement;
import org.eclipse.team.core.synchronize.SyncInfoSet;
-import org.eclipse.team.internal.ccvs.ui.subscriber.WorkspaceUpdateAction;
+import org.eclipse.team.internal.ccvs.ui.subscriber.WorkspaceUpdateOperation;
import org.eclipse.team.tests.ccvs.core.EclipseTest;
-class TestUpdateAction extends WorkspaceUpdateAction {
+class TestUpdateOperation extends WorkspaceUpdateOperation {
+ protected TestUpdateOperation(IDiffElement[] elements) {
+ super(null, elements, false);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ui.actions.TeamOperation#canRunAsJob()
+ */
+ protected boolean canRunAsJob() {
+ return false;
+ }
+
/* (non-Javadoc)
- * @see org.eclipse.team.internal.ccvs.ui.subscriber.SafeUpdateAction#warnAboutFailedResources(org.eclipse.team.ui.sync.SyncInfoSet)
+ * @see org.eclipse.team.internal.ccvs.ui.subscriber.SafeUpdateOperation#warnAboutFailedResources(org.eclipse.team.core.synchronize.SyncInfoSet)
*/
protected void warnAboutFailedResources(SyncInfoSet syncSet) {
return;
}
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ccvs.ui.subscriber.CVSSubscriberOperation#promptForOverwrite(org.eclipse.team.core.synchronize.SyncInfoSet)
+ */
protected boolean promptForOverwrite(SyncInfoSet syncSet) {
EclipseTest.fail("Should never prompt on update, simply update nodes that are valid.");
return false;
}
-
- public IRunnableWithProgress getRunnable(SyncInfoSet syncSet) {
- return super.getRunnable(syncSet);
- }
-
- protected boolean canRunAsJob() {
- return false;
- }
}
diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/HeadlessCVSRunnableContext.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/HeadlessCVSRunnableContext.java
index da2804248..04bdb9973 100644
--- a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/HeadlessCVSRunnableContext.java
+++ b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/HeadlessCVSRunnableContext.java
@@ -14,7 +14,6 @@ import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.jobs.IJobChangeListener;
-import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.team.internal.ui.actions.ITeamRunnableContext;
@@ -22,7 +21,6 @@ import org.eclipse.team.internal.ui.actions.JobRunnableContext;
public class HeadlessCVSRunnableContext implements ITeamRunnableContext {
- private boolean background;
private IJobChangeListener listener;
public HeadlessCVSRunnableContext() {
@@ -36,14 +34,10 @@ public class HeadlessCVSRunnableContext implements ITeamRunnableContext {
/* (non-Javadoc)
* @see org.eclipse.team.internal.ccvs.ui.operations.ITeamRunnableContext#run(java.lang.String, org.eclipse.core.runtime.jobs.ISchedulingRule, org.eclipse.jface.operation.IRunnableWithProgress)
*/
- public void run(
- String title,
- ISchedulingRule schedulingRule,
- boolean postponeBuild, IRunnableWithProgress runnable)
- throws InvocationTargetException, InterruptedException {
+ public void run(IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException {
if (listener != null) {
- new JobRunnableContext(listener, null).run("Headless Job", null, true, runnable);
+ new JobRunnableContext("Headless Job", listener, null).run(runnable);
} else {
runnable.run(new NullProgressMonitor());
}

Back to the top