KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > schemas > view > views > TableDecoratingLabelProvider


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20 package org.apache.directory.ldapstudio.schemas.view.views;
21
22
23 import org.eclipse.jface.viewers.DecoratingLabelProvider;
24 import org.eclipse.jface.viewers.ILabelDecorator;
25 import org.eclipse.jface.viewers.ILabelProvider;
26 import org.eclipse.jface.viewers.ITableLabelProvider;
27 import org.eclipse.jface.viewers.LabelDecorator;
28 import org.eclipse.swt.graphics.Image;
29
30
31 /**
32  * Class that supports Decoration of TableViewer and TreeViewer with TreeColumns
33  *
34  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
35  * @version $Rev$, $Date$
36  */

37 public class TableDecoratingLabelProvider extends DecoratingLabelProvider implements ITableLabelProvider
38 {
39     ITableLabelProvider provider;
40     ILabelDecorator decorator;
41
42
43     /**
44      * @param provider
45      * @param decorator
46      */

47     public TableDecoratingLabelProvider( ILabelProvider provider, ILabelDecorator decorator )
48     {
49         super( provider, decorator );
50         this.provider = ( ITableLabelProvider ) provider;
51         this.decorator = decorator;
52     }
53
54
55     /* (non-Javadoc)
56      * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
57      */

58     public Image getColumnImage( Object JavaDoc element, int columnIndex )
59     {
60         Image image = provider.getColumnImage( element, columnIndex );
61         if ( decorator != null )
62         {
63             if ( decorator instanceof LabelDecorator )
64             {
65                 LabelDecorator ld2 = ( LabelDecorator ) decorator;
66                 Image decorated = ld2.decorateImage( image, element, getDecorationContext() );
67                 if ( decorated != null )
68                 {
69                     return decorated;
70                 }
71             }
72             else
73             {
74                 Image decorated = decorator.decorateImage( image, element );
75                 if ( decorated != null )
76                 {
77                     return decorated;
78                 }
79             }
80         }
81         return image;
82     }
83
84
85     /* (non-Javadoc)
86      * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
87      */

88     public String JavaDoc getColumnText( Object JavaDoc element, int columnIndex )
89     {
90         String JavaDoc text = provider.getColumnText( element, columnIndex );
91         if ( decorator != null )
92         {
93             if ( decorator instanceof LabelDecorator )
94             {
95                 LabelDecorator ld2 = ( LabelDecorator ) decorator;
96                 String JavaDoc decorated = ld2.decorateText( text, element, getDecorationContext() );
97                 if ( decorated != null )
98                 {
99                     return decorated;
100                 }
101             }
102             else
103             {
104                 String JavaDoc decorated = decorator.decorateText( text, element );
105                 if ( decorated != null )
106                 {
107                     return decorated;
108                 }
109             }
110         }
111         return text;
112     }
113 }
Popular Tags