RAP 2.3 - keeping selected value on ComboViewer [message #1421372] |
Thu, 11 September 2014 09:21 |
Christian Wrobel Messages: 5 Registered: July 2013 |
Junior Member |
|
|
Hello everyone,
i have an problem with eclipse rap 2.3 and comboviewer.
When a value is selected in my combobox and the content of these combo is changed i like to keep the old selection if the new values contains the old selected item.
here my example code:
i create an combo:
final ComboViewer viewer = new ComboViewer(parent, SWT.NONE);
viewer.setContentProvider(new ArrayContentProvider());
for demonstrating this example i created two buttons:
Button btnObj = new Button(parent, SWT.NONE);
btnObj.setText("change input");
btnObj.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String[] itemsArr = new String[] {"a", "b", "c", "d", "e" };
String oldValue = viewer.getCombo().getText();
viewer.setInput(Arrays.asList(itemsArr));
for(String strObj : viewer.getCombo().getItems()) {
if(strObj.equals(oldValue)) {
viewer.getCombo().setText(oldValue);
}
}
System.out.println("viewer.getCombo().getSelectionIndex() " + viewer.getCombo().getSelectionIndex());
System.out.println("viewer.getCombo().getText() " + viewer.getCombo().getText());
}
});
Button btn2Obj = new Button(parent, SWT.NONE);
btn2Obj.setText("change input 2");
btn2Obj.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String[] itemsArr = new String[] {"a", "b", "c", "d", "e", "f" };
String oldValue = viewer.getCombo().getText();
viewer.setInput(Arrays.asList(itemsArr));
for(String strObj : viewer.getCombo().getItems()) {
if(strObj.equals(oldValue)) {
viewer.getCombo().setText(oldValue);
}
}
System.out.println("viewer.getCombo().getSelectionIndex() " + viewer.getCombo().getSelectionIndex());
System.out.println("viewer.getCombo().getText() " + viewer.getCombo().getText());
}
});
now when i run this code and push button 'change input' it fills my combo with that list of data. After when i select one item, for example 'c', and press this button again the value in my combo is 'c'.
Now when i push the second button 'change input 2' it fills the second list in my combo, but there is no item selected. The console prints the following:
viewer.getCombo().getSelectionIndex() -1
viewer.getCombo().getText()
viewer.getCombo().getSelectionIndex() 2
viewer.getCombo().getText() c
viewer.getCombo().getSelectionIndex() 2
viewer.getCombo().getText() c
so it seems that the value 'c' is still selected, but in the ui there ist nothing selected. This problem only occurs when the content lengt of the combo list changes. For example when the second buttons loads the items "e", "d", "c", "b", "a" into the combo it works, that means when i select for example 'b' and press both buttons it keeps that selection in the ui.
Can anybody tell my what's wrong with my code?
Best regards
Christian Wrobel
|
|
|
|
Re: RAP 2.3 - keeping selected value on ComboViewer [message #1435466 is a reply to message #1424038] |
Wed, 01 October 2014 14:34 |
Christian Wrobel Messages: 5 Registered: July 2013 |
Junior Member |
|
|
Hi Ivan,
thanks for your reply.
i was testing my code snippet with RCP, here it's working so i think that there is an bug with RAP. I watched bugzilla and saw that there is an similar bug (Bug 444128) which is already fixed, so i think that my issue should be solved, too.
So i would be happy to use this solution with RAP, based on version 2.3. Are there any patch releases planned in future (before RAP 3.0) ?
Best Regards
Christian Wrobel
[Updated on: Wed, 01 October 2014 14:35] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.04012 seconds