I need to listen to a HZ update event ONLY when an specific property of the object changes:
https://docs.hazelcast.com/imdg/4.1/data-structures/map#listening-to-map-entries-with-predicates
But I dont know if this could be done through a Predicate (see bold fragment):
map.addEntryListener(chatsWithConvView, Predicates.sql(""), true);
If the property stays the same, and all other properties of the object changes I dont want the event to be triggered because of millions of events would be trigered.
Is this possible?
Unfortunately, this doesnt work, but could be something like this:
map.addEntryListener(chatsWithConvView,
Predicates.sql("waConversationsCounter = (SELECT
'waConversationsCounter' + 1)"), true);
I know this waConversationsCounter is always going to increment 1 (always), is the only update event I want to capture. But this predicate doesnt work.
How can I do it?
Related
I need to add a reaction in my interface on changes in TextField and ComboBox.
Binder is a convinient way for handling data binding in Vaadin.
I can't use on textField.addValueChangeListener(...) as it is called before new value is set in binded model.
Is there a way to add a something like a value change listener on specific field in binder?
I can use binder.addValueChangeListener() but it is fired on every bound field changes and I can't easily tell them apart.
Ideally, it would be something like that:
binder.forField(specificTextField)
.withConverter(...)
.withValidator(...)
.bind(Person::getName, Person::setName)
.addValueChangeListener(...); // nonexistent functional
The answer to the question whether there is a way to add a value change listener to a single Binding itself is no there is not. I agree this could be a cool and useful addition to the Flow API. Please go ahead and write an issue in their github
However, as you noticed yourself, there is the method Binder::addValueChangeListener, and there is a way to tell them apart. The accepted eventListener has a way to get the HasValue (a.k.a. bound input field) that fired the change event. it also has access to both the old and the new value.
TextField tf = new TextField();
ComboBox cb = new ComboBox();
// todo: binding of fields
binder.addValueChangeListener(valueChangeListener -> {
if(valueChangeListener.getHasValue().equals(tf)){
// tf value changed
} else if(valueChangeListener.getHasValue().equals(cb)) {
// cb value changed
}
}
I want to set custom focus key in my application. Default is TAB. Sometime I need to omit for some component. Sometime need to reverse by another key. I find that when JTable gets focused. TAB only works and select within its row and never go outside the table. In my case, I need to change focus when all row has finished selection or a hot key to omit entire table.
Sometime I also need to implement system focus key as client already may habituate with it.
How can I achieve that easily?
I think this is what you are looking for.
note :
Set<AWTKeyStroke> set = p.getFocusTraversalKeys(KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS);
set = new HashSet(set);
KeyStroke up = KeyStroke.getKeyStroke("A");
I was trying to create a new UI component for the user to specify an integer value in two ways: using either a scrollbar, or a textfield. I wanted this to be a single UI component from which I can call something like integerField.getValue() and have it return the current integer value represented by the component.
My problem is, a classic cyclical update situation: when the underlying integer value is changed using the scrollbar, the textfield value needs to be updated, which triggers another event that causes the scrollbar to update - cycle complete.
In other words, scrollbar.setValue()->component.setValue()->textField.setText()->component.valueChanged()->component.setValue()->scrollbar.setValue()
Now, I can prevent this by having the first item in this chain setting a boolean flag and the other items in the component checking the flag before responding to a value change event. However, I'm not convinced that's an elegant solution.
Anyone have any better ideas?
Thanks!
A technical solution to the problem would be to read your text field and the last update time then your slider and the last update time. On the firing of the event, you would read the most recently updated value and if the values match stop updating and reacting.
SpinSlider, seen here and here, may be a good choice. It combines a JSpinner and a JSlider so that each component's ChangeListener listens to the other's ChangeListener.
I want to do something based on the model change, e.g. if user enters text in the Text SWT widget, I would like to do something based on that. But the problem is, if I use e.g. key listener on the widget, it will get called before the data binding process occurs and therefore the behaviour would'nt be consistent. One way around this is to do the logic inside the binding process, but this is not really a convinient way of handling this problem. Suggestions?
So basically, what I need is an event listener, which is triggered after the data binding occures (on some specified widget of course).
Use an IChangeListener to listen for changes on the model observable value. This will be called after the model has been updated from the target.
Something like:
IObservableValue targetOV = WidgetProperties.text(SWT.Modify).observe(text control);
IObservableValue modelOV = PojoProperties.value("your field").observe(object);
bindContext.bindValue(targetOV, modelOV);
modelOV.addChangeListener(change listener);
I want to create a Swing JTextPane that takes action when the user types text into it. But I also want to be able to alter the text in that pane without it treating that alteration as a user typing. How can I do this?
If you don't let update events fire, then chances are that your UI won't get updated either, depending on the actual implementation. So I agree that you might be better off by talking to the event handler, letting it know that the next alteration is going to be a programmatic change. Something like this:
try {
listener.setProgrammaticChange(true);
// change document
}
finally {
listener.setProgrammaticChange(false);
}