Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Databinding for Combo behaves differently in 3.4
Databinding for Combo behaves differently in 3.4 [message #332436] Tue, 21 October 2008 17:54 Go to next message
Eclipse UserFriend
Originally posted by: alexm.xxx.yyy

This is a multi-part message in MIME format.
--------------020902080207080905020201
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

The change in behavior between Eclipse 3.3 and 3.4 is significant and
breaks the existing logic.

Here is what happens: a data model carries an array of String items
(colourScales) that populate the Combo's drop-down list, and a single
String (colorScale) to track its selection.


When the data model is bound to a Combo box, as below

Combo colorScale = ...
DataBindingContext dbc = ...
dbc.bindList(SWTObservables.observeItems(colorScale),
BeansObservables.observeList(Realm.getDefault(), dataModel,
"colourScales"), null, null);

the Combo fires a text-change event, setting the model's colorScale
property to a blank value, and corrupting it as the result.

In Eclipse 3.3, binding a Combo to an array of String items did not
trigger any change in the Combo's current selection (and it shouldn't have).

I slightly modified one of the databinding Snippets to demonstrate this
effect. Run the attached code under 3.3, and then under 3.4 to see the
difference.

My questions are:

1. is this a planned change in behavior?
2. if so, how can I prevent the undesirable side effect of changing the
data model's property when binding items to the Combo?

Thanks for any clues.

Alex Molochnikov
Kelman Technologies Inc.

--------------020902080207080905020201
Content-Type: text/plain;
name="Snippet002UpdateComboRetainSelection.java"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
filename="Snippet002UpdateComboRetainSelection.java"

LyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq KioqKioqKioq
KioqKioqKioqKioqKioqKioqKioqKioqKioNCiAqIENvcHlyaWdodCAoYykg MjAwNiBUaGUg
UGFtcGVyZWQgQ2hlZiwgSW5jLiBhbmQgb3RoZXJzLg0KICogQWxsIHJpZ2h0 cyByZXNlcnZl
ZC4gVGhpcyBwcm9ncmFtIGFuZCB0aGUgYWNjb21wYW55aW5nIG1hdGVyaWFs cw0KICog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gICAgcmVzZXQuYWRkU2VsZWN0aW9uTGlz dGVuZXIobmV3
IFNlbGVjdGlvbkFkYXB0ZXIoKSB7DQogICAgICAgICAgICAgICAgcHVibGlj IHZvaWQgd2lk
Z2V0U2VsZWN0ZWQoU2VsZWN0aW9uRXZlbnQgZSkgew0KICAgICAgICAgICAg ICAgICAgICBM
aXN0IG5ld0xpc3QgPSBuZXcgQXJyYXlMaXN0KCk7DQogICAgICAgICAgICAg ICAgICAgIG5l
d0xpc3QuYWRkKCJDaG9jb2xhdGUiKTsNCiAgICAgICAgICAgICAgICAgICAg bmV3TGlzdC5h
ZGQoIlZhbmlsbGEiKTsNCiAgICAgICAgICAgICAgICAgICAgbmV3TGlzdC5h ZGQoIk1hbmdv
IFBhcmZhaXQiKTsNCiAgICAgICAgICAgICAgICAgICAgbmV3TGlzdC5hZGQo ImJlZWYiKTsN
CiAgICAgICAgICAgICAgICAgICAgbmV3TGlzdC5hZGQoIkNoZWVzZWNha2Ui KTsNCiAgICAg
ICAgICAgICAgICAgICAgbmV3TGlzdC5hZGQoSW50ZWdlci50b1N0cmluZygr K2NvdW50KSk7
DQogICAgICAgICAgICAgICAgICAgIHZpZXdNb2RlbC5zZXRDaG9pY2VzKG5l d0xpc3QpOw0K
ICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgIH0pOw0KDQogICAgICAg ICAgICAvLyBQ
cmludCB2YWx1ZSBvdXQgZmlyc3QNCiAgICAgICAgICAgIFN5c3RlbS5vdXQu cHJpbnRsbih2
aWV3TW9kZWwuZ2V0VGV4dCgpKTsNCg0KICAgICAgICAgICAgRGF0YUJpbmRp bmdDb250ZXh0
IGRiYyA9IG5ldyBEYXRhQmluZGluZ0NvbnRleHQoKTsNCiAgICAgICAgICAg IA0KICAgICAg
ICAgICAgZGJjLmJpbmRMaXN0KFNXVE9ic2VydmFibGVzLm9ic2VydmVJdGVt cyhjb21ibyks
IEJlYW5zT2JzZXJ2YWJsZXMub2JzZXJ2ZUxpc3QoUmVhbG0uZ2V0RGVmYXVs dCgpLCB2aWV3
TW9kZWwsICJjaG9pY2VzIiksIG51bGwsIG51bGwpOw0KICAgICAgICAgICAg ZGJjLmJpbmRW
YWx1ZShTV1RPYnNlcnZhYmxlcy5vYnNlcnZlU2VsZWN0aW9uKGNvbWJvKSwg QmVhbnNPYnNl
cnZhYmxlcy5vYnNlcnZlVmFsdWUodmlld01vZGVsLCAidGV4dCIpLCBudWxs LCBudWxsKTsN
CiAgICAgICAgICAgIA0KICAgICAgICAgICAgLy8gT3BlbiBhbmQgcmV0dXJu IHRoZSBTaGVs
bA0KICAgICAgICAgICAgc2hlbGwucGFjaygpOw0KICAgICAgICAgICAgc2hl bGwub3Blbigp
Ow0KICAgICAgICAgICAgcmV0dXJuIHNoZWxsOw0KICAgICAgICB9DQogICAg fQ0KfQ==
--------------020902080207080905020201--
Re: Databinding for Combo behaves differently in 3.4 [message #332445 is a reply to message #332436] Tue, 21 October 2008 18:58 Go to previous messageGo to next message
Boris Bokowski is currently offline Boris BokowskiFriend
Messages: 272
Registered: July 2009
Senior Member
I ran the code using 3.3.2 and 3.4.1 but did not notice any difference.
Could you please file a bug against Eclipse Platform UI and provide more
detailed steps what I should do with the snippet once I have it running?
Writing down the expected and actual behaviour in both environments would be
good too.

Thanks
Boris

"Alex Molochnikov" <alexm@xxx.yyy> wrote in message
news:gdl50i$68a$1@build.eclipse.org...
> The change in behavior between Eclipse 3.3 and 3.4 is significant and
> breaks the existing logic.
>
> Here is what happens: a data model carries an array of String items
> (colourScales) that populate the Combo's drop-down list, and a single
> String (colorScale) to track its selection.
>
>
> When the data model is bound to a Combo box, as below
>
> Combo colorScale = ...
> DataBindingContext dbc = ...
> dbc.bindList(SWTObservables.observeItems(colorScale),
> BeansObservables.observeList(Realm.getDefault(), dataModel,
> "colourScales"), null, null);
>
> the Combo fires a text-change event, setting the model's colorScale
> property to a blank value, and corrupting it as the result.
>
> In Eclipse 3.3, binding a Combo to an array of String items did not
> trigger any change in the Combo's current selection (and it shouldn't
> have).
>
> I slightly modified one of the databinding Snippets to demonstrate this
> effect. Run the attached code under 3.3, and then under 3.4 to see the
> difference.
>
> My questions are:
>
> 1. is this a planned change in behavior?
> 2. if so, how can I prevent the undesirable side effect of changing the
> data model's property when binding items to the Combo?
>
> Thanks for any clues.
>
> Alex Molochnikov
> Kelman Technologies Inc.
>


