Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2004-09-29 14:11:58 +0000
committerMichael Valenta2004-09-29 14:11:58 +0000
commit7bc47be35fc7b148198e252db4baf4dba3570e48 (patch)
treed946f5f4ce6273ba07ee120b2ecb67647060498d
parent03e19ee17d42b09bcfb6fd64b6a2478d00d1bb2a (diff)
downloadeclipse.platform.team-7bc47be35fc7b148198e252db4baf4dba3570e48.tar.gz
eclipse.platform.team-7bc47be35fc7b148198e252db4baf4dba3570e48.tar.xz
eclipse.platform.team-7bc47be35fc7b148198e252db4baf4dba3570e48.zip
More refactoring
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/CVSChangeSetCollector.java142
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ChangeSetModelProvider.java7
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/SyncInfoSetChangeSetCollector.java (renamed from bundles/org.eclipse.team.core/src/org/eclipse/team/core/subscribers/SyncInfoSetChangeSetCollector.java)110
3 files changed, 198 insertions, 61 deletions
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 67934efcf..a813b3abf 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
@@ -25,19 +25,24 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.team.core.subscribers.SyncInfoSetChangeSetCollector;
+import org.eclipse.team.core.TeamException;
+import org.eclipse.team.core.subscribers.ChangeSet;
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.CVSCompareSubscriber;
import org.eclipse.team.internal.ccvs.core.CVSException;
import org.eclipse.team.internal.ccvs.core.CVSSyncInfo;
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.ICVSRemoteFile;
import org.eclipse.team.internal.ccvs.core.ICVSRemoteResource;
import org.eclipse.team.internal.ccvs.core.ICVSResource;
+import org.eclipse.team.internal.ccvs.core.ILogEntry;
import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
import org.eclipse.team.internal.ccvs.core.resources.RemoteFile;
+import org.eclipse.team.internal.ccvs.core.resources.RemoteResource;
import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo;
import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo;
import org.eclipse.team.internal.ccvs.core.util.Util;
@@ -45,9 +50,12 @@ import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
import org.eclipse.team.internal.ccvs.ui.Policy;
import org.eclipse.team.internal.ccvs.ui.operations.RemoteLogOperation;
import org.eclipse.team.internal.ccvs.ui.operations.RemoteLogOperation.LogEntryCache;
+import org.eclipse.team.internal.ccvs.ui.subscriber.ChangeLogModelProvider.CVSUpdatableSyncInfo;
import org.eclipse.team.internal.ui.Utils;
import org.eclipse.team.ui.synchronize.ISynchronizeManager;
+import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
import org.eclipse.team.ui.synchronize.ISynchronizeParticipant;
+import org.eclipse.team.ui.synchronize.SyncInfoSetChangeSetCollector;
/**
* Collector that fetches the log for incoming CVS change sets
@@ -101,8 +109,8 @@ public class CVSChangeSetCollector extends SyncInfoSetChangeSetCollector {
}
};
- public CVSChangeSetCollector(SyncInfoSet seedSet) {
- super(seedSet);
+ public CVSChangeSetCollector(ISynchronizePageConfiguration configuration) {
+ super(configuration);
}
/* (non-Javadoc)
@@ -125,7 +133,6 @@ public class CVSChangeSetCollector extends SyncInfoSetChangeSetCollector {
// Decide which nodes we have to fetch log histories
SyncInfo[] infos = set.getSyncInfos();
ArrayList remoteChanges = new ArrayList();
- ArrayList localChanges = new ArrayList();
for (int i = 0; i < infos.length; i++) {
SyncInfo info = infos[i];
if(isRemoteChange(info)) {
@@ -364,4 +371,131 @@ public class CVSChangeSetCollector extends SyncInfoSetChangeSetCollector {
}
super.dispose();
}
+
+ /*
+ * Add the following sync info elements to the viewer. It is assumed that these elements have associated
+ * log entries cached in the log operation.
+ */
+ private void addLogEntries(SyncInfo[] commentInfos, LogEntryCache logs, IProgressMonitor monitor) {
+ try {
+ monitor.beginTask(null, commentInfos.length * 10);
+ if (logs != null) {
+ for (int i = 0; i < commentInfos.length; i++) {
+ addSyncInfoToCommentNode(commentInfos[i], logs);
+ monitor.worked(10);
+ }
+ }
+ } finally {
+ monitor.done();
+ }
+ }
+
+ /*
+ * Create a node for the given sync info object. The logs should contain the log for this info.
+ *
+ * @param info the info for which to create a node in the model
+ * @param log the cvs log for this node
+ */
+ private void addSyncInfoToCommentNode(SyncInfo info, LogEntryCache logs) {
+ ICVSRemoteResource remoteResource = getRemoteResource((CVSSyncInfo)info);
+ if(isTagComparison() && remoteResource != null) {
+ addMultipleRevisions(info, logs, remoteResource);
+ } else {
+ addSingleRevision(info, logs, remoteResource);
+ }
+ }
+
+ /*
+ * Add a single log entry to the model.
+ *
+ * @param info
+ * @param logs
+ * @param remoteResource
+ */
+ private void addSingleRevision(SyncInfo info, LogEntryCache logs, ICVSRemoteResource remoteResource) {
+ ILogEntry logEntry = logs.getLogEntry(remoteResource);
+ // For incoming deletions grab the comment for the latest on the same branch
+ // which is now in the attic.
+ try {
+ String remoteRevision = ((ICVSRemoteFile) remoteResource).getRevision();
+ if (isDeletedRemotely(info)) {
+ ILogEntry[] logEntries = logs.getLogEntries(remoteResource);
+ for (int i = 0; i < logEntries.length; i++) {
+ ILogEntry entry = logEntries[i];
+ String revision = entry.getRevision();
+ if (entry.isDeletion() && ResourceSyncInfo.isLaterRevision(revision, remoteRevision)) {
+ logEntry = entry;
+ }
+ }
+ }
+ } catch (TeamException e) {
+ // continue and skip deletion checks
+ }
+ addRemoteChange(info, remoteResource, logEntry);
+ }
+
+ /*
+ * Add multiple log entries to the model.
+ *
+ * @param info
+ * @param logs
+ * @param remoteResource
+ */
+ private void addMultipleRevisions(SyncInfo info, LogEntryCache logs, ICVSRemoteResource remoteResource) {
+ ILogEntry[] logEntries = logs.getLogEntries(remoteResource);
+ if(logEntries == null || logEntries.length == 0) {
+ // If for some reason we don't have a log entry, try the latest
+ // remote.
+ addRemoteChange(info, null, null);
+ } else {
+ for (int i = 0; i < logEntries.length; i++) {
+ ILogEntry entry = logEntries[i];
+ addRemoteChange(info, remoteResource, entry);
+ }
+ }
+ }
+
+ private boolean isDeletedRemotely(SyncInfo info) {
+ int kind = info.getKind();
+ if(kind == (SyncInfo.INCOMING | SyncInfo.DELETION)) return true;
+ if(SyncInfo.getDirection(kind) == SyncInfo.CONFLICTING && info.getRemote() == null) return true;
+ return false;
+ }
+
+ /*
+ * Add the remote change to an incoming commit set
+ */
+ private void addRemoteChange(SyncInfo info, ICVSRemoteResource remoteResource, ILogEntry logEntry) {
+ if(remoteResource != null && logEntry != null && isRemoteChange(info)) {
+ ChangeSet set = getChangeSetFor(logEntry);
+ if (set == null) {
+ set = createChangeSetFor(logEntry);
+ add(set);
+ }
+ if(requiresCustomSyncInfo(info, remoteResource, logEntry)) {
+ info = new CVSUpdatableSyncInfo(info.getKind(), info.getLocal(), info.getBase(), (RemoteResource)logEntry.getRemoteFile(), ((CVSSyncInfo)info).getSubscriber());
+ try {
+ info.init();
+ } catch (TeamException e) {
+ // this shouldn't happen, we've provided our own calculate kind
+ }
+ }
+ set.add(info);
+ } else {
+ // The info was not retrieved for the remote change for some reason.
+ // Add the node to the root
+ ChangeSet set = getDefaultChangeSet();
+ set.add(info);
+ }
+ }
+
+ private boolean requiresCustomSyncInfo(SyncInfo info, ICVSRemoteResource remoteResource, ILogEntry logEntry) {
+ // Only interested in non-deletions
+ if (logEntry.isDeletion() || !(info instanceof CVSSyncInfo)) return false;
+ // Only require a custom sync info if the remote of the sync info
+ // differs from the remote in the log entry
+ IResourceVariant remote = info.getRemote();
+ if (remote == null) return true;
+ return !remote.equals(remoteResource);
+ }
}
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 3026c7d36..16c207dd0 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
@@ -108,5 +108,12 @@ public class ChangeSetModelProvider extends CompositeModelProvider {
this.viewerSorter = viewerSorter;
firePropertyChange(ISynchronizeModelProvider.P_VIEWER_SORTER, null, null);
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ui.synchronize.AbstractSynchronizeModelProvider#runViewUpdate(java.lang.Runnable)
+ */
+ public void runViewUpdate(Runnable runnable) {
+ super.runViewUpdate(runnable);
+ }
}
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/subscribers/SyncInfoSetChangeSetCollector.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/SyncInfoSetChangeSetCollector.java
index ac4deaf0c..720843b32 100644
--- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/subscribers/SyncInfoSetChangeSetCollector.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/SyncInfoSetChangeSetCollector.java
@@ -8,7 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.team.core.subscribers;
+package org.eclipse.team.ui.synchronize;
import java.util.ArrayList;
import java.util.Arrays;
@@ -17,18 +17,30 @@ import java.util.List;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.team.core.ITeamStatus;
+import org.eclipse.team.core.subscribers.ChangeSet;
+import org.eclipse.team.core.subscribers.ChangeSetCollector;
+import org.eclipse.team.core.subscribers.CheckedInChangeSet;
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.internal.ui.synchronize.ChangeSetModelProvider;
/**
- * Contains a set of CheckedInChangeSets.
+ * This abstract class provides API for accumulating the <code>SyncInfo</code>
+ * from a seed <code>SyncInfoSet</code> into a set of <code>ChangeSet</code>
+ * instances. It is used to provide the input to a synchronize page when
+ * change sets are enabled.
+ * <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.
* @since 3.1
*/
public abstract class SyncInfoSetChangeSetCollector extends ChangeSetCollector {
- SyncInfoSet seedSet;
+ private final ISynchronizePageConfiguration configuration;
+ private ChangeSetModelProvider provider;
/*
* Listener that will remove sets when they become empty.
@@ -69,55 +81,14 @@ public abstract class SyncInfoSetChangeSetCollector extends ChangeSetCollector {
}
};
- /*
- * The listener that reacts to seed set changes.
- */
- ISyncInfoSetChangeListener seedSetListener = new ISyncInfoSetChangeListener() {
-
- /* (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) {
- reset();
- }
-
- /* (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) {
- List removals = new ArrayList();
- List additions = new ArrayList();
- removals.addAll(Arrays.asList(event.getRemovedResources()));
- additions.addAll(Arrays.asList(event.getAddedResources()));
- SyncInfo[] changed = event.getChangedResources();
- for (int i = 0; i < changed.length; i++) {
- SyncInfo info = changed[i];
- additions.add(info);
- removals.add(info.getLocal());
- }
- if (!removals.isEmpty()) {
- remove((IResource[]) removals.toArray(new IResource[removals.size()]));
- }
- if (!additions.isEmpty()) {
- add((SyncInfo[]) additions.toArray(new SyncInfo[additions.size()]));
- }
- }
- /* (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) {
- // TODO Auto-generated method stub
- }
- };
-
/**
* Create a collector that contains the sync info from the given seed set
* @param seedSet the set used to determine which sync info
* should be included in the change sets.
*/
- public SyncInfoSetChangeSetCollector(SyncInfoSet seedSet) {
- this.seedSet = seedSet;
+ public SyncInfoSetChangeSetCollector(ISynchronizePageConfiguration configuration) {
+ this.configuration = configuration;
}
/**
@@ -146,15 +117,6 @@ public abstract class SyncInfoSetChangeSetCollector extends ChangeSetCollector {
super.add(set);
}
- /**
- * Return the set that contains all the sync info that should
- * be considered for inclusion by this collector.
- * @return
- */
- public SyncInfoSet getSeedSet() {
- return seedSet;
- }
-
/* (non-Javadoc)
* @see org.eclipse.team.core.subscribers.ChangeSetCollector#getChangeSetChangeListener()
*/
@@ -166,13 +128,47 @@ public abstract class SyncInfoSetChangeSetCollector extends ChangeSetCollector {
* Repopulate the change sets from the seed set.
*
*/
- public void reset() {
+ 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];
remove(set2);
}
- add(getSeedSet().getSyncInfos());
+ add(seedSet.getSyncInfos());
+ }
+
+ public void handleChange(ISyncInfoSetChangeEvent event) {
+ List removals = new ArrayList();
+ List additions = new ArrayList();
+ removals.addAll(Arrays.asList(event.getRemovedResources()));
+ additions.addAll(Arrays.asList(event.getAddedResources()));
+ SyncInfo[] changed = event.getChangedResources();
+ for (int i = 0; i < changed.length; i++) {
+ SyncInfo info = changed[i];
+ additions.add(info);
+ removals.add(info.getLocal());
+ }
+ if (!removals.isEmpty()) {
+ remove((IResource[]) removals.toArray(new IResource[removals.size()]));
+ }
+ if (!additions.isEmpty()) {
+ add((SyncInfo[]) additions.toArray(new SyncInfo[additions.size()]));
+ }
+ }
+
+ public ISynchronizePageConfiguration getConfiguration() {
+ return configuration;
+ }
+
+ protected void runViewUpdate(Runnable runnable) {
+ provider.runViewUpdate(runnable);
+ }
+
+ /* (non-javadoc)
+ * Sets the provider for this collector. This method is for internal use only.
+ */
+ public void setProvider(ChangeSetModelProvider provider) {
+ this.provider = provider;
}
}

Back to the top