Skip to main content


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: 78
Registered: May 2013
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 231 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: 2426
Registered: July 2009
Location: Sofia, Bulgaria
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: 78
Registered: May 2013
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: 28
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: 78
Registered: May 2013
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:[ANN] RAP 2.1.2 is available
Next Topic:ComboViewer - selections cannot show icons
Goto Forum:
  


Current Time: Fri Apr 26 12:32:35 GMT 2024

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

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

Back to the top