diff options
author | Michael Valenta | 2006-03-06 22:37:21 +0000 |
---|---|---|
committer | Michael Valenta | 2006-03-06 22:37:21 +0000 |
commit | c2ab9d214dad53da784adf8611b4baabb03d7442 (patch) | |
tree | 1f72afb804e7b31d17c0c741660f6d5927e65dd4 | |
parent | a6675ff7a4ed051f98e49307046722f940c9dbc6 (diff) | |
download | eclipse.platform.team-c2ab9d214dad53da784adf8611b4baabb03d7442.tar.gz eclipse.platform.team-c2ab9d214dad53da784adf8611b4baabb03d7442.tar.xz eclipse.platform.team-c2ab9d214dad53da784adf8611b4baabb03d7442.zip |
Bug 122849 [Model Sync] Support for change sets
18 files changed, 730 insertions, 427 deletions
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/diff/IDiffChangeEvent.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/diff/IDiffChangeEvent.java index 08e27dad9..61a744232 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/diff/IDiffChangeEvent.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/diff/IDiffChangeEvent.java @@ -48,8 +48,8 @@ public interface IDiffChangeEvent { public IDiff[] getChanges(); /** - * Return any errors that occured while this change was taking place. - * @return any errors that occured while this change was taking place + * Return any errors that occurred while this change was taking place. + * @return any errors that occurred while this change was taking place */ public IStatus[] getErrors(); } diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/ActiveChangeSet.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/ActiveChangeSet.java index f46513dcd..183c79978 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/ActiveChangeSet.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/ActiveChangeSet.java @@ -13,12 +13,11 @@ package org.eclipse.team.internal.core.subscribers; import java.util.*; import org.eclipse.core.resources.*; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.*; import org.eclipse.team.core.TeamException; +import org.eclipse.team.core.diff.IDiff; +import org.eclipse.team.core.mapping.provider.ResourceDiffTree; import org.eclipse.team.core.subscribers.Subscriber; -import org.eclipse.team.core.synchronize.SyncInfo; -import org.eclipse.team.core.synchronize.SyncInfoTree; import org.eclipse.team.internal.core.TeamPlugin; import org.osgi.service.prefs.Preferences; @@ -27,7 +26,7 @@ import org.osgi.service.prefs.Preferences; * that are grouped together as a single logical change. * @since 3.1 */ -public class ActiveChangeSet extends ChangeSet { +public class ActiveChangeSet extends DiffChangeSet { private static final String CTX_TITLE = "title"; //$NON-NLS-1$ private static final String CTX_COMMENT = "comment"; //$NON-NLS-1$ @@ -97,15 +96,15 @@ public class ActiveChangeSet extends ChangeSet { /* * Override inherited method to only include outgoing changes */ - protected boolean isValidChange(SyncInfo info) { - return getManager().isModified(info); + protected boolean isValidChange(IDiff diff) { + return getManager().isModified(diff); } - private void addResource(IResource resource) throws TeamException { + private void addResource(IResource resource) throws CoreException { Subscriber subscriber = getManager().getSubscriber(); - SyncInfo info = subscriber.getSyncInfo(resource); - if (info != null) { - add(info); + IDiff diff = subscriber.getDiff(resource); + if (diff != null) { + add(diff); } } @@ -143,9 +142,9 @@ public class ActiveChangeSet extends ChangeSet { comment = prefs.get(CTX_COMMENT, null); String resourcePaths = prefs.get(CTX_RESOURCES, null); if (resourcePaths != null) { - SyncInfoTree syncInfoSet = getSyncInfoSet(); + ResourceDiffTree tree = internalGetDiffTree(); try { - syncInfoSet.beginInput(); + tree.beginInput(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); StringTokenizer tokenizer = new StringTokenizer(resourcePaths, "\n"); //$NON-NLS-1$ while (tokenizer.hasMoreTokens()) { @@ -157,7 +156,7 @@ public class ActiveChangeSet extends ChangeSet { if (resource != null && manager.getSubscriber().getSyncInfo(resource) != null) { try { addResource(resource); - } catch (TeamException e) { + } catch (CoreException e) { TeamPlugin.log(e); } } @@ -168,7 +167,7 @@ public class ActiveChangeSet extends ChangeSet { } } } finally { - syncInfoSet.endInput(null); + tree.endInput(null); } } } @@ -196,20 +195,20 @@ public class ActiveChangeSet extends ChangeSet { /** * Add the resources to the change set if they are outgoing changes. - * @param resources the resouces to add. - * @throws TeamException + * @param resources the resources to add. + * @throws CoreException */ - public void add(IResource[] resources) throws TeamException { + public void add(IResource[] resources) throws CoreException { List toAdd = new ArrayList(); for (int i = 0; i < resources.length; i++) { IResource resource = resources[i]; - SyncInfo info = manager.getSyncInfo(resource); - if (info != null) { - toAdd.add(info); + IDiff diff = getManager().getDiff(resource); + if (diff != null) { + toAdd.add(diff); } } if (!toAdd.isEmpty()) { - add((SyncInfo[]) toAdd.toArray(new SyncInfo[toAdd.size()])); + add((IDiff[]) toAdd.toArray(new IDiff[toAdd.size()])); } } } diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/ChangeSet.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/ChangeSet.java index e78ba350a..3c479f897 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/ChangeSet.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/ChangeSet.java @@ -1,31 +1,23 @@ /******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. + * Copyright (c) 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: - * IBM Corporation - initial API and implementation + * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.team.internal.core.subscribers; import org.eclipse.core.resources.IResource; -import org.eclipse.team.core.synchronize.SyncInfo; -import org.eclipse.team.core.synchronize.SyncInfoTree; /** - * A change set represents a set of changes that are logically - * grouped together as a single change. The changes are - * represented using a set of <code>SyncInfo</code>. - * - * @since 3.1 + * A set that contains a group of related changes */ public abstract class ChangeSet { - + private String name; - - private final SyncInfoTree set = new SyncInfoTree(); /** * Create a change set with no name. Subclasses @@ -43,88 +35,31 @@ public abstract class ChangeSet { public ChangeSet(String name) { this.name = name; } - - /** - * Return the SyncInfoSet that contains the resources that belong to this change set. - * @return the SyncInfoSet that contains the resources that belong to this change set - */ - public SyncInfoTree getSyncInfoSet() { - return set; - } /** * Return the resources that are contained in this set. * @return the resources that are contained in this set */ - public IResource[] getResources() { - return set.getResources(); - } + public abstract IResource[] getResources(); /** * Return whether the set contains any files. * @return whether the set contains any files */ - public boolean isEmpty() { - return set.isEmpty(); - } + public abstract boolean isEmpty(); /** * Return true if the given file is included in this set. * @param local a local file * @return true if the given file is included in this set */ - public boolean contains(IResource local) { - return set.getSyncInfo(local) != null; - } - - /** - * Add the resource to this set if it is modified - * w.r.t. the subscriber. - * @param info - */ - public void add(SyncInfo info) { - if (isValidChange(info)) { - set.add(info); - } - } - - /** - * Return whether the given sync info is a valid change - * and can be included in this set. This method is used - * by the <code>add</code> method to filter set additions. - * @param info a sync info - * @return whether the sync info is a valid member of this set - */ - protected boolean isValidChange(SyncInfo info) { - return (info != null); - } - - /** - * Add the resources to this set if they are modified - * w.r.t. the subscriber. - * @param infos the resources to be added. - */ - public void add(SyncInfo[] infos) { - try { - set.beginInput(); - for (int i = 0; i < infos.length; i++) { - SyncInfo info = infos[i]; - add(info); - } - } finally { - set.endInput(null); - } - } + public abstract boolean contains(IResource local); /** * Remove the resource from the set. * @param resource the resource to be removed */ - public void remove(IResource resource) { - if (contains(resource)) { - set.remove(resource); - } - } + public abstract void remove(IResource resource); /** * Remove the resources from the set. @@ -143,16 +78,7 @@ public abstract class ChangeSet { * @param depth the depth of the removal (one of * <code>IResource.DEPTH_ZERO, IResource.DEPTH_ONE, IResource.DEPTH_INFINITE)</code> */ - public void rootRemoved(IResource resource, int depth) { - SyncInfo[] infos = set.getSyncInfos(resource, depth); - if (infos.length > 0) { - IResource[] resources = new IResource[infos.length]; - for (int i = 0; i < resources.length; i++) { - resources[i] = infos[i].getLocal(); - } - set.removeAll(resources); - } - } + public abstract void rootRemoved(IResource resource, int depth); /** * Return a comment describing the change. diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/ChangeSetCollector.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/ChangeSetCollector.java index 307e9810d..d8e284c9d 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/ChangeSetCollector.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/ChangeSetCollector.java @@ -1,27 +1,22 @@ /******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. + * Copyright (c) 2000, 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html - * + * * Contributors: - * IBM Corporation - initial API and implementation + * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.team.internal.core.subscribers; -import java.util.*; +import java.util.HashSet; +import java.util.Set; -import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.*; -import org.eclipse.team.core.synchronize.ISyncInfoSetChangeListener; -import org.eclipse.team.core.synchronize.SyncInfoSet; /** - * This class defines the common aspects of collecting a set of change - * sets, including event notification. - * - * @since 3.1 + * An abstract change set collector that is not tied to a particular type of change set. */ public abstract class ChangeSetCollector { @@ -82,54 +77,58 @@ public abstract class ChangeSetCollector { public void add(final ChangeSet set) { if (!contains(set)) { sets.add(set); - set.getSyncInfoSet().addSyncSetChangedListener(getChangeSetChangeListener()); - Object[] listeners = getListeners(); - for (int i = 0; i < listeners.length; i++) { - final IChangeSetChangeListener listener = (IChangeSetChangeListener)listeners[i]; - SafeRunner.run(new ISafeRunnable() { - public void handleException(Throwable exception) { - // Exceptions are logged by the platform - } - public void run() throws Exception { - listener.setAdded(set); - } - }); - } + handleSetAdded(set); } } /** + * Handle the set addition by notifying listeners. + * @param set the added set + */ + protected void handleSetAdded(final ChangeSet set) { + Object[] listeners = getListeners(); + for (int i = 0; i < listeners.length; i++) { + final IChangeSetChangeListener listener = (IChangeSetChangeListener)listeners[i]; + SafeRunner.run(new ISafeRunnable() { + public void handleException(Throwable exception) { + // Exceptions are logged by the platform + } + public void run() throws Exception { + listener.setAdded(set); + } + }); + } + } + + /** * Remove the set from the list of active sets. * @param set the set to be removed */ public void remove(final ChangeSet set) { if (contains(set)) { - set.getSyncInfoSet().removeSyncSetChangedListener(getChangeSetChangeListener()); sets.remove(set); - Object[] listeners = getListeners(); - for (int i = 0; i < listeners.length; i++) { - final IChangeSetChangeListener listener = (IChangeSetChangeListener)listeners[i]; - SafeRunner.run(new ISafeRunnable() { - public void handleException(Throwable exception) { - // Exceptions are logged by the platform - } - public void run() throws Exception { - listener.setRemoved(set); - } - }); - } + handleSetRemoved(set); } } - + /** - * Return the change listener that will be registered with each - * <code>SyncInfoSet</code> associated with the <code>ChangeSets</code> - * added to this collector. - * @return the change listener that will be registered with each - * <code>SyncInfoSet</code> associated with the <code>ChangeSets</code> - * added to this collector + * Handle the set removal by notifying listeners. + * @param set the removed set */ - protected abstract ISyncInfoSetChangeListener getChangeSetChangeListener(); + protected void handleSetRemoved(final ChangeSet set) { + Object[] listeners = getListeners(); + for (int i = 0; i < listeners.length; i++) { + final IChangeSetChangeListener listener = (IChangeSetChangeListener)listeners[i]; + SafeRunner.run(new ISafeRunnable() { + public void handleException(Throwable exception) { + // Exceptions are logged by the platform + } + public void run() throws Exception { + listener.setRemoved(set); + } + }); + } + } /** * Return whether the manager contains the given commit set @@ -172,10 +171,11 @@ public abstract class ChangeSetCollector { } /** + * Fire resource change notifications to the listeners. * @param changeSet * @param allAffectedResources */ - protected void fireResourcesChangedEvent(final ChangeSet changeSet, final IResource[] allAffectedResources) { + protected void fireResourcesChangedEvent(final ChangeSet changeSet, final IPath[] allAffectedResources) { Object[] listeners = getListeners(); for (int i = 0; i < listeners.length; i++) { final IChangeSetChangeListener listener = (IChangeSetChangeListener)listeners[i]; @@ -189,20 +189,4 @@ public abstract class ChangeSetCollector { }); } } - - /** - * Return the Change Set whose sync info set is the - * one given. - * @param set a sync info set - * @return the change set for the given sync info set - */ - protected ChangeSet getChangeSet(SyncInfoSet set) { - for (Iterator iter = sets.iterator(); iter.hasNext();) { - ChangeSet changeSet = (ChangeSet) iter.next(); - if (changeSet.getSyncInfoSet() == set) { - return changeSet; - } - } - return null; - } } diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/CheckedInChangeSet.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/CheckedInChangeSet.java index 8bd1983c0..59006959c 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/CheckedInChangeSet.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/CheckedInChangeSet.java @@ -12,6 +12,10 @@ package org.eclipse.team.internal.core.subscribers; import java.util.Date; +import org.eclipse.core.resources.IResource; +import org.eclipse.team.core.synchronize.SyncInfo; +import org.eclipse.team.core.synchronize.SyncInfoTree; + /** * A checked-in change set represents a group of resource * changes that were previously checked into a repository @@ -19,14 +23,126 @@ import java.util.Date; * <p> * A previously checked-in set of changes may not apply directly * to the local versions of the resources involved. However, - * a <code>SyncInfo</code> is still used to reprsent each change. + * a <code>SyncInfo</code> is still used to represent each change. * The base and remote slots of the <code>SyncInfo</code> identify * the state before and after the resources were checked-in. * @since 3.1 */ public abstract class CheckedInChangeSet extends ChangeSet { + private final SyncInfoTree set = new SyncInfoTree(); + public abstract String getAuthor(); public abstract Date getDate(); + + /** + * Return the SyncInfoSet that contains the resources that belong to this change set. + * @return the SyncInfoSet that contains the resources that belong to this change set + */ + public SyncInfoTree getSyncInfoSet() { + return set; + } + + /** + * Return the resources that are contained in this set. + * @return the resources that are contained in this set + */ + public IResource[] getResources() { + return set.getResources(); + } + + /** + * Return whether the set contains any files. + * @return whether the set contains any files + */ + public boolean isEmpty() { + return set.isEmpty(); + } + + /** + * Return true if the given file is included in this set. + * @param local a local file + * @return true if the given file is included in this set + */ + public boolean contains(IResource local) { + return set.getSyncInfo(local) != null; + } + + /** + * Add the resource to this set if it is modified + * w.r.t. the subscriber. + * @param info + */ + public void add(SyncInfo info) { + if (isValidChange(info)) { + set.add(info); + } + } + + /** + * Return whether the given sync info is a valid change + * and can be included in this set. This method is used + * by the <code>add</code> method to filter set additions. + * @param info a sync info + * @return whether the sync info is a valid member of this set + */ + protected boolean isValidChange(SyncInfo info) { + return (info != null); + } + + /** + * Add the resources to this set if they are modified + * w.r.t. the subscriber. + * @param infos the resources to be added. + */ + public void add(SyncInfo[] infos) { + try { + set.beginInput(); + for (int i = 0; i < infos.length; i++) { + SyncInfo info = infos[i]; + add(info); + } + } finally { + set.endInput(null); + } + } + + /** + * Remove the resource from the set. + * @param resource the resource to be removed + */ + public void remove(IResource resource) { + if (contains(resource)) { + set.remove(resource); + } + } + + /** + * Remove the resources from the set. + * @param resources the resources to be removed + */ + public void remove(IResource[] resources) { + for (int i = 0; i < resources.length; i++) { + IResource resource = resources[i]; + remove(resource); + } + } + + /** + * Remove the resource and it's descendants to the given depth. + * @param resource the resource to be removed + * @param depth the depth of the removal (one of + * <code>IResource.DEPTH_ZERO, IResource.DEPTH_ONE, IResource.DEPTH_INFINITE)</code> + */ + public void rootRemoved(IResource resource, int depth) { + SyncInfo[] infos = set.getSyncInfos(resource, depth); + if (infos.length > 0) { + IResource[] resources = new IResource[infos.length]; + for (int i = 0; i < resources.length; i++) { + resources[i] = infos[i].getLocal(); + } + set.removeAll(resources); + } + } } diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/DiffChangeSet.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/DiffChangeSet.java new file mode 100644 index 000000000..1264b5f56 --- /dev/null +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/DiffChangeSet.java @@ -0,0 +1,144 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.core.subscribers; + +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IPath; +import org.eclipse.team.core.diff.IDiff; +import org.eclipse.team.core.mapping.IResourceDiffTree; +import org.eclipse.team.core.mapping.provider.ResourceDiffTree; + +public abstract class DiffChangeSet extends ChangeSet { + + private final ResourceDiffTree tree = new ResourceDiffTree(); + + public DiffChangeSet() { + super(); + } + + public DiffChangeSet(String name) { + super(name); + } + + /** + * Return the diff tree that contains the resources that belong to this change set. + * @return the diff tree that contains the resources that belong to this change set + */ + public IResourceDiffTree getDiffTree() { + return tree; + } + + protected ResourceDiffTree internalGetDiffTree() { + return tree; + } + + /** + * Return the resources that are contained in this set. + * @return the resources that are contained in this set + */ + public IResource[] getResources() { + return tree.getAffectedResources(); + } + + /** + * Return whether the set contains any files. + * @return whether the set contains any files + */ + public boolean isEmpty() { + return tree.isEmpty(); + } + + /** + * Return true if the given file is included in this set. + * @param local a local file + * @return true if the given file is included in this set + */ + public boolean contains(IResource local) { + return tree.getDiff(local) != null; + } + + /** + * Add the resource to this set if it is modified + * w.r.t. the subscriber. + * @param diff the diff to be added + */ + public void add(IDiff diff) { + if (isValidChange(diff)) { + tree.add(diff); + } + } + + /** + * Return whether the given sync info is a valid change + * and can be included in this set. This method is used + * by the <code>add</code> method to filter set additions. + * @param diff a diff + * @return whether the sync info is a valid member of this set + */ + protected boolean isValidChange(IDiff diff) { + return (diff != null); + } + + /** + * Add the resources to this set if they are modified + * w.r.t. the subscriber. + * @param diffs the resources to be added. + */ + public void add(IDiff[] diffs) { + try { + tree.beginInput(); + for (int i = 0; i < diffs.length; i++) { + IDiff diff = diffs[i]; + add(diff); + } + } finally { + tree.endInput(null); + } + } + + /** + * Remove the resource from the set. + * @param resource the resource to be removed + */ + public void remove(IResource resource) { + if (contains(resource)) { + tree.remove(resource); + } + } + + /** + * Remove the resource and it's descendants to the given depth. + * @param resource the resource to be removed + * @param depth the depth of the removal (one of + * <code>IResource.DEPTH_ZERO, IResource.DEPTH_ONE, IResource.DEPTH_INFINITE)</code> + */ + public void rootRemoved(IResource resource, int depth) { + IDiff[] diffs = tree.getDiffs(resource, depth); + if (diffs.length > 0) { + try { + tree.beginInput(); + for (int i = 0; i < diffs.length; i++) { + IDiff diff = diffs[i]; + IResource r = tree.getResource(diff); + if (r != null) + tree.remove(r); + } + } finally { + tree.endInput(null); + } + } + } + + public boolean contains(IPath path) { + return getDiffTree().getDiff(path) != null; + } + +} diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/DiffTreeChangeSetCollector.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/DiffTreeChangeSetCollector.java new file mode 100644 index 000000000..29e00a6d5 --- /dev/null +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/DiffTreeChangeSetCollector.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.core.subscribers; + +import org.eclipse.team.core.diff.IDiffChangeListener; +import org.eclipse.team.core.mapping.IResourceDiffTree; + +/** + * A change set collector for change sets whose underlying representation is a diff tree + */ +public abstract class DiffTreeChangeSetCollector extends ChangeSetCollector { + + /** + * Return the Change Set whose sync info set is the + * one given. + * @param tree a diff tree + * @return the change set for the given diff tree + */ + protected ChangeSet getChangeSet(IResourceDiffTree tree) { + ChangeSet[] sets = getSets(); + for (int i = 0; i < sets.length; i++) { + ChangeSet changeSet = sets[i]; + if (((DiffChangeSet)changeSet).getDiffTree() == tree) { + return changeSet; + } + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.team.internal.core.subscribers.AbstractChangeSetCollector#handleSetAdded(org.eclipse.team.internal.core.subscribers.ChangeSet) + */ + protected void handleSetAdded(ChangeSet set) { + ((DiffChangeSet)set).getDiffTree().addDiffChangeListener(getDiffTreeListener()); + super.handleSetAdded(set); + } + + /* (non-Javadoc) + * @see org.eclipse.team.internal.core.subscribers.AbstractChangeSetCollector#handleSetRemoved(org.eclipse.team.internal.core.subscribers.ChangeSet) + */ + protected void handleSetRemoved(ChangeSet set) { + ((DiffChangeSet)set).getDiffTree().removeDiffChangeListener(getDiffTreeListener()); + super.handleSetRemoved(set); + } + + protected abstract IDiffChangeListener getDiffTreeListener(); + +} diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/IChangeSetChangeListener.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/IChangeSetChangeListener.java index 7ee22908b..6b7777f2e 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/IChangeSetChangeListener.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/IChangeSetChangeListener.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.team.internal.core.subscribers; -import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IPath; /** @@ -29,6 +29,7 @@ public interface IChangeSetChangeListener { * The default change set has change to be the given set. * All new modifications will be placed in the default * set. + * @param previousDefault * @param set the default set */ void defaultSetChanged(ChangeSet previousDefault, ChangeSet set); @@ -51,8 +52,8 @@ public interface IChangeSetChangeListener { * or removed from the set. Callers can use the resources contained * in the set to determine if each resource is an addition or removal. * @param set the set that has changed - * @param resources the resources whose containment state has changed w.r.t the set + * @param paths the paths of the resources whose containment state has changed w.r.t the set */ - void resourcesChanged(ChangeSet set, IResource[] resources); + void resourcesChanged(ChangeSet set, IPath[] paths); } diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/SubscriberChangeSetCollector.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/SubscriberChangeSetCollector.java index 033223146..6e3582c5f 100644 --- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/SubscriberChangeSetCollector.java +++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/SubscriberChangeSetCollector.java @@ -18,10 +18,11 @@ import org.eclipse.core.runtime.*; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.osgi.util.NLS; -import org.eclipse.team.core.ITeamStatus; import org.eclipse.team.core.TeamException; +import org.eclipse.team.core.diff.*; +import org.eclipse.team.core.mapping.IResourceDiffTree; +import org.eclipse.team.core.mapping.provider.ResourceDiffTree; import org.eclipse.team.core.subscribers.Subscriber; -import org.eclipse.team.core.synchronize.*; import org.eclipse.team.internal.core.*; import org.osgi.service.prefs.BackingStoreException; import org.osgi.service.prefs.Preferences; @@ -29,7 +30,7 @@ import org.osgi.service.prefs.Preferences; /** * This class manages the active change sets associated with a subscriber. */ -public class SubscriberChangeSetCollector extends ChangeSetCollector implements ISyncInfoSetChangeListener { +public class SubscriberChangeSetCollector extends DiffTreeChangeSetCollector implements IDiffChangeListener { private static final String PREF_CHANGE_SETS = "changeSets"; //$NON-NLS-1$ private static final String CTX_DEFAULT_SET = "defaultSet"; //$NON-NLS-1$ @@ -71,7 +72,7 @@ public class SubscriberChangeSetCollector extends ChangeSetCollector implements } if (isShutdown()) throw new OperationCanceledException(); - SyncInfoTree[] locked = null; + ResourceDiffTree[] locked = null; try { locked = beginDispath(); for (Iterator iter = dispatchEvents.iterator(); iter.hasNext();) { @@ -89,7 +90,9 @@ public class SubscriberChangeSetCollector extends ChangeSetCollector implements if (isShutdown()) throw new OperationCanceledException(); } - } finally { + } catch (CoreException e) { + throw TeamException.asTeamException(e); + } finally { try { endDispatch(locked, monitor); } finally { @@ -104,21 +107,21 @@ public class SubscriberChangeSetCollector extends ChangeSetCollector implements * locked. If this method throws an exception then the client * can assume that no sets were locked */ - private SyncInfoTree[] beginDispath() { + private ResourceDiffTree[] beginDispath() { ChangeSet[] sets = getSets(); List lockedSets = new ArrayList(); try { for (int i = 0; i < sets.length; i++) { - ChangeSet set = sets[i]; - SyncInfoTree syncInfoSet = set.getSyncInfoSet(); - lockedSets.add(syncInfoSet); - syncInfoSet.beginInput(); + ActiveChangeSet set = (ActiveChangeSet)sets[i]; + ResourceDiffTree tree = set.internalGetDiffTree(); + lockedSets.add(tree); + tree.beginInput(); } - return (SyncInfoTree[]) lockedSets.toArray(new SyncInfoTree[lockedSets.size()]); + return (ResourceDiffTree[]) lockedSets.toArray(new ResourceDiffTree[lockedSets.size()]); } catch (RuntimeException e) { try { for (Iterator iter = lockedSets.iterator(); iter.hasNext();) { - SyncInfoTree tree = (SyncInfoTree) iter.next(); + ResourceDiffTree tree = (ResourceDiffTree) iter.next(); try { tree.endInput(null); } catch (Throwable e1) { @@ -132,14 +135,14 @@ public class SubscriberChangeSetCollector extends ChangeSetCollector implements } } - private void endDispatch(SyncInfoTree[] locked, IProgressMonitor monitor) { + private void endDispatch(ResourceDiffTree[] locked, IProgressMonitor monitor) { if (locked == null) { // The begin failed so there's nothing to unlock return; } monitor.beginTask(null, 100 * locked.length); for (int i = 0; i < locked.length; i++) { - SyncInfoTree tree = locked[i]; + ResourceDiffTree tree = locked[i]; try { tree.endInput(Policy.subMonitorFor(monitor, 100)); } catch (RuntimeException e) { @@ -181,21 +184,21 @@ public class SubscriberChangeSetCollector extends ChangeSetCollector implements /* * Handle the change */ - private void handleChange(IResource resource, int depth) throws TeamException { - SyncInfo syncInfo = getSyncInfo(resource); - if (isModified(syncInfo)) { + private void handleChange(IResource resource, int depth) throws CoreException { + IDiff diff = getDiff(resource); + if (isModified(diff)) { ActiveChangeSet[] containingSets = getContainingSets(resource); if (containingSets.length == 0) { // Consider for inclusion in the default set - // if the resource is not already a memebr of another set + // if the resource is not already a member of another set if (defaultSet != null) { - defaultSet.add(syncInfo); + defaultSet.add(diff); } } else { for (int i = 0; i < containingSets.length; i++) { ActiveChangeSet set = containingSets[i]; // Update the sync info in the set - set.getSyncInfoSet().add(syncInfo); + set.add(diff); } } } else { @@ -275,32 +278,38 @@ public class SubscriberChangeSetCollector extends ChangeSetCollector implements public boolean hasMembers(IResource resource) { ChangeSet[] sets = getSets(); for (int i = 0; i < sets.length; i++) { - ChangeSet set = sets[i]; - if (set.getSyncInfoSet().hasMembers(resource)); + ActiveChangeSet set = (ActiveChangeSet)sets[i]; + if (set.getDiffTree().getChildren(resource.getFullPath()).length > 0) + return true; } if (defaultSet != null) - return (defaultSet.getSyncInfoSet().hasMembers(resource)); + return (defaultSet.getDiffTree().getChildren(resource.getFullPath()).length > 0); return false; } - /** - * Add the active change set to this collector. - * @param set the active change set being added + /* (non-Javadoc) + * @see org.eclipse.team.internal.core.subscribers.ChangeSetCollector#add(org.eclipse.team.internal.core.subscribers.ChangeSet) */ public void add(ChangeSet set) { Assert.isTrue(set instanceof ActiveChangeSet); - if (!contains(set)) { - super.add(set); - handleAddedResources(set, set.getSyncInfoSet().getSyncInfos()); - } + super.add(set); + } + + /* (non-Javadoc) + * @see org.eclipse.team.internal.core.subscribers.DiffTreeChangeSetCollector#handleSetAdded(org.eclipse.team.internal.core.subscribers.ChangeSet) + */ + protected void handleSetAdded(ChangeSet set) { + Assert.isTrue(set instanceof ActiveChangeSet); + super.handleSetAdded(set); + handleAddedResources(set, ((ActiveChangeSet)set).internalGetDiffTree().getDiffs()); } /** * Return whether the manager allows a resource to - * be in mulitple sets. By default, a resource + * be in multiple sets. By default, a resource * may only be in one set. * @return whether the manager allows a resource to - * be in mulitple sets. + * be in multiple sets. */ protected boolean isSingleSetPerResource() { return true; @@ -312,13 +321,13 @@ public class SubscriberChangeSetCollector extends ChangeSetCollector implements * so no events are fired. The set can be added using the * <code>add</code> method. * @param title the title of the commit set - * @param infos the files contained in the set + * @param diffs the files contained in the set * @return the created set */ - public ActiveChangeSet createSet(String title, SyncInfo[] infos) { + public ActiveChangeSet createSet(String title, IDiff[] diffs) { ActiveChangeSet commitSet = new ActiveChangeSet(this, title); - if (infos != null && infos.length > 0) { - commitSet.add(infos); + if (diffs != null && diffs.length > 0) { + commitSet.add(diffs); } return commitSet; } @@ -329,23 +338,23 @@ public class SubscriberChangeSetCollector extends ChangeSetCollector implements * @param title the title of the commit set * @param files the files contained in the set * @return the created set - * @throws TeamException + * @throws CoreException */ - public ActiveChangeSet createSet(String title, IFile[] files) throws TeamException { + public ActiveChangeSet createSet(String title, IFile[] files) throws CoreException { List infos = new ArrayList(); for (int i = 0; i < files.length; i++) { IFile file = files[i]; - SyncInfo info = getSyncInfo(file); - if (info != null) { - infos.add(info); + IDiff diff = getDiff(file); + if (diff != null) { + infos.add(diff); } } - return createSet(title, (SyncInfo[]) infos.toArray(new SyncInfo[infos.size()])); + return createSet(title, (IDiff[]) infos.toArray(new IDiff[infos.size()])); } /** * Make the given set the default set into which all new modifications - * that ae not already in another set go. + * that are not already in another set go. * @param set the set which is to become the default set */ public void makeDefault(ActiveChangeSet set) { @@ -359,7 +368,7 @@ public class SubscriberChangeSetCollector extends ChangeSetCollector implements } /** - * Retrn the set which is currently the default or + * Return the set which is currently the default or * <code>null</code> if there is no default set. * @return the default change set */ @@ -381,12 +390,11 @@ public class SubscriberChangeSetCollector extends ChangeSetCollector implements * from the subscriber. * @param resource the resource * @return the sync info for the resource - * @throws TeamException + * @throws CoreException */ - protected SyncInfo getSyncInfo(IResource resource) throws TeamException { + protected IDiff getDiff(IResource resource) throws CoreException { Subscriber subscriber = getSubscriber(); - SyncInfo info = subscriber.getSyncInfo(resource); - return info; + return subscriber.getDiff(resource); } /** @@ -397,14 +405,15 @@ public class SubscriberChangeSetCollector extends ChangeSetCollector implements return collector.getSubscriber(); } - protected boolean isModified(SyncInfo info) { - if (info != null) { - if (info.getComparator().isThreeWay()) { - int dir = (info.getKind() & SyncInfo.DIRECTION_MASK); - return dir == SyncInfo.OUTGOING || dir == SyncInfo.CONFLICTING; - } else { - return (info.getKind() & SyncInfo.CHANGE_MASK) == SyncInfo.CHANGE; - } + protected boolean isModified(IDiff diff) { + if (diff != null) { + if (diff instanceof IThreeWayDiff) { + IThreeWayDiff twd = (IThreeWayDiff) diff; + int dir = twd.getDirection(); + return dir == IThreeWayDiff.OUTGOING || dir == IThreeWayDiff.CONFLICTING; + } else { + return diff.getKind() != IDiff.NO_CHANGE; + } } return false; } @@ -429,7 +438,7 @@ public class SubscriberChangeSetCollector extends ChangeSetCollector implements prefs.node(string).removeNode(); } } catch (BackingStoreException e) { - TeamPlugin.log(IStatus.ERROR, NLS.bind("An error occurred purging the sommit set state for {0}", new String[] { getSubscriber().getName() }), e); //$NON-NLS-1$ + TeamPlugin.log(IStatus.ERROR, NLS.bind("An error occurred purging the commit set state for {0}", new String[] { getSubscriber().getName() }), e); //$NON-NLS-1$ } ChangeSet[] sets = getSets(); for (int i = 0; i < sets.length; i++) { @@ -503,43 +512,32 @@ public class SubscriberChangeSetCollector extends ChangeSetCollector implements return getSubscriber().getName(); } - /* (non-Javadoc) - * @see org.eclipse.team.core.synchronize.ISyncInfoSetChangeListener#syncInfoSetReset(org.eclipse.team.core.synchronize.SyncInfoSet, org.eclipse.core.runtime.IProgressMonitor) - */ - public void syncInfoSetReset(SyncInfoSet set, IProgressMonitor monitor) { - handleSyncSetChange(set, set.getSyncInfos(), set.getResources()); - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.synchronize.ISyncInfoSetChangeListener#syncInfoChanged(org.eclipse.team.core.synchronize.ISyncInfoSetChangeEvent, org.eclipse.core.runtime.IProgressMonitor) - */ - public void syncInfoChanged(ISyncInfoSetChangeEvent event, IProgressMonitor monitor) { - SyncInfoSet set = event.getSet(); - handleSyncSetChange(set, event.getAddedResources(), getAllResources(event)); - } - - private IResource[] getAllResources(ISyncInfoSetChangeEvent event) { - Set allResources = new HashSet(); - SyncInfo[] addedResources = event.getAddedResources(); - for (int i = 0; i < addedResources.length; i++) { - SyncInfo info = addedResources[i]; - allResources.add(info.getLocal()); - } - SyncInfo[] changedResources = event.getChangedResources(); - for (int i = 0; i < changedResources.length; i++) { - SyncInfo info = changedResources[i]; - allResources.add(info.getLocal()); - } - allResources.addAll(Arrays.asList(event.getRemovedResources())); - return (IResource[]) allResources.toArray(new IResource[allResources.size()]); + private IPath[] getAllResources(IDiffChangeEvent event) { + Set allResources = new HashSet(); + IDiff[] addedResources = event.getAdditions(); + for (int i = 0; i < addedResources.length; i++) { + IDiff diff = addedResources[i]; + allResources.add(diff.getPath()); + } + IDiff[] changedResources = event.getChanges(); + for (int i = 0; i < changedResources.length; i++) { + IDiff diff = changedResources[i]; + allResources.add(diff.getPath()); + } + IPath[] removals = event.getRemovals(); + for (int i = 0; i < removals.length; i++) { + IPath path = removals[i]; + allResources.add(path); + } + return (IPath[]) allResources.toArray(new IPath[allResources.size()]); } - private void handleAddedResources(ChangeSet set, SyncInfo[] infos) { + private void handleAddedResources(ChangeSet set, IDiff[] diffs) { if (isSingleSetPerResource()) { - IResource[] resources = new IResource[infos.length]; - for (int i = 0; i < infos.length; i++) { - resources[i] = infos[i].getLocal(); - } + IResource[] resources = new IResource[diffs.length]; + for (int i = 0; i < resources.length; i++) { + resources[i] = ((DiffChangeSet)set).getDiffTree().getResource(diffs[i]); + } // Remove the added files from any other set that contains them ChangeSet[] sets = getSets(); for (int i = 0; i < sets.length; i++) { @@ -551,32 +549,26 @@ public class SubscriberChangeSetCollector extends ChangeSetCollector implements } } - private void handleSyncSetChange(SyncInfoSet set, SyncInfo[] addedInfos, IResource[] allAffectedResources) { - ChangeSet changeSet = getChangeSet(set); - if (set.isEmpty() && changeSet != null) { + private void handleSyncSetChange(IResourceDiffTree tree, IDiff[] addedDiffs, IPath[] allAffectedResources) { + ChangeSet changeSet = getChangeSet(tree); + if (tree.isEmpty() && changeSet != null) { remove(changeSet); } fireResourcesChangedEvent(changeSet, allAffectedResources); - handleAddedResources(changeSet, addedInfos); - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.synchronize.ISyncInfoSetChangeListener#syncInfoSetErrors(org.eclipse.team.core.synchronize.SyncInfoSet, org.eclipse.team.core.ITeamStatus[], org.eclipse.core.runtime.IProgressMonitor) - */ - public void syncInfoSetErrors(SyncInfoSet set, ITeamStatus[] errors, IProgressMonitor monitor) { - // Nothing to do + handleAddedResources(changeSet, addedDiffs); } /* (non-Javadoc) * @see org.eclipse.team.core.subscribers.ChangeSetCollector#getChangeSetSyncSetChangeListener() */ - protected ISyncInfoSetChangeListener getChangeSetChangeListener() { + protected IDiffChangeListener getDiffTreeListener() { return this; } /** * Wait until the collector is done processing any events. * This method is for testing purposes only. + * @param monitor */ public void waitUntilDone(IProgressMonitor monitor) { monitor.worked(1); @@ -591,4 +583,13 @@ public class SubscriberChangeSetCollector extends ChangeSetCollector implements } monitor.worked(1); } + + public void diffsChanged(IDiffChangeEvent event, IProgressMonitor monitor) { + IResourceDiffTree tree = (IResourceDiffTree)event.getTree(); + handleSyncSetChange(tree, event.getAdditions(), getAllResources(event)); + } + + public void propertyChanged(IDiffTree tree, int property, IPath[] paths) { + // ignore + } } diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/CVSChangeSetCollector.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/CVSChangeSetCollector.java index 774830ab7..50d18e5e0 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/CVSChangeSetCollector.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/CVSChangeSetCollector.java @@ -20,7 +20,7 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.team.core.TeamException; import org.eclipse.team.core.TeamStatus; -import org.eclipse.team.core.subscribers.*; +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.core.variants.IResourceVariant; @@ -30,10 +30,10 @@ import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo; import org.eclipse.team.internal.ccvs.ui.*; import org.eclipse.team.internal.ccvs.ui.Policy; import org.eclipse.team.internal.ccvs.ui.operations.RemoteLogOperation.LogEntryCache; -import org.eclipse.team.internal.core.subscribers.ChangeSet; -import org.eclipse.team.internal.core.subscribers.CheckedInChangeSet; +import org.eclipse.team.internal.core.subscribers.*; import org.eclipse.team.internal.ui.synchronize.SyncInfoSetChangeSetCollector; -import org.eclipse.team.ui.synchronize.*; +import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; +import org.eclipse.team.ui.synchronize.SynchronizePageActionGroup; /** * Collector that fetches the log for incoming CVS change sets @@ -194,7 +194,7 @@ public class CVSChangeSetCollector extends SyncInfoSetChangeSetCollector impleme * @see org.eclipse.team.ui.synchronize.SyncInfoSetChangeSetCollector#reset(org.eclipse.team.core.synchronize.SyncInfoSet) */ public void reset(SyncInfoSet seedSet) { - // Notify thet handler to stop any fetches in progress + // Notify that handler to stop any fetches in progress LogEntryCacheUpdateHandler handler = getLogEntryHandler(); if (handler != null) { handler.stopFetching(); @@ -343,7 +343,7 @@ public class CVSChangeSetCollector extends SyncInfoSetChangeSetCollector impleme IResourceVariant remote = info.getRemote(); if ((base == null && remote != null) || (remote == null && base != null) || (remote != null && base != null && !base.equals(remote))) { synchronized(this) { - ChangeSet set = getChangeSetFor(logEntry); + CheckedInChangeSet set = getChangeSetFor(logEntry); if (set == null) { set = createChangeSetFor(logEntry); add(set); @@ -359,7 +359,7 @@ public class CVSChangeSetCollector extends SyncInfoSetChangeSetCollector impleme } private void addToDefaultSet(String name, SyncInfo info) { - ChangeSet set; + CheckedInChangeSet set; synchronized(this) { set = getChangeSetFor(name); if (set == null) { @@ -370,33 +370,33 @@ public class CVSChangeSetCollector extends SyncInfoSetChangeSetCollector impleme } } - private ChangeSet createDefaultChangeSet(String name) { + private CheckedInChangeSet createDefaultChangeSet(String name) { return new DefaultCheckedInChangeSet(name); } - private ChangeSet createChangeSetFor(ILogEntry logEntry) { + private CheckedInChangeSet createChangeSetFor(ILogEntry logEntry) { return new CVSCheckedInChangeSet(logEntry); } - private ChangeSet getChangeSetFor(ILogEntry logEntry) { - ChangeSet[] sets = getSets(); + private CheckedInChangeSet getChangeSetFor(ILogEntry logEntry) { + ChangeSet[] sets = getSets(); for (int i = 0; i < sets.length; i++) { - ChangeSet set = sets[i]; + ChangeSet set = sets[i]; if (set instanceof CheckedInChangeSet && set.getComment().equals(logEntry.getComment()) && ((CheckedInChangeSet)set).getAuthor().equals(logEntry.getAuthor())) { - return set; + return (CheckedInChangeSet)set; } } return null; } - private ChangeSet getChangeSetFor(String name) { + private CheckedInChangeSet getChangeSetFor(String name) { ChangeSet[] sets = getSets(); for (int i = 0; i < sets.length; i++) { ChangeSet set = sets[i]; if (set.getName().equals(name)) { - return set; + return (CheckedInChangeSet)set; } } return null; diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/WorkspaceSynchronizeParticipant.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/WorkspaceSynchronizeParticipant.java index f992ebe6b..079b5d74b 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/WorkspaceSynchronizeParticipant.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/WorkspaceSynchronizeParticipant.java @@ -11,6 +11,9 @@ *******************************************************************************/ package org.eclipse.team.internal.ccvs.ui.subscriber; +import java.util.HashSet; +import java.util.Set; + import org.eclipse.compare.CompareConfiguration; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IProgressMonitor; @@ -18,7 +21,8 @@ import org.eclipse.jface.preference.PreferencePage; import org.eclipse.jface.viewers.ILabelDecorator; import org.eclipse.jface.window.Window; import org.eclipse.team.core.TeamException; -import org.eclipse.team.core.synchronize.SyncInfo; +import org.eclipse.team.core.diff.IDiff; +import org.eclipse.team.core.mapping.provider.ResourceDiffTree; import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin; import org.eclipse.team.internal.ccvs.ui.*; import org.eclipse.team.internal.ccvs.ui.actions.*; @@ -132,8 +136,8 @@ public class WorkspaceSynchronizeParticipant extends ScopableSubscriberParticipa /* (non-Javadoc) * @see org.eclipse.team.ui.synchronize.ChangeSetCapability#createChangeSet(org.eclipse.team.core.synchronize.SyncInfo[]) */ - public ActiveChangeSet createChangeSet(ISynchronizePageConfiguration configuration, SyncInfo[] infos) { - ActiveChangeSet set = getActiveChangeSetManager().createSet(CVSUIMessages.WorkspaceChangeSetCapability_1, new SyncInfo[0]); + public ActiveChangeSet createChangeSet(ISynchronizePageConfiguration configuration, IDiff[] infos) { + ActiveChangeSet set = getActiveChangeSetManager().createSet(CVSUIMessages.WorkspaceChangeSetCapability_1, new IDiff[0]); CommitSetDialog dialog = new CommitSetDialog(configuration.getSite().getShell(), set, getResources(infos), CVSUIMessages.WorkspaceChangeSetCapability_2, CVSUIMessages.WorkspaceChangeSetCapability_3); // dialog.open(); @@ -142,12 +146,15 @@ public class WorkspaceSynchronizeParticipant extends ScopableSubscriberParticipa return set; } - private IResource[] getResources(SyncInfo[] infos) { - IResource[] resources = new IResource[infos.length]; - for (int i = 0; i < resources.length; i++) { - resources[i] = infos[i].getLocal(); - } - return resources; + private IResource[] getResources(IDiff[] diffs) { + Set result = new HashSet(); + for (int i = 0; i < diffs.length; i++) { + IDiff diff = diffs[i]; + IResource resource = ResourceDiffTree.getResourceFor(diff); + if (resource != null) + result.add(resource); + } + return (IResource[]) result.toArray(new IResource[result.size()]); } /* (non-Javadoc) @@ -170,7 +177,7 @@ public class WorkspaceSynchronizeParticipant extends ScopableSubscriberParticipa } /** - * No arg contructor used for + * No-arg constructor used for * creation of persisted participant after startup */ public WorkspaceSynchronizeParticipant() { diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ActiveChangeSetCollector.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ActiveChangeSetCollector.java index 759979a02..63bd1528e 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ActiveChangeSetCollector.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ActiveChangeSetCollector.java @@ -10,38 +10,31 @@ *******************************************************************************/ package org.eclipse.team.internal.ui.synchronize; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; +import java.util.*; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspaceRunnable; +import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.core.ITeamStatus; import org.eclipse.team.core.TeamException; -import org.eclipse.team.core.synchronize.ISyncInfoSetChangeEvent; -import org.eclipse.team.core.synchronize.ISyncInfoSetChangeListener; -import org.eclipse.team.core.synchronize.SyncInfo; -import org.eclipse.team.core.synchronize.SyncInfoSet; -import org.eclipse.team.core.synchronize.SyncInfoTree; +import org.eclipse.team.core.diff.*; +import org.eclipse.team.core.mapping.IResourceDiffTree; +import org.eclipse.team.core.mapping.provider.ResourceDiffTree; +import org.eclipse.team.core.synchronize.*; import org.eclipse.team.internal.core.subscribers.*; import org.eclipse.team.internal.ui.TeamUIPlugin; -import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; -import org.eclipse.team.ui.synchronize.ISynchronizeParticipant; +import org.eclipse.team.ui.synchronize.*; /** - * Group incoming changes according to the active change set thet are + * Group incoming changes according to the active change set that are * located in */ -public class ActiveChangeSetCollector implements ISyncInfoSetChangeListener { +public class ActiveChangeSetCollector implements IDiffChangeListener { private final ISynchronizePageConfiguration configuration; /* - * Map active change sets to infos displayed by the particpant + * Map active change sets to infos displayed by the participant */ private final Map activeSets = new HashMap(); @@ -81,7 +74,7 @@ public class ActiveChangeSetCollector implements ISyncInfoSetChangeListener { public void run(IProgressMonitor monitor) { remove(set); if (!set.isEmpty()) { - add(set.getSyncInfoSet().getSyncInfos()); + add(getSyncInfos(set).getSyncInfos()); } } }, true, true); @@ -96,14 +89,14 @@ public class ActiveChangeSetCollector implements ISyncInfoSetChangeListener { }, true, true); } - public void resourcesChanged(final ChangeSet set, final IResource[] resources) { + public void resourcesChanged(final ChangeSet set, final IPath[] paths) { // Look for any resources that were removed from the set but are still out-of sync. // Re-add those resources final List outOfSync = new ArrayList(); - for (int i = 0; i < resources.length; i++) { - IResource resource = resources[i]; - if (!set.contains(resource)) { - SyncInfo info = provider.getSyncInfoSet().getSyncInfo(resource); + for (int i = 0; i < paths.length; i++) { + IPath path = paths[i]; + if (!((DiffChangeSet)set).contains(path)) { + SyncInfo info = getSyncInfo(path); if (info != null && info.getKind() != SyncInfo.IN_SYNC) { outOfSync.add(info); } @@ -117,11 +110,10 @@ public class ActiveChangeSetCollector implements ISyncInfoSetChangeListener { }, true, true); } } - }; /** - * Listener that wants to recieve change events from this collector + * Listener that wants to receive change events from this collector */ private IChangeSetChangeListener listener; @@ -144,10 +136,10 @@ public class ActiveChangeSetCollector implements ISyncInfoSetChangeListener { } /** - * Repopulate the change sets from the seed set. + * Re-populate the change sets from the seed set. * If <code>null</code> is passed, the state * of the collector is cleared but the set is not - * repopulated. + * re-populated. * <p> * This method is invoked by the model provider when the * model provider changes state. It should not @@ -170,7 +162,7 @@ public class ActiveChangeSetCollector implements ISyncInfoSetChangeListener { } activeSets.clear(); - // Now repopulate + // Now re-populate if (seedSet != null) { if (getConfiguration().getComparisonType() == ISynchronizePageConfiguration.THREE_WAY) { // Show all active change sets even if they are empty @@ -255,7 +247,7 @@ public class ActiveChangeSetCollector implements ISyncInfoSetChangeListener { } else { for (int j = 0; j < sets.length; j++) { ChangeSet set = sets[j]; - SyncInfoSet targetSet = (SyncInfoSet)activeSets.get(set); + SyncInfoSet targetSet = getSyncInfoSet(set); if (targetSet == null) { // This will add all the appropriate sync info to the set createSyncInfoSet(set); @@ -306,7 +298,7 @@ public class ActiveChangeSetCollector implements ISyncInfoSetChangeListener { * Add the set from the collector. */ public void add(ChangeSet set) { - SyncInfoSet targetSet = (SyncInfoSet)activeSets.get(set); + SyncInfoSet targetSet = getSyncInfoSet(set); if (targetSet == null) { createSyncInfoSet(set); } @@ -316,7 +308,7 @@ public class ActiveChangeSetCollector implements ISyncInfoSetChangeListener { } private SyncInfoTree createSyncInfoSet(ChangeSet set) { - SyncInfoTree sis = (SyncInfoTree)activeSets.get(set); + SyncInfoTree sis = getSyncInfoSet(set); // Register the listener last since the add will // look for new elements boolean added = false; @@ -330,24 +322,81 @@ public class ActiveChangeSetCollector implements ISyncInfoSetChangeListener { sis.beginInput(); if (!sis.isEmpty()) sis.removeAll(sis.getResources()); - sis.addAll(select(set.getSyncInfoSet().getSyncInfos())); + sis.addAll(getSyncInfos(set)); } finally { if (sis != null) sis.endInput(null); } if (added) { - set.getSyncInfoSet().addSyncSetChangedListener(this); + ((DiffChangeSet)set).getDiffTree().addDiffChangeListener(this); if (listener != null) listener.setAdded(set); } return sis; } - /* + private SyncInfoSet getSyncInfos(ChangeSet set) { + IDiff[] diffs = ((ResourceDiffTree)((DiffChangeSet)set).getDiffTree()).getDiffs(); + return asSyncInfoSet(diffs); + } + + private SyncInfoSet asSyncInfoSet(IDiff[] diffs) { + SyncInfoSet result = new SyncInfoSet(); + for (int i = 0; i < diffs.length; i++) { + IDiff diff = diffs[i]; + if (select(diff)) { + SyncInfo info = asSyncInfo(diff); + if (info != null) + result.add(info); + } + } + return result; + } + + private SyncInfo asSyncInfo(IDiff diff) { + try { + return ((SubscriberParticipant)getConfiguration().getParticipant()).getSubscriber().getSyncInfo(ResourceDiffTree.getResourceFor(diff)); + } catch (TeamException e) { + TeamUIPlugin.log(e); + } + return null; + } + + private boolean select(IDiff diff) { + return getSeedSet().getSyncInfo(ResourceDiffTree.getResourceFor(diff)) != null; + } + + /* private */ SyncInfo getSyncInfo(IPath path) { + return getSyncInfo(getSeedSet(), path); + } + + /* private */ IResource[] getResources(SyncInfoSet set, IPath[] paths) { + List result = new ArrayList(); + for (int i = 0; i < paths.length; i++) { + IPath path = paths[i]; + SyncInfo info = getSyncInfo(set, path); + if (info != null) { + result.add(info.getLocal()); + } + } + return (IResource[]) result.toArray(new IResource[result.size()]); + } + + private SyncInfo getSyncInfo(SyncInfoSet set, IPath path) { + SyncInfo[] infos = set.getSyncInfos(); + for (int i = 0; i < infos.length; i++) { + SyncInfo info = infos[i]; + if (info.getLocal().getFullPath().equals(path)) + return info; + } + return null; + } + + /* * Remove the set from the collector. */ public void remove(ChangeSet set) { - set.getSyncInfoSet().removeSyncSetChangedListener(this); + ((DiffChangeSet)set).getDiffTree().removeDiffChangeListener(this); activeSets.remove(set); if (listener != null) { listener.setRemoved(set); @@ -359,53 +408,13 @@ public class ActiveChangeSetCollector implements ISyncInfoSetChangeListener { * or null if there isn't one. */ public SyncInfoTree getSyncInfoSet(ChangeSet set) { - SyncInfoTree sis = (SyncInfoTree)activeSets.get(set); - return sis; - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.synchronize.ISyncInfoSetChangeListener#syncInfoSetReset(org.eclipse.team.core.synchronize.SyncInfoSet, org.eclipse.core.runtime.IProgressMonitor) - */ - public void syncInfoSetReset(final SyncInfoSet set, IProgressMonitor monitor) { - provider.performUpdate(new IWorkspaceRunnable() { - public void run(IProgressMonitor monitor) { - ChangeSet changeSet = getChangeSet(set); - if (changeSet != null) { - SyncInfoSet targetSet = (SyncInfoSet)activeSets.get(changeSet); - if (targetSet != null) { - targetSet.clear(); - targetSet.addAll(select(set.getSyncInfos())); - rootSet.removeAll(set.getResources()); - } - } - } - }, true /* preserver expansion */, true /* run in UI thread */); - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.synchronize.ISyncInfoSetChangeListener#syncInfoChanged(org.eclipse.team.core.synchronize.ISyncInfoSetChangeEvent, org.eclipse.core.runtime.IProgressMonitor) - */ - public void syncInfoChanged(final ISyncInfoSetChangeEvent event, IProgressMonitor monitor) { - provider.performUpdate(new IWorkspaceRunnable() { - public void run(IProgressMonitor monitor) { - ChangeSet changeSet = getChangeSet(event.getSet()); - if (changeSet != null) { - SyncInfoSet targetSet = (SyncInfoSet)activeSets.get(changeSet); - if (targetSet != null) { - targetSet.removeAll(event.getRemovedResources()); - targetSet.addAll(select(event.getChangedResources())); - targetSet.addAll(select(event.getAddedResources())); - rootSet.removeAll(event.getSet().getResources()); - } - } - } - }, true /* preserver expansion */, true /* run in UI thread */); + return (SyncInfoTree)activeSets.get(set); } - private ChangeSet getChangeSet(SyncInfoSet set) { + private ChangeSet getChangeSet(IDiffTree tree) { for (Iterator iter = activeSets.keySet().iterator(); iter.hasNext();) { ChangeSet changeSet = (ChangeSet) iter.next(); - if (changeSet.getSyncInfoSet() == set) { + if (((DiffChangeSet)changeSet).getDiffTree() == tree) { return changeSet; } } @@ -416,28 +425,10 @@ public class ActiveChangeSetCollector implements ISyncInfoSetChangeListener { return getSeedSet().getSyncInfo(info.getLocal()) != null; } - private SyncInfoSet select(SyncInfo[] syncInfos) { - SyncInfoSet result = new SyncInfoSet(); - for (int i = 0; i < syncInfos.length; i++) { - SyncInfo info = syncInfos[i]; - if (getSeedSet().getSyncInfo(info.getLocal()) != null) { - result.add(info); - } - } - return result; - } - private SyncInfoSet getSeedSet() { return provider.getSyncInfoSet(); } - /* (non-Javadoc) - * @see org.eclipse.team.core.synchronize.ISyncInfoSetChangeListener#syncInfoSetErrors(org.eclipse.team.core.synchronize.SyncInfoSet, org.eclipse.team.core.ITeamStatus[], org.eclipse.core.runtime.IProgressMonitor) - */ - public void syncInfoSetErrors(SyncInfoSet set, ITeamStatus[] errors, IProgressMonitor monitor) { - // Errors are not injected into the active change sets - } - public void dispose() { getActiveChangeSetManager().removeListener(activeChangeSetListener); } @@ -455,4 +446,26 @@ public class ActiveChangeSetCollector implements ISyncInfoSetChangeListener { getActiveChangeSetManager().addListener(activeChangeSetListener); } } + + public void diffsChanged(final IDiffChangeEvent event, IProgressMonitor monitor) { + provider.performUpdate(new IWorkspaceRunnable() { + public void run(IProgressMonitor monitor) { + ChangeSet changeSet = getChangeSet(event.getTree()); + if (changeSet != null) { + SyncInfoSet targetSet = getSyncInfoSet(changeSet); + if (targetSet != null) { + targetSet.removeAll(getResources(targetSet, event.getRemovals())); + targetSet.addAll(asSyncInfoSet(event.getAdditions())); + targetSet.addAll(asSyncInfoSet(event.getChanges())); + rootSet.removeAll(((IResourceDiffTree)event.getTree()).getAffectedResources()); + } + } + } + + }, true /* preserver expansion */, true /* run in UI thread */); + } + + public void propertyChanged(IDiffTree tree, int property, IPath[] paths) { + // Nothing to do + } } diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ChangeSetCapability.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ChangeSetCapability.java index 31e0677cb..c31bfc38a 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ChangeSetCapability.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ChangeSetCapability.java @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.team.internal.ui.synchronize; -import org.eclipse.team.core.synchronize.SyncInfo; +import org.eclipse.team.core.diff.IDiff; import org.eclipse.team.internal.core.subscribers.ActiveChangeSet; import org.eclipse.team.internal.core.subscribers.SubscriberChangeSetCollector; import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; @@ -73,10 +73,10 @@ public abstract class ChangeSetCapability { * return <code>null</code>. This method must be * overridden by subclasses that support active change sets. * @param configuration the configuration of the page displaying the change sets - * @param infos the sync info to be added to the change set + * @param diffs the sync info to be added to the change set * @return the created set. */ - public ActiveChangeSet createChangeSet(ISynchronizePageConfiguration configuration, SyncInfo[] infos) { + public ActiveChangeSet createChangeSet(ISynchronizePageConfiguration configuration, IDiff[] diffs) { return null; } diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ChangeSetModelProvider.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ChangeSetModelProvider.java index edde887c9..f69ddfbad 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ChangeSetModelProvider.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ChangeSetModelProvider.java @@ -14,7 +14,7 @@ import java.util.HashMap; import java.util.Map; import org.eclipse.compare.structuremergeviewer.IDiffElement; -import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.util.IPropertyChangeListener; @@ -51,7 +51,7 @@ public class ChangeSetModelProvider extends CompositeModelProvider { final SyncInfoTree syncInfoSet; // TODO: May need to be modified to work with two-way if (set instanceof CheckedInChangeSet) { - syncInfoSet = set.getSyncInfoSet(); + syncInfoSet = checkedInCollector.getSyncInfoSet(set); } else { syncInfoSet = activeCollector.getSyncInfoSet(set); } @@ -84,7 +84,7 @@ public class ChangeSetModelProvider extends CompositeModelProvider { /* (non-Javadoc) * @see org.eclipse.team.core.subscribers.IChangeSetChangeListener#resourcesChanged(org.eclipse.team.core.subscribers.ChangeSet, org.eclipse.core.resources.IResource[]) */ - public void resourcesChanged(ChangeSet set, IResource[] resources) { + public void resourcesChanged(ChangeSet set, IPath[] paths) { // The sub-providers listen directly to the sets for changes // There is no global action to be taken for such changes } diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/SyncInfoSetChangeSetCollector.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/SyncInfoSetChangeSetCollector.java index 54fb213b0..4fae764e5 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/SyncInfoSetChangeSetCollector.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/SyncInfoSetChangeSetCollector.java @@ -17,8 +17,7 @@ import org.eclipse.core.resources.IWorkspaceRunnable; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.team.core.ITeamStatus; import org.eclipse.team.core.synchronize.*; -import org.eclipse.team.internal.core.subscribers.ChangeSet; -import org.eclipse.team.internal.core.subscribers.ChangeSetCollector; +import org.eclipse.team.internal.core.subscribers.*; import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; /** @@ -29,7 +28,7 @@ import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; * <p> * This class does not register as a change listener with the seed set. It * is up to clients to invoke either the <code>reset</code> or <code>handleChange</code> - * methods in reponse to seed set changes. + * methods in response to seed set changes. * @since 3.1 */ public abstract class SyncInfoSetChangeSetCollector extends ChangeSetCollector { @@ -121,9 +120,9 @@ public abstract class SyncInfoSetChangeSetCollector extends ChangeSetCollector { * @param resources the resources to be removed */ protected void remove(IResource[] resources) { - ChangeSet[] sets = getSets(); + ChangeSet[] sets = getSets(); for (int i = 0; i < sets.length; i++) { - ChangeSet set = sets[i]; + ChangeSet set = sets[i]; set.remove(resources); } } @@ -136,9 +135,9 @@ public abstract class SyncInfoSetChangeSetCollector extends ChangeSetCollector { } /** - * Repopulate the change sets from the seed set. + * Re-populate the change sets from the seed set. * If <code>null</code> is passed, clear any state - * but do not repopulate. + * but do not re-populate. * <p> * This method is invoked by the model provider when the * model provider changes state. It should not @@ -151,12 +150,13 @@ public abstract class SyncInfoSetChangeSetCollector extends ChangeSetCollector { * updated properly. * <p> * Subclasses may override this method. + * @param seedSet */ public void reset(SyncInfoSet seedSet) { // First, remove all the sets ChangeSet[] sets = getSets(); for (int i = 0; i < sets.length; i++) { - ChangeSet set2 = sets[i]; + ChangeSet set2 = sets[i]; remove(set2); } if (seedSet != null) { @@ -217,7 +217,7 @@ public abstract class SyncInfoSetChangeSetCollector extends ChangeSetCollector { * the updates occur in the proper thread in order to ensure thread safety. * <p> * The update may be run in a different thread then the caller. - * However, regardless of which thread the upate is run in, the view + * However, regardless of which thread the update is run in, the view * will be updated once the update is completed. * @param runnable the workspace runnable that updates the sync sets. * @param preserveExpansion whether the expansed items in the view should @@ -236,7 +236,7 @@ public abstract class SyncInfoSetChangeSetCollector extends ChangeSetCollector { } /** - * This method should wait unti any background processing is + * This method should wait until any background processing is * completed. It is for testing purposes. By default, it does not wait at all. * Subclasses that perform work in the background should override. * @param monitor a progress monitor @@ -244,4 +244,35 @@ public abstract class SyncInfoSetChangeSetCollector extends ChangeSetCollector { public void waitUntilDone(IProgressMonitor monitor) { // Do nothing, by default } + + protected void handleSetAdded(ChangeSet set) { + ((CheckedInChangeSet)set).getSyncInfoSet().addSyncSetChangedListener(getChangeSetChangeListener()); + super.handleSetAdded(set); + } + + protected void handleSetRemoved(ChangeSet set) { + ((CheckedInChangeSet)set).getSyncInfoSet().removeSyncSetChangedListener(getChangeSetChangeListener()); + super.handleSetRemoved(set); + } + + /** + * Return the Change Set whose sync info set is the + * one given. + * @param set a sync info set + * @return the change set for the given sync info set + */ + protected ChangeSet getChangeSet(SyncInfoSet set) { + ChangeSet[] sets = getSets(); + for (int i = 0; i < sets.length; i++) { + ChangeSet changeSet = sets[i]; + if (((CheckedInChangeSet)changeSet).getSyncInfoSet() == set) { + return changeSet; + } + } + return null; + } + + public SyncInfoTree getSyncInfoSet(ChangeSet set) { + return ((CheckedInChangeSet)set).getSyncInfoSet(); + } } diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/ChangeSetActionGroup.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/ChangeSetActionGroup.java index 175489bb2..ae71af990 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/ChangeSetActionGroup.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/ChangeSetActionGroup.java @@ -11,16 +11,20 @@ package org.eclipse.team.internal.ui.synchronize.actions; import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.List; import org.eclipse.compare.structuremergeviewer.IDiffElement; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.*; import org.eclipse.jface.action.*; import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.*; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.widgets.Control; +import org.eclipse.team.core.diff.IDiff; +import org.eclipse.team.core.subscribers.Subscriber; import org.eclipse.team.core.synchronize.FastSyncInfoFilter; import org.eclipse.team.core.synchronize.SyncInfo; import org.eclipse.team.core.synchronize.FastSyncInfoFilter.SyncInfoDirectionFilter; @@ -78,8 +82,7 @@ public class ChangeSetActionGroup extends SynchronizePageActionGroup { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { syncExec(new Runnable() { public void run() { - SyncInfo[] infos = getSyncInfoSet().getSyncInfos(); - ActiveChangeSet set = createChangeSet(infos); + ActiveChangeSet set = createChangeSet(getDiffs(getSyncInfoSet().getResources())); if (set != null) { getActiveChangeSetManager().add(set); } @@ -188,13 +191,15 @@ public class ChangeSetActionGroup extends SynchronizePageActionGroup { return new SynchronizeModelOperation(configuration, elements) { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + IResource[] resources = getSyncInfoSet().getResources(); if (set != null) { - set.add(getSyncInfoSet().getSyncInfos()); + IDiff[] diffArray = getDiffs(resources); + set.add(diffArray); } else { ChangeSet[] sets = getActiveChangeSetManager().getSets(); for (int i = 0; i < sets.length; i++) { ActiveChangeSet activeSet = (ActiveChangeSet)sets[i]; - activeSet.remove(getSyncInfoSet().getResources()); + activeSet.remove(resources); } } } @@ -420,8 +425,8 @@ public class ChangeSetActionGroup extends SynchronizePageActionGroup { return new ChangeSetModelSorter(provider, sortCriteria); } - private ActiveChangeSet createChangeSet(SyncInfo[] infos) { - return getChangeSetCapability().createChangeSet(getConfiguration(), infos); + private ActiveChangeSet createChangeSet(IDiff[] diffs) { + return getChangeSetCapability().createChangeSet(getConfiguration(), diffs); } private void editChangeSet(ActiveChangeSet set) { @@ -431,4 +436,22 @@ public class ChangeSetActionGroup extends SynchronizePageActionGroup { private ChangeSetCapability getChangeSetCapability() { return provider.getChangeSetCapability(); } + + private IDiff[] getDiffs(IResource[] resources) { + List diffs = new ArrayList(); + Subscriber s = ((SubscriberParticipant)getConfiguration().getParticipant()).getSubscriber(); + for (int i = 0; i < resources.length; i++) { + IResource resource = resources[i]; + try { + IDiff diff = s.getDiff(resource); + if (diff != null) + diffs.add(diff); + } catch (CoreException e) { + TeamUIPlugin.log(e); + } + } + IDiff[] diffArray = (IDiff[]) diffs + .toArray(new IDiff[diffs.size()]); + return diffArray; + } } diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/CVSChangeSetTests.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/CVSChangeSetTests.java index 11fbd9e15..487111448 100644 --- a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/CVSChangeSetTests.java +++ b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/subscriber/CVSChangeSetTests.java @@ -12,7 +12,6 @@ package org.eclipse.team.tests.ccvs.core.subscriber; import java.io.ByteArrayInputStream; import java.util.*; -import java.util.ArrayList; import java.util.List; import junit.framework.Test; @@ -23,6 +22,7 @@ import org.eclipse.core.runtime.*; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.widgets.*; import org.eclipse.team.core.TeamException; +import org.eclipse.team.core.diff.IDiff; import org.eclipse.team.core.subscribers.*; import org.eclipse.team.core.synchronize.SyncInfo; import org.eclipse.team.internal.ccvs.core.CVSTag; @@ -405,7 +405,7 @@ public class CVSChangeSetTests extends CVSSyncSubscriberTest { newFile.create(new ByteArrayInputStream("Hi There".getBytes()), false, null); // Create an active commit set and assert that it appears in the sync view SubscriberChangeSetCollector manager = getActiveChangeSetManager(); - ActiveChangeSet set = manager.createSet("test", new SyncInfo[0]); + ActiveChangeSet set = manager.createSet("test", new IDiff[0]); manager.add(set); assertInActiveSet(new IResource[] { }, set); assertInRootSet(new IResource[] {newFolder, newFile}); diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/CommitSetTests.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/CommitSetTests.java index ddb35d7d9..49dc2ecfa 100644 --- a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/CommitSetTests.java +++ b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/CommitSetTests.java @@ -18,8 +18,10 @@ import junit.framework.Test; import org.eclipse.core.resources.*; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; import org.eclipse.swt.widgets.Display; import org.eclipse.team.core.TeamException; +import org.eclipse.team.internal.ccvs.core.CVSException; import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin; import org.eclipse.team.internal.core.subscribers.*; import org.eclipse.team.tests.ccvs.core.EclipseTest; @@ -46,7 +48,7 @@ public class CommitSetTests extends EclipseTest { // TODO Auto-generated method stub } - public void resourcesChanged(ChangeSet set, IResource[] resources) { + public void resourcesChanged(ChangeSet set, IPath[] paths) { // TODO Auto-generated method stub } @@ -71,11 +73,11 @@ public class CommitSetTests extends EclipseTest { * @return the newly create commit set * @throws TeamException */ - protected ActiveChangeSet createCommitSet(String title, IFile[] files, boolean manageSet) throws TeamException { + protected ActiveChangeSet createCommitSet(String title, IFile[] files, boolean manageSet) throws CoreException { assertIsModified(getName(), files); SubscriberChangeSetCollector manager = CVSUIPlugin.getPlugin().getChangeSetManager(); ActiveChangeSet set = manager.createSet(title, files); - assertEquals("Not all files were asdded to the set", files.length, set.getResources().length); + assertEquals("Not all files were added to the set", files.length, set.getResources().length); if (manageSet) { manager.add(set); waitForSetAddedEvent(set); |