KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > viewers > TableColumnViewerLabelProvider


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  * Tom Shindl <tom.schindl@bestsolution.at> - initial API and implementation
11  *******************************************************************************/

12
13 package org.eclipse.jface.viewers;
14
15
16 /**
17  * TableColumnViewerLabelProvider is the mapping from the table based providers
18  * to the ViewerLabelProvider.
19  *
20  * @since 3.3
21  * @see ITableLabelProvider
22  * @see ITableColorProvider
23  * @see ITableFontProvider
24  *
25  */

26 class TableColumnViewerLabelProvider extends WrappedViewerLabelProvider {
27
28     private ITableLabelProvider tableLabelProvider;
29
30     private ITableColorProvider tableColorProvider;
31
32     private ITableFontProvider tableFontProvider;
33
34     /**
35      * Create a new instance of the receiver.
36      *
37      * @param labelProvider
38      * instance of a table based label provider
39      * @see ITableLabelProvider
40      * @see ITableColorProvider
41      * @see ITableFontProvider
42      */

43     public TableColumnViewerLabelProvider(IBaseLabelProvider labelProvider) {
44         super(labelProvider);
45
46         if (labelProvider instanceof ITableLabelProvider)
47             tableLabelProvider = (ITableLabelProvider) labelProvider;
48
49         if (labelProvider instanceof ITableColorProvider)
50             tableColorProvider = (ITableColorProvider) labelProvider;
51
52         if (labelProvider instanceof ITableFontProvider)
53             tableFontProvider = (ITableFontProvider) labelProvider;
54     }
55
56
57
58     /* (non-Javadoc)
59      * @see org.eclipse.jface.viewers.WrappedViewerLabelProvider#update(org.eclipse.jface.viewers.ViewerCell)
60      */

61     public void update(ViewerCell cell) {
62
63         Object JavaDoc element = cell.getElement();
64         int index = cell.getColumnIndex();
65
66         if (tableLabelProvider == null) {
67             cell.setText(getLabelProvider().getText(element));
68             cell.setImage(getLabelProvider().getImage(element));
69         } else {
70             cell.setText(tableLabelProvider.getColumnText(element, index));
71             cell.setImage(tableLabelProvider.getColumnImage(element, index));
72         }
73
74         if (tableColorProvider == null) {
75             if (getColorProvider() != null) {
76                 cell.setBackground(getColorProvider().getBackground(element));
77                 cell.setForeground(getColorProvider().getForeground(element));
78             }
79
80         } else {
81             cell.setBackground(tableColorProvider
82                     .getBackground(element, index));
83             cell.setForeground(tableColorProvider
84                     .getForeground(element, index));
85
86         }
87
88         if (tableFontProvider == null) {
89             if (getFontProvider() != null)
90                 cell.setFont(getFontProvider().getFont(element));
91         } else
92             cell.setFont(tableFontProvider.getFont(element, index));
93
94     }
95
96
97 }
98
Popular Tags