Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 098840ced2485854945258811afa448a8b2267fa (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
107
108
/*******************************************************************************
 * Copyright (c) 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.viewers.*;
import org.eclipse.swt.graphics.*;

class MultiLabelDecorator extends LabelProvider implements ILabelDecorator, IFontDecorator, IColorDecorator {
	private ILabelDecorator[] decorators;

	public MultiLabelDecorator(ILabelDecorator[] decorators) {
		this.decorators = decorators;
	}

	/* (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) {
		for (int i = 0; i < decorators.length; i++) {
			ILabelDecorator decorator = decorators[i];
			Image newImage = decorator.decorateImage(image, element);
			if (newImage != null) {
				image = newImage;
			}
		}
		return image;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ILabelDecorator#decorateText(java.lang.String, java.lang.Object)
	 */
	@Override
	public String decorateText(String text, Object element) {
		for (int i = 0; i < decorators.length; i++) {
			ILabelDecorator decorator = decorators[i];
			String newText = decorator.decorateText(text, element);
			if (newText != null) {
				text = newText;
			}
		}
		return text;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
	 */
	@Override
	public void dispose() {
		for (int i = 0; i < decorators.length; i++) {
			ILabelDecorator d = decorators[i];
			d.dispose();
		}
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.IFontDecorator#decorateFont(java.lang.Object)
	 */
	@Override
	public Font decorateFont(Object element) {
		for (int i = 0; i < decorators.length; i++) {
			ILabelDecorator decorator = decorators[i];
			if(decorator instanceof IFontDecorator) {
				return ((IFontDecorator)decorator).decorateFont(element);
			}
		}
		return null;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.IColorDecorator#decorateForeground(java.lang.Object)
	 */
	@Override
	public Color decorateForeground(Object element) {
		for (int i = 0; i < decorators.length; i++) {
			ILabelDecorator decorator = decorators[i];
			if(decorator instanceof IColorDecorator) {
				return ((IColorDecorator)decorator).decorateForeground(element);
			}
		}
		return null;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.IColorDecorator#decorateBackground(java.lang.Object)
	 */
	@Override
	public Color decorateBackground(Object element) {
		for (int i = 0; i < decorators.length; i++) {
			ILabelDecorator decorator = decorators[i];
			if(decorator instanceof IColorDecorator) {
				return ((IColorDecorator)decorator).decorateBackground(element);
			}
		}
		return null;
	}
}

Back to the top