Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 84b0479e7561cdbcf6168cf478d2f44364f5bdb8 (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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
/*******************************************************************************
 * Copyright (c) 2011 Wind River Systems, Inc. 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:
 * Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.tm.te.ui.swt;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Decorations;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Scrollable;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.ui.PlatformUI;

/**
 * Utility providing convenience methods for use with SWT controls.
 */
public final class SWTControlUtil {

	/**
	 * Returns the text from the specified control. The method will return <code>null</code>
	 * if the control is <code>null</code> or has been already disposed.
	 *
	 * @param control The control to get the text from.
	 * @param The text currently set to the control or <code>null</code>.
	 */
	public static final String getText(Control control) {
		if (control != null && !control.isDisposed()) {
			if (control instanceof Button) {
				return ((Button)control).getText().trim();
			}
			if (control instanceof Combo) {
				return ((Combo)control).getText().trim();
			}
			if (control instanceof Group) {
				return ((Group)control).getText().trim();
			}
			if (control instanceof Label) {
				return ((Label)control).getText().trim();
			}
			if (control instanceof Link) {
				return ((Link)control).getText().trim();
			}
			if (control instanceof Text) {
				return ((Text)control).getText().trim();
			}
			if (control instanceof Decorations) {
				return ((Decorations)control).getText();
			}
		}
		return null;
	}

	/**
	 * Sets the given text to the specified control. The text will be not applied if the
	 * control is <code>null</code> or has been already disposed or if the given text itself
	 * is <code>null</code>.
	 *
	 * @param control The control the given text should be applied to.
	 * @param value The text to apply to the given control.
	 */
	public static final void setText(Control control, String value) {
		if (control != null && !control.isDisposed() && value != null) {
			String trimmedValue = value.trim();

			// Avoid triggering attached listeners if the value has not changed.
			String oldValue = getText(control);
			if (!trimmedValue.equals(oldValue)) {
				if (control instanceof Button) {
					((Button)control).setText(trimmedValue);
				}
				if (control instanceof Combo) {
					((Combo)control).setText(trimmedValue);
				}
				if (control instanceof Group) {
					((Group)control).setText(trimmedValue);
				}
				if (control instanceof Label) {
					((Label)control).setText(trimmedValue);
				}
				if (control instanceof Link) {
					((Link)control).setText(trimmedValue);
				}
				if (control instanceof Text) {
					((Text)control).setText(trimmedValue);
				}
				if (control instanceof Decorations) {
					((Decorations)control).setText(trimmedValue);
				}
			}
		}
	}

	/**
	 * Sets the given text to the specified control as tooltip. The tooltip text will be not
	 * applied if the control is <code>null</code> or has been already disposed.
	 *
	 * @param control The control the given text should be applied to.
	 * @param value The text to apply to the given control or <code>null</code> to reset the tooltip.
	 */
	public static final void setToolTipText(Control control, String value) {
		if (control != null && !control.isDisposed()) {
			control.setToolTipText(value);
		}
	}

	/**
	 * Sets the text of the control (Text, Combo) as tooltip if the text is
	 * not fully visible.
	 * @param control The control to set the tooltip for.
	 */
	public static final void setValueToolTip(Scrollable control) {
		if (control != null && !control.isDisposed()) {
			String text = null;
			int resize = 0;
			if (control instanceof Text) {
				text = ((Text)control).getText().trim();
				resize = control.getBorderWidth() * 2;
			}
			if (control instanceof Combo) {
				text = ((Combo)control).getText().trim();
				resize = (int)(control.getSize().y * 1.5) + control.getBorderWidth() * 2;
			}
			if (text != null) {
				GC gc = new GC(control);
				int width = 0;
				for (int i = 0; i < text.length(); i++) {
					width += gc.getAdvanceWidth(text.charAt(i));
				}
				// Show the tooltip _only_ if the text itself exceeds
				// the length of the control (partially shown within the control).
				if (width > (control.getClientArea().width - resize)) {
					control.setToolTipText(text);
				} else {
					control.setToolTipText(null);
				}
				gc.dispose();
			}
		}
	}

	/**
	 * Adds the given text to the specified control. The given text will be added in case it's not
	 * <code>null</code> and not empty and if the given control itself is not <code>null</code>
	 * and not disposed. If the given text is already within the controls drop down list, the text
	 * will <i>not</i> be added again to the list.
	 *
	 * @param control The control to add the given text to.
	 * @param value The text to add to the control.
	 */
	public static final void add(Control control, String value) {
		add(control, value, false);
	}

	/**
	 * Adds the given text to the specified control. The given text will be added in case it's not
	 * <code>null</code> and not empty and if the given control itself is not <code>null</code>
	 * and not disposed. If the given text is already within the controls drop down list, the text
	 * will <i>not</i> be added again to the list.
	 *
	 * @param control The control to add the given text to.
	 * @param value The text to add to the control.
	 * @param allowEmpty If <code>true</code>, empty values will be added to the control. Otherwise,
	 *                   empty values will be filtered out and not applied to the control.
	 */
	public static final void add(Control control, String value, boolean allowEmpty) {
		if (control != null && !control.isDisposed() && value != null) {
			if (!allowEmpty  && value.trim().length() == 0) {
				return;
			}
			if (control instanceof Combo) {
				Combo combo = ((Combo)control);
				if (combo.indexOf(value) == -1) {
					combo.add(value);
				}
			}
			if (control instanceof List) {
				List list = ((List)control);
				if (list.indexOf(value) == -1) {
					list.add(value);
				}
			}
		}
	}

	/**
	 * Adds the given text to the specified control at the given index. If the given index is negative,
	 * the item index will be set to <code>0</code>. The given text will be added in case it's not
	 * <code>null</code> and not empty and if the given control itself is not <code>null</code>
	 * and not disposed. If the given text is already within the controls drop down list, the text will
	 * <i>not</i> be added again to the list.
	 *
	 * @param control The control to add the given text to.
	 * @param value The text to add to the control.
	 * @param index The index of the item to add to the control.
	 */
	public static final void add(Control control, String value, int index) {
		add(control, value, index, false);
	}

	/**
	 * Adds the given text to the specified control at the given index. If the given index is negative,
	 * the item index will be set to <code>0</code>. The given text will be added in case it's not
	 * <code>null</code> and not empty and if the given control itself is not <code>null</code>
	 * and not disposed. If the given text is already within the controls drop down list, the text will
	 * <i>not</i> be added again to the list.
	 *
	 * @param control The control to add the given text to.
	 * @param value The text to add to the control.
	 * @param index The index of the item to add to the control.
	 * @param allowEmpty If <code>true</code>, empty values will be added to the control. Otherwise,
	 *                   empty values will be filtered out and not applied to the control.
	 */
	public static final void add(Control control, String value, int index, boolean allowEmpty) {
		if (control != null && !control.isDisposed() && value != null) {
			if (!allowEmpty  && value.trim().length() == 0) {
				return;
			}
			if (control instanceof Combo) {
				Combo combo = ((Combo)control);
				if (combo.indexOf(value) == -1) {
					if (index < 0) {
						index = 0;
					}
					combo.add(value, index);
				}
			}
			if (control instanceof List) {
				List list = ((List)control);
				if (list.indexOf(value) == -1) {
					if (index < 0) {
						index = 0;
					}
					list.add(value, index);
				}
			}
		}
	}

	/**
	 * Sets the enabled state of the given control to the given state. The state will be
	 * applied in case the given control is not <code>null</code> and not disposed.
	 *
	 * @param control The control to set the enabled state for.
	 * @param enabled <code>true</code> to enable the control, <code>false</code> otherwise.
	 */
	public static final void setEnabled(Control control, boolean enabled) {
		if (control != null && !control.isDisposed()) {
			control.setEnabled(enabled);
		}
	}

	/**
	 * Returns the enabled state of the given control. The method returns always <code>true</code>
	 * in case the given control is <code>null</code> or disposed.
	 *
	 * @param control The control to get the enabled state for.
	 * @return <code>true</code> if the control is enabled, <code>false</code> otherwise.
	 */
	public static final boolean isEnabled(Control control) {
		if (control != null && !control.isDisposed()) {
			return control.isEnabled();
		}
		return true;
	}

	/**
	 * Sets the visible state of the given control. The state will be applied in
	 * case the given control is not <code>null</code> and not disposed.
	 *
	 * @param control The control to set the visible state for.
	 * @param visible <code>True</code> to set the control visible, <code>false</code> otherwise.
	 */
	public static final void setVisible(Control control, boolean visible) {
		if (control != null && !control.isDisposed()) {
			control.setVisible(visible);
		}
	}

	/**
	 * Returns the visible state of the given control. The method returns always
	 * <code>true</code> in case the given control is <code>null</code> or disposed.
	 *
	 * @param control The control to set the visible state for.
	 * @param visible <code>True</code> to set the control visible, <code>false</code> otherwise.
	 */
	public static final boolean isVisible(Control control) {
		if (control != null && !control.isDisposed()) {
			return control.getVisible();
		}
		return true;
	}

	/**
	 * Returns the item count of the specified control. The method will return <code>0</code>
	 * in case the control is <code>null</code> or has been already disposed or does not
	 * support items.
	 *
	 * @param control The control to get the item count for.
	 * @return The number of items within the control or <code>-1</code>.
	 */
	public static final int getItemCount(Control control) {
		if (control != null && !control.isDisposed()) {
			if (control instanceof Combo) {
				return ((Combo)control).getItemCount();
			}
			if (control instanceof List) {
				return ((List)control).getItemCount();
			}
		}
		return -1;
	}

	/**
	 * Sets the specified items to the specified control.
	 *
	 * @param control The control to set the items to.
	 * @param items The array of items to set.
	 */
	public static final void setItems(Control control, String[] items) {
		if (control != null && !control.isDisposed() && items != null) {
			if (control instanceof Combo) {
				((Combo)control).setItems(items);
			}
			else if (control instanceof List) {
				((List)control).setItems(items);
			}
		}
	}

	/**
	 * Returns the items of the specified control. The method will return an empty array
	 * in case the control is <code>null</code> or has been already disposed or does not
	 * support items.
	 *
	 * @param control The control to get the items from.
	 * @return The array items or and empty array.
	 */
	public static final String[] getItems(Control control) {
		if (control != null && !control.isDisposed()) {
			if (control instanceof Combo) {
				return ((Combo)control).getItems();
			}
			if (control instanceof List) {
				return ((List)control).getItems();
			}
		}
		return new String[0];
	}

	/**
	 * Sets the text of the specified item of the specified control.
	 *
	 * @param control The control to set the item text.
	 * @param index The index of the item to change.
	 * @param value The new item text to apply.
	 */
	public static final void setItem(Control control, int index, String value) {
		if (control != null && !control.isDisposed() && value != null) {
			// The index must be within valid range
			if (index >= 0 && index < getItemCount(control)) {
				String trimmedValue = value.trim();

				// Avoid triggering attached listeners if the value has not changed.
				String oldValue = getItem(control, index);
				if (!trimmedValue.equals(oldValue)) {
					if (control instanceof Combo) {
						((Combo)control).setItem(index, trimmedValue);
					}
					if (control instanceof List) {
						((List)control).setItem(index, trimmedValue);
					}
				}
			}
		}
	}

	/**
	 * Returns the text of the item at the specified index of the specified control.
	 *
	 * @param control The control to query the item text from.
	 * @param index The index of the item to query.
	 * @return The item text or <code>null</code>.
	 */
	public static final String getItem(Control control, int index) {
		if (control != null && !control.isDisposed()) {
			// The index must be within valid range
			if (index >= 0 && index < getItemCount(control)) {
				if (control instanceof Combo) {
					return ((Combo)control).getItem(index).trim();
				}
				if (control instanceof List) {
					return ((List)control).getItem(index).trim();
				}
			}
		}
		return null;
	}

	/**
	 * Returns the selected item index of the specified control. The method will return <code>-1</code> in case
	 * the control is <code>null</code> or has been already disposed or does not support selections.
	 *
	 * @param control The control to get the selected item index for.
	 * @return The index of the selected item within the control or <code>-1</code>.
	 */
	public static final int getSelectionIndex(Control control) {
		if (control != null && !control.isDisposed()) {
			if (control instanceof Combo) {
				return ((Combo)control).getSelectionIndex();
			}
			if (control instanceof List) {
				return ((List)control).getSelectionIndex();
			}
			if (control instanceof Table) {
				return ((Table)control).getSelectionIndex();
			}
		}
		return -1;
	}

	/**
	 * Returns the selected item count of the specified control. The method will return <code>-1</code> in case
	 * the control is <code>null</code> or has been already disposed or does not support selections.
	 *
	 * @param control The control to get the selected item count for.
	 * @return The number of selected items within the control or <code>-1</code>.
	 */
	public static final int getSelectionCount(Control control) {
		if (control != null && !control.isDisposed()) {
			if (control instanceof List) {
				return ((List)control).getSelectionCount();
			}
			if (control instanceof Table) {
				return ((Table)control).getSelectionCount();
			}
			if (control instanceof Tree) {
				return ((Tree)control).getSelectionCount();
			}
		}
		return -1;
	}

	/**
	 * Removes all items of the specified control.
	 *
	 * @param control The control to remove all items from.
	 */
	public static final void removeAll(Control control) {
		if (control != null && !control.isDisposed()) {
			if (control instanceof Combo) {
				((Combo)control).removeAll();
			}
			if (control instanceof List) {
				((List)control).removeAll();
			}
			if (control instanceof Table) {
				((Table)control).removeAll();
			}
			if (control instanceof Tree) {
				((Tree)control).removeAll();
			}
		}
	}

	/**
	 * Returns the index of the given item for the specified control. The method will return
	 * <code>-1</code> in case the control is <code>null</code> or has been already disposed
	 * or does not support items.
	 *
	 * @param control The control to lookup the item index.
	 * @param item The item to lookup the index for.
	 * @return The item index if found or <code>-1</code>.
	 */
	public static final int indexOf(Control control, String item) {
		if (control != null && !control.isDisposed() && item != null) {
			if (control instanceof Combo) {
				return ((Combo)control).indexOf(item);
			}
			if (control instanceof List) {
				return ((List)control).indexOf(item);
			}
		}
		return -1;
	}

	/**
	 * Selects the item with the given item index for the specified control. The method will
	 * return immediately in case the control is <code>null</code> or has been already
	 * disposed or does not support items.
	 *
	 * @param control The control to select the given item.
	 * @param item The item to select.
	 */
	public static final void select(Control control, int index) {
		if (control != null && !control.isDisposed()) {
			if (index >= 0 && index < getItemCount(control)) {
				if (control instanceof Combo) {
					((Combo)control).select(index);
				}
				if (control instanceof List) {
					((List)control).select(index);
				}
			}
		}
		return;
	}

	/**
	 * Returns the buttons selection state.
	 *
	 * @param button The button to query the selection state for.
	 * @return <code>true</code> if the button specified is not <code>null</code> nor disposed and selected, <code>false</code> otherwise.
	 */
	public static final boolean getSelection(Button button) {
		if (button != null && !button.isDisposed()) {
			return button.getSelection();
		}
		return false;
	}

	/**
	 * Sets the buttons selection state to the given state.
	 *
	 * @param button The button to set the selection state for.
	 * @param selected The button selection state to set.
	 */
	public static final void setSelection(Button button, boolean selected) {
		if (button != null && !button.isDisposed()) {
			button.setSelection(selected);
		}
	}

	/**
	 * Returns the number of pixels corresponding to the height of the given
	 * number of characters.
	 * <p>
	 * This methods uses the static {@link Dialog#convertHeightInCharsToPixels(org.eclipse.swt.graphics.FontMetrics, int)}
	 * method for calculation.
	 * <p>
	 * @param chars The number of characters
	 * @return The corresponding height in pixels
	 */
	public static int convertHeightInCharsToPixels(Control control, int chars) {
		int height = 0;
		if (control != null && !control.isDisposed()) {
			GC gc = new GC(control);
			gc.setFont(JFaceResources.getDialogFont());
			height = Dialog.convertHeightInCharsToPixels(gc.getFontMetrics(), chars);
			gc.dispose();
		}

		return height;
	}

	/**
	 * Returns the number of pixels corresponding to the width of the given
	 * number of characters.
	 * <p>
	 * This methods uses the static {@link Dialog#convertWidthInCharsToPixels(org.eclipse.swt.graphics.FontMetrics, int)}
	 * method for calculation.
	 * <p>
	 * @param chars The number of characters
	 * @return The corresponding width in pixels
	 */
	public static int convertWidthInCharsToPixels(Control control, int chars) {
		int width = 0;
		if (control != null && !control.isDisposed()) {
			GC gc = new GC(control);
			gc.setFont(JFaceResources.getDialogFont());
			width = Dialog.convertWidthInCharsToPixels(gc.getFontMetrics(), chars);
			gc.dispose();
		}

		return width;
	}

	/**
	 * Sets the focus to the given control.
	 *
	 * @param control The control to set the focus to.
	 * @return <code>True</code> if the control got the focus, <code>false</code> otherwise.
	 */
	public static boolean setFocus(Control control) {
		if (control != null && !control.isDisposed()) {
			return control.setFocus();
		}
		return false;
	}

	/**
	 * Sets the given color as control foreground.
	 *
	 * @param control The control.
	 * @param color The color.
	 */
	public static void setForeground(Control control, Color color) {
		if (control != null && !control.isDisposed() && color != null) {
			control.setForeground(color);
		}
	}

	/**
	 * Sets the given color as control background.
	 *
	 * @param control The control.
	 * @param color The color.
	 */
	public static void setBackground(Control control, Color color) {
		if (control != null && !control.isDisposed() && color != null) {
			control.setBackground(color);
		}
	}

	/**
	 * Sets the given image as control background image.
	 *
	 * @param control The control.
	 * @param image The image.
	 */
	public static void setBackgroundImage(Control control, Image image) {
		if (control != null && !control.isDisposed() && image != null) {
			control.setBackgroundImage(image);
		}
	}

	/* --------------------------------------------------------------------
	 *
	 * Generate system specific checkbox images.
	 *
	 * -------------------------------------------------------------------- */

	private static final String CHECKED = "CHECKED"; //$NON-NLS-1$
	private static final String UNCHECKED = "UNCHECKED"; //$NON-NLS-1$
	private static final String GRAYED = "GRAYED"; //$NON-NLS-1$
	private static final String ENABLED = "ENABLED"; //$NON-NLS-1$
	private static final String DISABLED = "DISABLED"; //$NON-NLS-1$

	private static Image makeShot(Shell shell, boolean checked, boolean grayed, boolean enabled) {
		shell = new Shell(shell, SWT.NO_FOCUS | SWT.NO_TRIM);

		Color greenScreen = new Color(shell.getDisplay(), 222, 223, 224);
		shell.setBackground(greenScreen);

		Button button = new Button(shell, SWT.CHECK);
		button.setBackground(greenScreen);
		button.setSelection(grayed || checked);
		button.setEnabled(enabled);
		button.setGrayed(grayed);

		button.setLocation(0, 0);
		Point bsize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);

		button.setSize(bsize);
		shell.setSize(bsize);

		shell.open();
		GC gc = new GC(shell);
		Image image = new Image(shell.getDisplay(), bsize.x, bsize.y);
		gc.copyArea(image, 0, 0);
		gc.dispose();

		ImageData imageData = image.getImageData();
		imageData.transparentPixel = imageData.palette.getPixel(greenScreen
			.getRGB());
		image = new Image(shell.getDisplay(), imageData);
		shell.close();

		return image;
	}

	public static synchronized Image getCheckBoxImage(boolean checked, boolean grayed, boolean enabled) {
		String key = (SWTControlUtil.class.getName() + "_" + //$NON-NLS-1$
			((checked || grayed) ? CHECKED : UNCHECKED) + "_" + //$NON-NLS-1$
			(grayed ? GRAYED + "_" : "") + //$NON-NLS-1$ //$NON-NLS-2$
			(enabled ? ENABLED : DISABLED));

		Image image = JFaceResources.getImageRegistry().get(key);
		try {
			if (image == null || image.getImageData().data == null) {
				Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
				image = makeShot(shell, checked||grayed, grayed, enabled);
				if (image != null && image.getImageData().data != null) {
					JFaceResources.getImageRegistry().put(key, image);
				}
			}
		}
		catch (Exception e) {
		}

		return image;
	}
}

Back to the top