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
Related
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.
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);
});
Is it possible in Vaadin 8 combobox handle before(!) dropdown event?
Actually, I need to implement DataProvider that would re-read data each time when a user tries to select data from the combobox (adding new items are not allowed). CallbackDataProvider, FetchItemsCallback etc. are not an option cause they read data only once.
Any ideas?
Have you tried implementing AbstractBackEndDataProvider? Method fetchFromBackEnd seems to be called every time user opens the combo box.
Furthermore the is enhanced version of the ComboBox in the Vaadin's Directory https://vaadin.com/directory/component/prefixcombobox, which adds events for observing popup opening and closing. But this event is fired after popup has been opened.
In SWT, I can find plenty of events that fire when text is typed into the combo, the user makes a selection, etc.
Are there any triggers for when the combo list gets updated, though?
E.g., if I the list is
['apple', 'banana']
and it becomes
['apple', 'banana', 'shoe']
is there any trigger for that, and if not, can I create one?
SWT does not send an event if the list of items of a Combo or CComb changes.
If you use a JFace ComboViewer, its IContentProvider gets informed when the viewer's input changes through its inputChanged() method.
If that's not what you want, then you are free to write application code that notifies interested observers about content changes.
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.