CaptainCasa framework: DOF reactOnInstanceSelect conflicting with clickable items in the grid - java

In a few DOF grids I have icons and buttons with click actions added using a DOF extension. I also want to trigger another action when single-clicking on a grid row (reactOnInstanceSelect). I want to avoid triggering the reactOnInstanceSelect action when clicking on the icons/buttons.
Right now when I click on a button, both the button event and the reactOnInstanceSelect event are fired. The event sequence seems to be random. (in my case both events opened a popup, and the resulting popup sequence is random, the event fire sequence is not)

There is a function...
List<FacesEvent> requestEvents = ThreadData.getInstance().getRequestEvents();
...which gives you all events that are contained in a roundtrip. Could you try this one to find out in the "reactOnInstanceSelect" if another event occurs in parallel?
By the way: the event sequence is driven by the sequence of components in the component hierarchy.

Related

Need to trigger JavaFX TableView's built-in Table Menu Button

I have an application where a TableView will be created dynamically based on a database query. This means that my application will have multiple tables with differing columns.
I must display a separate button to show/hide columns. I am familiar with the table menu button triggered with table.setTableMenuButtonVisible(). Unfortunately, I cannot use the actual on-screen built-in button on the UI, although I would like to use it's functionality.
I am essentially looking for a table.getTableMenu().show()
sort of call. But I can't find where this is a built in method of any sort. Is there a way that I can call this button's action from a UI button of my own design?
Actually, I was wrong in my comment: it is possible to lookup the corner region and trigger its mousePressedHandler without reflection.
The following code snippet opens the corner menu just as if it had been clicked directly (in fx11 at least, and still dirty in relying on the implementation detail that opening is triggered by a mousePressed event):
Button showCorner = new Button("open menu button");
showCorner.addEventHandler(MouseEvent.MOUSE_PRESSED, e -> {
Node corner = table.lookup(".show-hide-columns-button");
corner.fireEvent(e);
});

programmatically clicking combo-box button in swt

How to cause the click/ selection event in SWT through code ? without the user actually clicking the control, the event should be fired !! is it possible?
I need to automate the clicking of a combo box button and the dropping down of the list and the selection of the item - as done by the user!! i.e., playback of the recorded events. Which listener do i need to use ? i tried selection but couldn't get the results.
combo.setText(combo.getItem(combo.getSelectionIndex()));
You can simulate a selection event with something like:
Event event = new Event();
event.widget = combo;
event.type = SWT.Selection;
combo.getDisplay().post(event);
You might need to set other fields in Event
If you want to simulate the user interactions for testing purpose, try windowstester. It also has recording feature where you can record the ui activities and just run it over the test...
https://developers.google.com/java-dev-tools/download-wintester

Java differentiate between menu click and accelerator

I have menu items with an accelerators. I would like to detect when a menu item was clicked as opposed to executed using accelerator. Is this possible?
Thanks,
Alexander.
While you can listen for MouseEVents and Actions, you can also just inspect the modifiers of the ActionEvent and see if a key was involved in the event or not. That way, you only have one listener to deal with...
a mouse click will fire off a MouseEvent and an Action. An accelerator will only fire off an action.
You can compare the key-info in the ActionEvent with the Action#ACCELERATOR_KEY key-value pair, which should be able to distinguish between a user clicking while holding a random/modifier key, and the actual accelerator key combination

FocusLost called after menuaction

I have a MenuItem with a shortcut key to save the data of a JTextFied temporary and print it
The save function is called on FocusLost event of the JTextField and the print is called via MenuItems actionListener and is fired when I click on the MenuItem as well as when i press the shortcut key for the menuitem (eg: f1)
The problem is that when i directly press f1(shortcut for menuitem), the focusLost event for the Textfied is fired only after the menuitem has performed its action, whereas when I go to the menu and press, the focuslost is fired first followed by the menu's Action
Is there a way to force a Focuslost so that even with a shortcut key, the focusLost event is fired first
Tried using requesfocusinWindow, setText (performed on other demo textfields just to force a focusLost)
1) I think that's not possible in Programing Languages, more about that in the theory of AWT Focus Subsystem and How to Use the Focus Subsystem,
2) you have to redirect this Save Processes to the Backgroung Task, and before that you can check if JMenu and its JMenuItem are/aren't selected, for this check use only ButtonModel, otherwise don't do that, because your GUI heve to waiting for this processes
3) anothere choice is save on periodical bases values from JComponents to some Array, there you can check if value was/were changed, all changes must be checked/saved from Backgroung Task, without any impact to the Swing GUI
4) easiest way how to create something as Timer would be to wrap some logics to the Runnable#Thread, delayed by Thread.sleep(int) but exclusively inside Runnable#Thread only
It is generally suspect when you want to 'force' focusLost, as the intention of that event is the user did something to change the focus status of the application. When you say that F1 is a menu item shortcut, do you mean it is a shortcut to the same code that is executed when the menu is selected, or that you have it setup as a menu mnemonic?
In the end, shortcut keys do not generally change focus intrinsically, whereas the mouse actions required to click a menu item do, and that is something you may have to account for yourself.

How do I make a listener that fires when the USER selects an item in a JComboBox

I'm looking for a listener that fires ONLY when the user, the one who's using the program, selects an item in the JComboBox. I don't want to use ActionListener or ItemListener because those also fire when I select an item through the program. And I can't use MouseListener either because it only fires when I click the JComboBox, not when I select an item.
I was wondering what the easiest way to do this is? Currently, my solution is messy. When I change the selected item of the jcombobox through code, I set a flag to true. And in my action listener, it only executes if the flag is false.
A) I would recommend you to temporarily remove the listener when you perform the selection programatically.
B) If your programatic change is not an effect of another GUI event you could solve it the following ugly/non-robust/error-prone/"hacky" way: Check EventQueue.isEventDispatchThread() to find out if the click was triggered by the GUI thread (the user).
C) (Oops I just reread your question and saw that you've already discovered the method described below. Basically I would say that this (or the the method described above) is your best alternative.)
Another option is to have a boolean flag called something like nonUserSelection which you set to true before you select a value programatically and reset to false afterwards. In the action listener you simply add an
if (nonUserSelection)
return;

Categories