Use of label provider

Source: Internet
Author: User

Sigh! Continue with the book.

Today we will discuss the label provider of tableviewer.

For the label provider of tableviewer, according to the eclipse source code, as long as it is a class that implements the ibaselabelprovider interface, but in fact the label provider of tableviewer must be a class that implements the itablelabelprovider or ilabelprovider interface, if we want to customize the font or color of the table in addition to the label, we also need to implement itablefontprovider, itablecolorprovider, icolorprovider, and ifontprovider;

For treeviewer, it is the same as tableviewer according to the eclipse source code. In this way, as long as we understand the label provider of tableviewer, The treeviewer can be solved, because the custom label provider must be a class that implements the itablelabelprovider or ilabelprovider interface;

In this case, what are the differences between the two interfaces? The difference between them is that if we implement the itablelabelprovider interface, it will provide label text and images for each column and should be used together with itablefontprovider and itablecolorprovider when necessary; if we implement the ilabelprovider interface, it only provides label text and images for the first column, and must be used with icolorprovider and ifontprovider;

For listviewer, it is simpler. Its label provider only needs to implement ilabelprovider. Of course, to process fonts and colors, it can also implement icolorprovider and ifontprovider;

 

Well, let's see what these interfaces look like.

First: ilabelprovider, which provides two functions:
1. Public Image getimage (object element); this function is used to obtain the image of the first column;
2. Public String gettext (object element); similarly, this function is used to obtain the text description of the first column;

 

Second: itablelabelprovider. This interface also provides two functions:
1. Public Image getcolumnimage (object element, int columnindex); this function is used to obtain the image of the column specified by columnindex and the position of the row specified by the element;
2. Public String getcolumntext (object element, int columnindex); needless to say;But remember that columnindex is "zero-based!

 

Third: icolorprovider. This interface also provides two functions:
1. Color getforeground (object element); needless to say;
2. Color getbackground (object element); Haha, it's really the same;

 

Fourth: itablecolorprovider. This interface also provides two functions:
1. Color getforeground (object element, int columnindex); check the preceding description;
2. Color getbackground (object element, int columnindex); Same as above;

 

Fifth: ifontprovider, which provides only one function:
1. Public font getfont (object element); are you still using it?

 

Sixth: itablefontprovider. This interface also provides a function:
1. Public font getfont (object element, int columnindex); I won't talk about it anymore;

 

Again:

In eclipse, three important viewers actually use the same two sets of items in label provider. One set is the label, Font, and color provider with table, and the other one does not contain table; the former can be used to process different columns in more detail, while the latter only takes effect for the first column. Check your personal interests and use them as needed!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.