Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: aa257a58b57da9cf658046e27b660e44db021f5b (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
/*******************************************************************************
 * Copyright (c) 2000, 2006 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.internal.ui.synchronize;

import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.IFontDecorator;
import org.eclipse.jface.viewers.ILabelDecorator;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Image;
import org.eclipse.team.internal.core.subscribers.ActiveChangeSet;
import org.eclipse.team.internal.core.subscribers.ActiveChangeSetManager;
import org.eclipse.team.internal.core.subscribers.ChangeSet;
import org.eclipse.team.internal.ui.TeamUIMessages;
import org.eclipse.team.internal.ui.TeamUIPlugin;
import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
import org.eclipse.team.ui.synchronize.ISynchronizeParticipant;

/**
 * Label decorator that decorates the default active change set.
 */
public class ChangeSetLabelDecorator extends LabelProvider implements ILabelDecorator, IFontDecorator{

	private Font boldFont;
	private ActiveChangeSetManager collector;

    public ChangeSetLabelDecorator(ISynchronizePageConfiguration configuration) {
        ISynchronizeParticipant participant = configuration.getParticipant();
        if (participant instanceof IChangeSetProvider) {
            this.collector = ((IChangeSetProvider)participant).getChangeSetCapability().getActiveChangeSetManager();
        }
    }

    @Override
	public String decorateText(String input, Object element) {
		String text = input;
		if (element instanceof ChangeSetDiffNode) {
		    ChangeSet set = ((ChangeSetDiffNode)element).getSet();
		    if (set instanceof ActiveChangeSet && isDefaultActiveSet((ActiveChangeSet)set)) {
		        text = NLS.bind(TeamUIMessages.CommitSetDiffNode_0, new String[] { text });
		    }
		}
		return text;
	}

	@Override
	public void dispose() {
		if(boldFont != null) {
			boldFont.dispose();
		}
	}

	@Override
	public Font decorateFont(Object element) {
		if (element instanceof ChangeSetDiffNode) {
		    ChangeSet set = ((ChangeSetDiffNode)element).getSet();
		    if (set instanceof ActiveChangeSet && isDefaultActiveSet((ActiveChangeSet)set)) {
		    	if (boldFont == null) {
					Font defaultFont = JFaceResources.getDefaultFont();
					FontData[] data = defaultFont.getFontData();
					for (int i = 0; i < data.length; i++) {
						data[i].setStyle(SWT.BOLD);
					}
					boldFont = new Font(TeamUIPlugin.getStandardDisplay(), data);
				}
				return boldFont;
		    }
		}
		return null;
	}

	private boolean isDefaultActiveSet(ActiveChangeSet set) {
	    return collector.isDefault(set);
	}

    /* (non-Javadoc)
     * @see org.eclipse.jface.viewers.ILabelDecorator#decorateImage(org.eclipse.swt.graphics.Image, java.lang.Object)
     */
    @Override
	public Image decorateImage(Image image, Object element) {
        return image;
    }

}

Back to the top