Is any way to create custom InputEvent or custom InputRadioButton? What I need is a button selection without calling registered “OnEvent” callback, if the selection is not performed by the user, but programmatically from Java code. The problem is that the only way to make button selection from the code is by calling setSelected() method, which is the same like user click on a button. I need to distinguish
if a button is selected by the user (and in that case it is expected that registered callback is called), and
if selection is performed programmatically (in this case I don’t want registered callback to be executed)
Calling setSelected() is not the only way to make a selection from a button. That method only sets the state of the button. I suppose depending on the type of listener, certain programmatic actions can also fire the listener. For example, if you use an “onClick” listener, setSelected() doesn’t fire the callback.
My guess would be that your openView() is running setSelected, and you’re having undesired effects? If you truly need whatever listener you’re using, then set some locking flags in openView() and look for these as part of the conditions to fire your callback on the radio button. For example:
IN OPENVIEW():
blockMyRadioButton = true //<-- Make this a public boolean
...
do the rest of your openView code
...
blockMyRadioButton = false
IN YOUR VIEW WITH RADIO BUTTON:
onEvent() {
if(myRadioButton.isEnabled() && !myContribution.blockMyRadioButton) {
//do whatever you need to
}
}
Ok, maybe I didn’t give enough information or describe it in the right way. I’m using Java HTML where graphical component is “defined” in *.html file. In java, it is bound:
and then method registered to the button: @Input(id = “btnTest”)
public void onBtnTestClick(InputEvent event)
{
if(event.getEventType() == ON_PRESSED)
{ // code}
elif(event.getEventType() == ON_RELEASED)
{ // code}
}
This is a recommendation and example how to bind component in Java html. Possible values for InputEvent type are: ON_PRESSED, ON_RELEASED and ON_CHANGE. Yes, in java Swing it is possible to add listener, but not sure how in Java html.
Now, except “btnTest” button on Installation Node, additionally I have two radio buttons (ON and OFF) and the same on Toolbar (implemented in Java swing) (two radio buttons + InputButton), with the same logic if you select ON, OFF, or press and release input button. Problem:
any action on radio buttons on IN have to be replicated on Toolbar and vice versa. It is not necessary to execute twice the same logic, but visualization have to be aligned.
if it’s ON selected, when (and while it is not released) “btnTest” is pressed, OFF radio button should be shown as selected (on IN and Toolbar as well), once “btnTest” is released, then ON radio button is restored (on IN and Toolbar). From the code, the only way to make selection of an HTML component InputRadioButton (as far I know) is to call setSelected() method, which is the same like operator made selection by touching it on teach pendant. I do not know if it is possible to assign listener for html component, so the idea was to define “CustomInputEvent” event (which inherits InputEvent) and to distinguish the caller in that way, but it is not possible.
Information on InstallationNode and Toolbar (data, component enabled/disabled, etc) are updated each second by the timer which gets data from daemon service.
I know that workaround is to change the text assigned to the buttons instead of changing selection, but in my opinion it is not clear solution.
If any way to make visual selection on the IN for InputRadioButton without triggering the callback, I would appreciate it.
I can’t really speak for the HTML side, as I thought I read somewhere that doing HTML was not advised for developing CAPs. All I can say is that I’ve seen the exact behavior you’re describing in Java, and it boils down to the type of event. Certain listeners react to any change to the component (manual or programmatic) while others react only to the manual selection.
You just need to find something other than “InputEvent” as your event type. For example, I’m not sure why a MouseEvent wouldn’t work. Something like this: