Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 13a3352b9ef46c2c4ffc9d1a16c6dd953a7953cb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*******************************************************************************
 * Copyright (c) 2000, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.internal.ccvs.ui.subscriber;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.compare.structuremergeviewer.DiffNode;
import org.eclipse.compare.structuremergeviewer.IDiffElement;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.team.core.subscribers.*;
import org.eclipse.team.internal.ccvs.core.*;
import org.eclipse.team.internal.ccvs.core.resources.RemoteFile;
import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
import org.eclipse.team.ui.synchronize.SyncInfoDiffNodeRoot;
import org.eclipse.team.ui.synchronize.views.SyncInfoDiffNodeBuilder;

/**
 * It would be very useful to support showing changes grouped logically
 * instead of grouped physically. This could be used for showing incoming
 * changes and also for showing the results of comparisons.
 * 
 * Some problems with this:
 * 1. you have to fetch the log entries to extract useful information by
 * which to classify changes. this is expensive and can't be done in the
 * ui thread.
 * 
 * 2. how to support logical groupins based on any of the information in
 * the log entry?
 */
public class ChangeLogDiffNodeBuilder extends SyncInfoDiffNodeBuilder {
	
	private Map commentRoots = new HashMap();
	
	public ChangeLogDiffNodeBuilder(SyncInfoDiffNodeRoot root) {
		super(root);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.team.ui.synchronize.views.SyncInfoDiffNodeBuilder#buildTree(org.eclipse.compare.structuremergeviewer.DiffNode)
	 */
	protected IDiffElement[] buildTree(DiffNode node) {
		if(node == getRoot()) {
			DiffNode[] nodes = calculateRoots(getRoot().getSyncInfoSet());
			for (int i = 0; i < nodes.length; i++) {
				super.buildTree(nodes[i]);				
			}
		} else {
			return super.buildTree(node);
		}
		return new IDiffElement[0];
	}

	private DiffNode[] calculateRoots(SyncInfoSet set) {
		commentRoots.clear();
		SyncInfo[] infos = set.members();
		for (int i = 0; i < infos.length; i++) {
			ILogEntry logEntry = getSyncInfoComment((CVSSyncInfo) infos[i]);
			if(logEntry != null) {
				String comment = logEntry.getComment();
				ChangeLogDiffNode changeRoot = (ChangeLogDiffNode) commentRoots.get(comment);
				if (changeRoot == null) {
					changeRoot = new ChangeLogDiffNode(getRoot(), logEntry);
					commentRoots.put(comment, changeRoot);
				}
				changeRoot.add(infos[i]);
			}
		}		
		return (ChangeLogDiffNode[]) commentRoots.values().toArray(new ChangeLogDiffNode[commentRoots.size()]);
	}
	
	private ILogEntry getSyncInfoComment(CVSSyncInfo info) {
		try {
			ICVSRemoteResource remote = (ICVSRemoteResource)info.getRemote();
			if(remote instanceof RemoteFile) {
				return ((RemoteFile)remote).getLogEntry(new NullProgressMonitor());
			}
			return null;
		} catch (CVSException e) {
			CVSUIPlugin.getPlugin().log(e);
			return null;
		}
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.team.ui.synchronize.views.SyncInfoDiffNodeBuilder#syncSetChanged(org.eclipse.team.core.subscribers.ISyncInfoSetChangeEvent)
	 */
	protected void syncSetChanged(ISyncInfoSetChangeEvent event) {
		reset();
	}
}

Back to the top