Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » ComboViewer - flag icons cannot appear(ComboViewer - flags & country(language))
ComboViewer - flag icons cannot appear [message #1261027] Sun, 02 March 2014 05:13 Go to next message
David Lee is currently offline David LeeFriend
Messages: 26
Registered: May 2013
Junior Member
I tried showing images in TableViewer and TreeViewer by using like getImage() function in LabelProvider, all works very well!

I'd like to implement a Combo with flags/languages just like the picture in "Shadows" paragraph of http://www.eclipse.org/rap/noteworthy/1.4/

I tried ComboViewer, the getText() of LabelProvider works well, but the getImage() does not work at all, it cannot show the flag icons! the code is as below, can someone please let me know why?! Thank you!

// where compComboViewer is a Composite container
final Image flagAmerica = SysIcon.loadImage("icon/America.png");
final Image flagChina = SysIcon.loadImage("icon/Canada.png");

// to test if 16x16 icon flagAmerica works, and the answer is YES
Label label = new Label(compComboViewer, SWT.NONE);
label.setImage(flagAmerica);

final ComboViewer cboLocale = new ComboViewer(compComboViewer, SWT.READ_ONLY);
cboLocale.setContentProvider(ArrayContentProvider.getInstance());
cboLocale.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
Country country = (Country) element;
return country.getCountryName();
}
@Override
public Image getImage(Object element) {
Image imgFlag = null;
Country country = (Country) element;
switch ( country.getCountryName() ) {
case "America":
imgFlag = flagAmerica;
break;
case "Canada":
imgFlag = flagCanada;
break;
}
return imgFlag;
}
});
Country[] countries = new Country[]{ new Country("America"), new Country("Canada") };
cboLocale.setInput(countries);

private class Country {
private String countryName;
public Country(String countryName) {
this.countryName = countryName;
}
public String getCountryName() { return this.countryName; }
public void setCountryName(String countryName) { this.countryName = countryName; }
}
  • Attachment: Shadows.png
    (Size: 17.52KB, Downloaded 30 times)
Re: ComboViewer - flag icons cannot appear [message #1261180 is a reply to message #1261027] Sun, 02 March 2014 09:17 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 1853
Registered: July 2009
Senior Member
Hi,
you can't implement this with Combo as it does not support images (both
in SWT and RAP). You need ToolBar and drop-down tool item
See: http://rap.eclipsesource.com/demo/release/rapdemo/examples#nls
Source code:
http://git.eclipse.org/c/rap/org.eclipse.rap.git/tree/examples/org.eclipse.rap.examples.pages/src/org/eclipse/rap/examples/pages/InternationalizationExamplePage.java
HTH,
Ivan

--
Ivan Furnadjiev

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: ComboViewer - flag icons cannot appear [message #1261227 is a reply to message #1261180] Sun, 02 March 2014 10:26 Go to previous messageGo to next message
David Lee is currently offline David LeeFriend
Messages: 26
Registered: May 2013
Junior Member
Thank Ivan so much! I'll follow your guide to implement that!

On the other hand, since the ComboViewer has no obvious difference from a Combo widget, what is it needed for? Or, what can the ComboViewer do?

[Updated on: Sun, 02 March 2014 10:27]

Report message to a moderator

Re: ComboViewer - flag icons cannot appear [message #1262328 is a reply to message #1261227] Mon, 03 March 2014 14:13 Go to previous messageGo to next message
Paul Bilnoski is currently offline Paul BilnoskiFriend
Messages: 24
Registered: August 2010
Junior Member
A ComboViewer offers an improved API over a Combo (or CCombo). The Viewer framework from JFace abstracts the specific mechanics of particular complex widgets (combo, tree, table, etc.) into common patterns such as content provder, label provider, and current selection. Look more into the JFace Viewers framework docs for more details.

In particular regarding ComboViewer. A Combo has this basic API:
* setItems(String[])
* select(int)
* getSelectionIndex():int
* getItem(int):String
* getText():String
* indexOf(String):int
This API operates on String elements by index. What you put in must be String and what you get out is the selection index or selected String value.

Whereas the ComboViewer has this basic API:
* setContentProvider(IContentProvider)
* setLabelProvider(IBaseLabelProvider)
* setInput(Object)
* getSelection():ISelection
* setComparator(Comparator)
You may set any Object as the input (typically a Collection) as long as the IContentProvider (use ArrayContentProvider for Collection) can turn your Object into a values with which to populate the viewer. Your objects are then passed through the label provider which is your implementation of adapting your objects to display strings. When you get the selection, you get your object instance back rather than a String or int index which you must map back into your data model. Also, sorting can be done within the viewer rather than sorting your input before providing it as input.

I rarely find need to use a Combo when I can use the improved ComboViewer API and my data models. Let the library do your model to display conversion rather than custom code per combo.

--Paul Bilnoski
Re: ComboViewer - flag icons cannot appear [message #1268261 is a reply to message #1262328] Mon, 10 March 2014 09:10 Go to previous message
David Lee is currently offline David LeeFriend
Messages: 26
Registered: May 2013
Junior Member
Hi, Paul,

Thank you for your reply!
Since getImage() works well in TableViewer and TreeViewer, that's the reason why I first considered ComboViewer for showing nation flags, and I never used ComboViewer before that!
Previous Topic:repository for dropdown widget no available
Next Topic:Event order on tree and table
Goto Forum:
  


Current Time: Thu Nov 20 21:01:56 GMT 2014

Powered by FUDForum. Page generated in 0.02876 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software