Skip to main content
summaryrefslogtreecommitdiffstats
blob: 8801ebc3ccf40127739accfbbcda2960d70f600f (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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*******************************************************************************
 * Copyright (c) 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.debug.internal.ui.viewers.model;

import org.eclipse.debug.internal.ui.commands.actions.AbstractRequestMonitor;
import org.eclipse.debug.internal.ui.viewers.model.provisional.ILabelUpdate;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.TreeItem;

/**
 * @since 3.3
 */
class LabelUpdate extends AbstractRequestMonitor implements ILabelUpdate {
	
	private TreePath fElementPath;
	private String[] fColumnIds;
	private RGB[] fBackgrounds;
	private RGB[] fForegrounds;
	private ImageDescriptor[] fImageDescriptors;
	private String[] fLabels;
	private FontData[] fFontDatas;
	private TreeModelLabelProvider fProvider;
	private TreeItem fItem;
	private int fNumColumns; 
	
	/**
	 * Label/Image cache keys
	 * TODO: workaround for bug 159461
	 */
	static String PREV_LABEL_KEY = "PREV_LABEL_KEY"; //$NON-NLS-1$
	static String PREV_IMAGE_KEY = "PREV_IMAGE_KEY"; //$NON-NLS-1$
	
	/**
	 * @param element element the label is for
	 * @param provider label provider to callback to 
	 * @param columnId column identifier or <code>null</code>
	 */
	public LabelUpdate(TreePath elementPath, TreeItem item, TreeModelLabelProvider provider, String[] columnIds) {
		fElementPath = elementPath;
		fProvider = provider;
		fColumnIds = columnIds;
		fItem = item;
		fNumColumns = 1;
		if (columnIds != null) {
			fNumColumns = columnIds.length;
		}
		fLabels = new String[fNumColumns];
		fProvider.updateStarted(this);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.debug.internal.ui.viewers.model.provisional.ILabelUpdate#getColumnIds()
	 */
	public String[] getColumnIds() {
		return fColumnIds;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.debug.internal.ui.viewers.model.provisional.ILabelUpdate#getElement()
	 */
	public TreePath getElementPath() {
		return fElementPath;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.debug.internal.ui.viewers.model.provisional.ILabelUpdate#setBackground(org.eclipse.swt.graphics.RGB, int)
	 */
	public void setBackground(RGB background, int columnIndex) {
		if (background == null) {
			return;
		}
		if (fBackgrounds == null) {
			fBackgrounds = new RGB[fNumColumns];
		}
		fBackgrounds[columnIndex] = background;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.debug.internal.ui.viewers.model.provisional.ILabelUpdate#setFontData(org.eclipse.swt.graphics.FontData, int)
	 */
	public void setFontData(FontData fontData, int columnIndex) {
		if (fontData == null) {
			return;
		}
		if (fFontDatas == null) {
			fFontDatas = new FontData[fNumColumns];
		}
		fFontDatas[columnIndex] = fontData;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.debug.internal.ui.viewers.model.provisional.ILabelUpdate#setForeground(org.eclipse.swt.graphics.RGB, int)
	 */
	public void setForeground(RGB foreground, int columnIndex) {
		if (foreground == null) {
			return;
		}
		if (fForegrounds == null) {
			fForegrounds = new RGB[fNumColumns];
		}
		fForegrounds[columnIndex] = foreground;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.debug.internal.ui.viewers.model.provisional.ILabelUpdate#setImageDescriptor(org.eclipse.jface.resource.ImageDescriptor, int)
	 */
	public void setImageDescriptor(ImageDescriptor image, int columnIndex) {
		if (image == null) {
			return;
		}
		if (fImageDescriptors == null) {
			fImageDescriptors = new ImageDescriptor[fNumColumns];
		}
		fImageDescriptors[columnIndex] = image;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.debug.internal.ui.viewers.model.provisional.ILabelUpdate#setLabel(java.lang.String, int)
	 */
	public void setLabel(String text, int columnIndex) {
		fLabels[columnIndex] = text;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate#getPresentationContext()
	 */
	public IPresentationContext getPresentationContext() {
		return fProvider.getPresentationContext();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.core.runtime.IProgressMonitor#done()
	 */
	public void done() {
		fProvider.complete(this);
	}

	/**
	 * Applies settings to viewer cell
	 */
	public void update() {
		if (!fItem.isDisposed()) {
			if (fColumnIds == null) {
				fItem.setText(fLabels[0]);
			} else {
				fItem.setText(fLabels);
			}
			fItem.setData(PREV_LABEL_KEY, fLabels);
			if (fImageDescriptors == null) {
				fItem.setImage((Image)null);
				fItem.setData(PREV_IMAGE_KEY, null); // TODO: bug 159461
			} else {
				if (fImageDescriptors == null) {
					fItem.setImage((Image)null);
					fItem.setData(PREV_IMAGE_KEY, null);
				} else {
					Image[] images = new Image[fImageDescriptors.length];
					for (int i = 0; i < fImageDescriptors.length; i++) {
						images[i] = fProvider.getImage(fImageDescriptors[i]);
					}
					if (fColumnIds == null) {
						fItem.setImage(images[0]);
					} else {
						fItem.setImage(images);
					}
					fItem.setData(PREV_IMAGE_KEY, images); // TODO: bug 159461
				}
			}
			if (fForegrounds == null) {
				fItem.setForeground((Color)null);
			} else {
				if (fColumnIds == null) {
					fItem.setForeground(fProvider.getColor(fForegrounds[0]));
				} else {
					for (int i = 0; i< fForegrounds.length; i++) {
						fItem.setForeground(i, fProvider.getColor(fForegrounds[i]));
					}
				}
			}
			if (fBackgrounds == null) {
				fItem.setBackground((Color)null);
			} else {
				if (fColumnIds == null) {
					fItem.setBackground(fProvider.getColor(fBackgrounds[0]));
				} else {
					for (int i = 0; i< fBackgrounds.length; i++) {
						fItem.setBackground(i, fProvider.getColor(fBackgrounds[i]));
					}
				}
			}
			if (fFontDatas == null) {
				fItem.setFont((Font)null);
			} else {
				if (fColumnIds == null) {
					fItem.setFont(fProvider.getFont(fFontDatas[0]));
				} else {
					for (int i = 0; i < fFontDatas.length; i++) {
						fItem.setFont(i, fProvider.getFont(fFontDatas[i]));
					}
				}
			}
		}
		fProvider.updateComplete(this);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate#getElement(org.eclipse.jface.viewers.TreePath)
	 */
	public Object getElement(TreePath path) {
		// TODO Auto-generated method stub
		return null;
	}
	
}

Back to the top