Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » [DataBinding] Problem with clearing the text in a Combo
[DataBinding] Problem with clearing the text in a Combo [message #332787] Sat, 08 November 2008 04:39 Go to next message
Ali Naddaf is currently offline Ali NaddafFriend
Messages: 85
Registered: July 2009
Member
Hello all.

I have a Combo box that is also editable and I want to make sure any
change in the text there, whether it is true using the drop down or
using the text by just editing the value is captured. Here is my current
binding:

dbc.bindValue(SWTObservables.observeText(myCombo),
BeansObservables.observeValue(myModel,"someField"), null, null);

The issue I am running into is the following: if the Combo is showing a
value and

(1) if I put the focus into that combo by clicking inside it, the whole
content becomes "highlighted" and if at that moment I use the Backspace
key to clear the content (only on Backspace is adequate since the whole
content is highlighted), then my model *doesn't* get updated.

(2) if I put the focus into that combo, the whole content becomes
"highlighted" and if I click there again, the highlighting of the
content disappears. If at that moment I use the Backspace key to clear
the content (only on character is removed at a time), then my model
*does* get updated.

The behavior in case (2) is what I like but the behavior in (1) is not
good for me, I need my model be updated regardless of the way the
content is updated. Does anyone have any suggestion?

Thanks,
Ali.
Re: [DataBinding] Problem with clearing the text in a Combo [message #332873 is a reply to message #332787] Tue, 11 November 2008 22:25 Go to previous message
Eclipse UserFriend
Originally posted by: malloovidio.bluewin.ch

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

Hi Ali,

with the CVS HEAD version of the databinding framework, both of your scenarios
(1) && (2) seem to work correctly for me. I've modified an existing databinding
snippet to make it use a combobox to reproduce your setup. Can you maybe try to
run the attached snippet in your environment and see whether the model observable
is updated (you should get an output on the console)? If not, what version of
databinding are you using?

Kind regards,
Ovidio


Ali Naddaf wrote:
> Hello all.
>
> I have a Combo box that is also editable and I want to make sure any
> change in the text there, whether it is true using the drop down or
> using the text by just editing the value is captured. Here is my current
> binding:
>
> dbc.bindValue(SWTObservables.observeText(myCombo),
> BeansObservables.observeValue(myModel,"someField"), null, null);
>
> The issue I am running into is the following: if the Combo is showing a
> value and
>
> (1) if I put the focus into that combo by clicking inside it, the whole
> content becomes "highlighted" and if at that moment I use the Backspace
> key to clear the content (only on Backspace is adequate since the whole
> content is highlighted), then my model *doesn't* get updated.
>
> (2) if I put the focus into that combo, the whole content becomes
> "highlighted" and if I click there again, the highlighting of the
> content disappears. If at that moment I use the Backspace key to clear
> the content (only on character is removed at a time), then my model
> *does* get updated.
>
> The behavior in case (2) is what I like but the behavior in (1) is not
> good for me, I need my model be updated regardless of the way the
> content is updated. Does anyone have any suggestion?
>
> Thanks,
> Ali.


--------------070601070704080407080508
Content-Type: text/plain;
name="Snippet000HelloWorld.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="Snippet000HelloWorld.java"

/*********************************************************** ********************
* 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
* Benjamin Cabe - bug 252219
************************************************************ ******************/

package org.eclipse.jface.examples.databinding.snippets;

import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.beans.PojoObservables;
import org.eclipse.core.databinding.observable.Realm;
import org.eclipse.core.databinding.observable.value.IObservableVal ue;
import org.eclipse.core.databinding.observable.value.IValueChangeLi stener;
import org.eclipse.core.databinding.observable.value.ValueChangeEve nt;
import org.eclipse.jface.databinding.swt.ISWTObservableValue;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

/**
* Hello, databinding. Bind changes in a GUI to a Model object but don't worry
* about propogating changes from the Model to the GUI.
* <p>
* Illustrates the basic Model-ViewModel-Binding-View architecture typically
* used in data binding applications.
*/
public class Snippet000HelloWorld {
public static void main(String[] args) {
Display display = new Display();
final ViewModel viewModel = new ViewModel();

Realm.runWithDefault(SWTObservables.getRealm(display),
new Runnable() {
public void run() {
final Shell shell = new View(viewModel).createShell();
// The SWT event loop
Display display = Display.getCurrent();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
});
// Print the results
System.out.println("person.getName() = "
+ viewModel.getPerson().getName());
}

// The data model class. This is normally a persistent class of some sort.
//
// In this example, we only push changes from the GUI to the model, so we
// don't worry about implementing JavaBeans bound properties. If we need
// our GUI to automatically reflect changes in the Person object, the
// Person object would need to implement the JavaBeans property change
// listener methods.
static class Person {
// A property...
String name = "HelloWorld";

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}

// The View's model--the root of our Model graph for this particular GUI.
//
// Typically each View class has a corresponding ViewModel class.
// The ViewModel is responsible for getting the objects to edit from the
// DAO. Since this snippet doesn't have any persistent objects to
// retrieve, this ViewModel just instantiates a model object to edit.
static class ViewModel {
// The model to bind
private Person person = new Person();

public Person getPerson() {
return person;
}
}

// The GUI view
static class View {
private ViewModel viewModel;
private Combo name;

public View(ViewModel viewModel) {
this.viewModel = viewModel;
}

public Shell createShell() {
// Build a UI
Display display = Display.getDefault();
Shell shell = new Shell(display);
shell.setLayout(new RowLayout(SWT.VERTICAL));
name = new Combo(shell, SWT.BORDER);

// Bind it
DataBindingContext bindingContext = new DataBindingContext();
Person person = viewModel.getPerson();

ISWTObservableValue target = SWTObservables.observeText(name);
IObservableValue model = PojoObservables.observeValue(person, "name");
bindingContext.bindValue(target, model, null, null);
model.addValueChangeListener(new IValueChangeListener() {
public void handleValueChange(ValueChangeEvent event) {
System.err.println("model changed to: " + event.diff.getNewValue());
}
});

// Open and return the Shell
shell.pack();
shell.open();
return shell;
}
}
}

--------------070601070704080407080508--
Previous Topic:Question about IAutoEditStrategy
Next Topic:How to open a file and jump to a certain line number
Goto Forum:
  


Current Time: Fri Apr 26 15:17:38 GMT 2024

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

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

Back to the top