Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 7316189744de6f636513a7644327e8d6d835d8e9 (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
100
101
102
103
104
105
106
/*******************************************************************************
 * Copyright (c) 2000, 2003 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.internal.ccvs.ui.subscriber;

import org.eclipse.core.resources.IResource;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.*;
import org.eclipse.swt.graphics.Image;
import org.eclipse.team.internal.ccvs.ui.CVSLightweightDecorator;
import org.eclipse.team.ui.synchronize.*;
import org.eclipse.team.ui.synchronize.views.SyncInfoLabelProvider;

public class CVSSynchronizeViewCompareConfiguration extends TeamSubscriberPageDiffTreeViewerConfiguration {

	private boolean isGroupIncomingByComment = false;

	private static class CVSLabelDecorator extends LabelProvider implements ILabelDecorator  {
		public String decorateText(String input, Object element) {
			String text = input;
			if (element instanceof SyncInfoDiffNode) {
				IResource resource =  ((SyncInfoDiffNode)element).getResource();
				if(resource != null) {
					CVSLightweightDecorator.Decoration decoration = new CVSLightweightDecorator.Decoration();
					CVSLightweightDecorator.decorateTextLabel(resource, decoration, false, true);
					StringBuffer output = new StringBuffer(25);
					if(decoration.prefix != null) {
						output.append(decoration.prefix);
					}
					output.append(text);
					if(decoration.suffix != null) {
						output.append(decoration.suffix);
					}
					return output.toString();
				}
			} else if(element instanceof ChangeLogDiffNode) {
				return ((ChangeLogDiffNode)element).getComment();
			}
			return text;
		}
		public Image decorateImage(Image base, Object element) {
			return base;
		}
	}
	
	public CVSSynchronizeViewCompareConfiguration(ISynchronizeView view, TeamSubscriberParticipant participant) {
		super(view, participant);
		participant.addPropertyChangeListener(this);
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.team.ui.synchronize.DiffTreeViewerConfiguration#getLabelProvider()
	 */
	protected ILabelProvider getLabelProvider() {
		return new SyncInfoLabelProvider.DecoratingColorLabelProvider(new SyncInfoLabelProvider(), new CVSLabelDecorator());
	}
	
	public boolean isGroupIncomingByComment() {
		return isGroupIncomingByComment;
	}
	
	public void setGroupIncomingByComment(boolean enabled) {
		this.isGroupIncomingByComment = enabled;
		if(getParticipant().getMode() == TeamSubscriberParticipant.INCOMING_MODE) {
			setInput(getViewer());
		}
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.team.ui.synchronize.DiffTreeViewerConfiguration#getInput()
	 */
	protected SyncInfoDiffNodeRoot getInput() {
		if(isGroupIncomingByComment() && getParticipant().getMode() == TeamSubscriberParticipant.INCOMING_MODE) {
			return new ChangeLogDiffNodeRoot(getSyncSet());
		} else {
			return super.getInput();
		}
	}
	
	/* (non-Javadoc)
	 * @see org.eclipse.team.ui.synchronize.DiffTreeViewerConfiguration#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
	 */
	public void propertyChange(PropertyChangeEvent event) {
		String property = event.getProperty();
		if(property.equals(TeamSubscriberParticipant.P_SYNCVIEWPAGE_MODE) && isGroupIncomingByComment()) {
			int oldMode = ((Integer)event.getOldValue()).intValue();
			int newMode = ((Integer)event.getNewValue()).intValue();
			if(newMode == TeamSubscriberParticipant.INCOMING_MODE || 
			   oldMode == TeamSubscriberParticipant.INCOMING_MODE) {
				aSyncExec(new Runnable() {
					public void run() {
						setInput(getViewer());
					}
				});				
			}
		}
		super.propertyChange(event);
	}
}

Back to the top