Hi Matthias,
Another option is to throttle the selection. Databinding has support for
that. Try this snippet:
import org.eclipse.core.databinding.observable.Realm;
import org.eclipse.core.databinding.observable.sideeffect.ISideEffect;
import
org.eclipse.core.databinding.observable.sideeffect.ISideEffectFactory;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.databinding.swt.DisplayRealm;
import org.eclipse.jface.databinding.swt.WidgetSideEffects;
import org.eclipse.jface.databinding.swt.typed.WidgetProperties;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
/**
* This snippet shows how to use the {@link ISideEffect} class together
with a
* delayed IObservable with a {@link Text} widget. If text is entered the
side
* effect is triggered with a delay
*
* @since 3.2
*
*/
public class SnippetSideEffect50_DelayedUpdate {
/**
* @wbp.parser.entryPoint
*/
public static void main(String[] args) {
Display display = new Display();
Realm.runWithDefault(DisplayRealm.getRealm(display), () -> {
// create the Task model object
final Shell shell = new View().createShell();
Display display1 = Display.getCurrent();
while (!shell.isDisposed()) {
if (!display1.readAndDispatch()) {
display1.sleep();
}
}
});
}
static class View {
private Text summaryText;
private Label resultLabel;
public Shell createShell() {
Display display = Display.getDefault();
Shell shell = new Shell(display);
GridLayoutFactory.fillDefaults().applyTo(shell);
GridDataFactory gridDataFactory = GridDataFactory.fillDefaults().grab(true,
false);
Label label = new Label(shell, SWT.NONE);
label.setLayoutData(
new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
label.setText("Wait for it....");
resultLabel = new Label(shell, SWT.NONE);
resultLabel.setText("");
gridDataFactory.applyTo(resultLabel);
// create a Text widget, which will be bound to the Task summary
summaryText = new Text(shell, SWT.BORDER);
gridDataFactory.applyTo(summaryText);
bindData();
// Open and return the Shell
shell.pack();
shell.open();
return shell;
}
private void bindData() {
ISideEffectFactory sideEffectFactory =
WidgetSideEffects.createFactory(summaryText);
// create the observables, which should be bound by the SideEffect
IObservableValue<String> textModifyObservable =
WidgetProperties.text(SWT.Modify).observeDelayed(1000,
summaryText);
sideEffectFactory.create(textModifyObservable::getValue, e -> {
resultLabel.setText(summaryText.getText());
});
}
}
}
On Mon, Mar 15, 2021 at 12:17 PM Matthias Paul Scholz <
[email protected]> wrote:
> Hi Wim,
>
> I'm aware that the concept of an edit transction makes sense for the
> graphical mode only where the user has some sort of "edit session".
> But at least in that case I think there should be such a concept and the
> API should provide a possibility to hook into it.
>
> By the way, I wonder whether both a programmer and the user actually
> expects that the value of the widget gets changed already before she
> presses Enter or clicks the green hook.
>
> Best,
> MP
>
>
> Am Mo., 15. März 2021 um 11:28 Uhr schrieb Wim Jongman <
> [email protected]>:
>
>> Hi Matthias,
>>
>> It depends on how you use the widget. CDateTime has many faces. When
>> using the widget in its simplest form, there is no concept of Enter or OK.
>> So it means that databinding has to be different based on the style of the
>> widget.
>>
>> [image: image.png]
>>
>> Cheers,
>>
>> Wim
>>
>>
>>
>>
>> On Mon, Mar 15, 2021 at 10:08 AM Matthias Paul Scholz <
>> [email protected]> wrote:
>>
>>> Hi all,
>>>
>>> For some years we have used the CDateTime widget in our RCP application
>>> which works quite good. :)
>>>
>>> However, we ran in some troubles lately: to get notion about changes the
>>> user made in the widget, we use the databinding proposed by Henno
>>> Vermeulen (see https://www.eclipse.org/forums/index.php/t/172877) that
>>> binds our application to a selection event in the widget.
>>>
>>> There's an issue with that approach, however: it seems that such a
>>> selection event is triggered always on each selection inside of the widget.
>>> For instance, when the user cycles through the months in the calendar drop
>>> down or selects another day, each time a separate selection event is fired.
>>> This is inconvenient for us, since we need an event only when the user
>>> explicitely commits her changes by selecting the ok button (or pressing
>>> enter).
>>>
>>> This has become crucial for us lately since we have a new use case now
>>> where a change in the widget triggers an expensive backend operation - and
>>> it is a no go when this happens each time the user changes the month in the
>>> calendar drop down ...
>>>
>>> Is there a possibility to listen for or to bind to ok/enter events on
>>> the CDateTime widget only?
>>>
>>> Thanks,
>>> MP
>>>
>>> _______________________________________________
>>> nebula-dev mailing list
>>> [email protected]
>>> To unsubscribe from this list, visit
>>> https://www.eclipse.org/mailman/listinfo/nebula-dev
>>>
>> _______________________________________________
>> nebula-dev mailing list
>> [email protected]
>> To unsubscribe from this list, visit
>> https://www.eclipse.org/mailman/listinfo/nebula-dev
>>
> _______________________________________________
> nebula-dev mailing list
> [email protected]
> To unsubscribe from this list, visit
> https://www.eclipse.org/mailman/listinfo/nebula-dev
>
_______________________________________________
nebula-dev mailing list
[email protected]
To unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/nebula-dev