Vaadin 8 combobox implements before(!) dropdown event? - java

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.

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);
});

SWT event triggered by combo list changing?

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.

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

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;

Issue updating a parent JFrame

First, let it be known that I'm new to java and it's quirks. I'm a seasoned programmer with various languages, which may be why I'm stuck...
I have an application that, possibly due to poor design, spawns new JFrames through the users' work-flow. My question is, if there is an event in a spawned JFrame, is it able to contact and pass data or an event to it's parent?
I have read that using a JDialog seems to be the way to design, but let's assume that's not an option. Essentially, JFrame1 contains a JTable with a list of data. An action spawns JFrame2 and a user "does something" that impacts the data in the list in JFrame1. Upon closing JFrame2, is there a way to control the JTable based on JFrame2's close event?
It's a pretty basic concept, I just can't seem to find the mechanism that would allow such an action.
Thanks!
You can use "listeners" to listen for various events.
It sounds like you might want to start with How to Write a Window Listener.
I have read that using a JDialog seems to be the way to design, but let's assume that's not an option.
Why? The code is the same and JDialogs where designed for this purpose. What is the specific requirement that says you need to use a JFrame?
An action spawns JFrame2 and a user "does something" that impacts the data in the list in JFrame1. Upon closing JFrame2, is there a way to control the JTable based on JFrame2's close event?
This is a common design. The user selects a row to change or update and a model dialog is created to display all the data so it can be changed. When the dialog is saved the data in the table is updated. If this is your requirement, then you can just pass in the TableModel to the dialog. Then when the dialog is closed you update the TableModel and the table will be repainted automatically.
You would have to capture the window closing event using a window listener. The window listener would also need a reference to the data that needs to be changed.
In addition to using Window.addWindowListener() on either a JFrame or a JDialog, consider using a model-view approach. Have the close event modify the table's data, rather than the table itself. Use AbstractTableModel as the model for the table, and listen for changes to the data.

Categories