------------------------------------------------------------ --------------------


> /*********************************************************** ********************
> * Copyright (c) 2006 The Pampered Chef, Inc. and others.
> * All rights reserved. This program and the accompanying materials
> * are made available under the terms of the Eclipse Public License v1.0
> * which accompanies this distribution, and is available at
> * http://www.eclipse.org/legal/epl-v10.html
> *
> * Contributors:
> * The Pampered Chef, Inc. - initial API and implementation
> * Brad Reynolds - bug 116920
> ************************************************************ ******************/
>
> package org.eclipse.jface.examples.databinding.snippets;
>
> import java.beans.PropertyChangeListener;
> import java.beans.PropertyChangeSupport;
> import java.util.ArrayList;
> import java.util.List;
>
> import org.eclipse.core.databinding.DataBindingContext;
> import org.eclipse.core.databinding.beans.BeansObservables;
> import org.eclipse.core.databinding.observable.Realm;
> import org.eclipse.jface.databinding.swt.SWTObservables;
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.events.SelectionAdapter;
> import org.eclipse.swt.events.SelectionEvent;
> import org.eclipse.swt.layout.RowLayout;
> import org.eclipse.swt.widgets.Button;
> import org.eclipse.swt.widgets.Combo;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Shell;
>
> /**
> * Shows how to bind a Combo so that when update its items, the selection
> is
> * retained if at all possible.
> *
> * @since 3.2
> */
> public class Snippet002UpdateComboRetainSelection {
> public static void main(String[] args) {
> final Display display = new Display();
> Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() {
> public void run() {
> ViewModel viewModel = new ViewModel();
> Shell shell = new View(viewModel).createShell();
>
> // The SWT event loop
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch()) {
> display.sleep();
> }
> }
>
> // Print the results
> System.out.println(viewModel.getText());
> }
> });
> display.dispose();
> }
>
> // Minimal JavaBeans support
> public static abstract class AbstractModelObject {
> private PropertyChangeSupport propertyChangeSupport = new
> PropertyChangeSupport(this);
>
> public void addPropertyChangeListener(PropertyChangeListener
> listener) {
> propertyChangeSupport.addPropertyChangeListener(listener);
> }
>
> public void addPropertyChangeListener(String propertyName,
> PropertyChangeListener listener) {
> propertyChangeSupport.addPropertyChangeListener(propertyName ,
> listener);
> }
>
> public void removePropertyChangeListener(PropertyChangeListener
> listener) {
> propertyChangeSupport.removePropertyChangeListener(listener) ;
> }
>
> public void removePropertyChangeListener(String propertyName,
> PropertyChangeListener listener) {
>
> propertyChangeSupport.removePropertyChangeListener(propertyN ame,
> listener);
> }
>
> protected void firePropertyChange(String propertyName, Object
> oldValue, Object newValue) {
> propertyChangeSupport.firePropertyChange(propertyName,
> oldValue, newValue);
> }
> }
>
> // The View's model--the root of our Model graph for this particular
> GUI.
> public static class ViewModel extends AbstractModelObject {
> private String text = "beef";
>
> private List choices = new ArrayList();
> {
> choices.add("pork");
> choices.add("beef");
> choices.add("poultry");
> choices.add("vegatables");
> }
>
> public List getChoices() {
> return choices;
> }
>
> public void setChoices(List choices) {
> List old = this.choices;
> this.choices = choices;
> firePropertyChange("choices", old, choices);
> }
>
> public String getText() {
> return text;
> }
>
> public void setText(String text) {
> System.out.println("setText(" + text + ")"); // Fires only under
> 3.4
> String oldValue = this.text;
> this.text = text;
> firePropertyChange("text", oldValue, text);
> }
> }
>
> // The GUI view
> static class View {
> private ViewModel viewModel;
> /**
> * used to make a new choices array unique
> */
> static int count;
>
> public View(ViewModel viewModel) {
> this.viewModel = viewModel;
> }
>
> public Shell createShell() {
> // Build a UI
> Shell shell = new Shell(Display.getCurrent());
> shell.setLayout(new RowLayout(SWT.VERTICAL));
>
> Combo combo = new Combo(shell, SWT.BORDER | SWT.READ_ONLY);
> Button reset = new Button(shell, SWT.NULL);
> reset.setText("reset collection");
> reset.addSelectionListener(new SelectionAdapter() {
> public void widgetSelected(SelectionEvent e) {
> List newList = new ArrayList();
> newList.add("Chocolate");
> newList.add("Vanilla");
> newList.add("Mango Parfait");
> newList.add("beef");
> newList.add("Cheesecake");
> newList.add(Integer.toString(++count));
> viewModel.setChoices(newList);
> }
> });
>
> // Print value out first
> System.out.println(viewModel.getText());
>
> DataBindingContext dbc = new DataBindingContext();
>
> dbc.bindList(SWTObservables.observeItems(combo),
> BeansObservables.observeList(Realm.getDefault(), viewModel, "choices"),
> null, null);
> dbc.bindValue(SWTObservables.observeSelection(combo),
> BeansObservables.observeValue(viewModel, "text"), null, null);
>
> // Open and return the Shell
> shell.pack();
> shell.open();
> return shell;
> }
> }
> }
Re: Databinding for Combo behaves differently in 3.4 [message #332449 is a reply to message #332445] Tue, 21 October 2008 19:35 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: alexm.xxx.yyy

Boris,

Thank you for a speedy response. I will file a bug report; in the
meantime, you can easily reproduce the problem:

1. run the snippet as a Java app, in Eclipse 3.4.1. A small window comes up.
2. press "reset collection" button.
3. see the setText() method of ViewModel fire, with an empty String as a
parameter. The Console shows this:

beef
setText()

It is this last bit that should not happen. The Combo should not have an
"empty" selection (setting the item list does not alter the selection -
at least, that was the pre-3.4 behavior). And it should not update the
data model at this point.

Boris Bokowski wrote:
> I ran the code using 3.3.2 and 3.4.1 but did not notice any difference.
> Could you please file a bug against Eclipse Platform UI and provide more
> detailed steps what I should do with the snippet once I have it running?
> Writing down the expected and actual behaviour in both environments would be
> good too.
>
> Thanks
> Boris
Re: Databinding for Combo behaves differently in 3.4 [message #332458 is a reply to message #332449] Tue, 21 October 2008 20:22 Go to previous message
Eclipse UserFriend
Originally posted by: alexm.xxx.yyy

Submitted bug report: https://bugs.eclipse.org/bugs/show_bug.cgi?id=251611

Alex
Previous Topic:refresh file with refreshLocal( ), does not sync all tabs in Multipage ed
Next Topic:Where is the menu "Generate Bindung Content" ?
Goto Forum:
  


Current Time: Sat Nov 02 16:50:04 GMT 2024

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

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

Back to the top