To detect the paste event in addressbar in gwt - java

How to detect that pasting event is fired in the address bar through GWT? When we paste the thing from textbox to the addressbar then how to detect that pasting event in gwt.

What if a user decides to type an address instead of pasting it?
A standard approach is to use OnValueChangeEvent on a Textbox. It fires when a Textbox loses focus AND a value in the Textbox has changed, or when the Enter button is pressed while focus is still on the Textbox.
An alternative approach is to add a button, like "Take me there", that a user can press after a user is done entering the URL (either by pasting it or typing it).

Related

System returns me back to the previous page instead of taking to the next one without even clicking 'Next' or 'Back' button

I have a webpage See WebPage screen shot
Code
WebElement whatAirline = driver.findElement(By.cssSelector(".BaggageFlightDetailsView-airlineField input"));
whatAirline.sendKeys("AeroGal (2K)");
whatAirline.submit(); //This is kind of drop down menu list is the COMBOBOX with no class 'select', just class 'input'
WebElement confirmationCode = driver.findElement(By.cssSelector(".Input-input"));
confirmationCode.sendKeys("test");
whatAirline.submit();
It brings me to the previous page, though 'Next' button on this page becomes enabled!
IMPORTANT:'Next' button is not even a button it just has class -that's all, no other data! `class = ''PagerButtons-button PagerButtons-button--next''
What else i tried? Explicitly wait, click 'Next' as a button (though it is not even a button)
Nothing works ! HELP!
I think you have entered invalid data in any of two fields. So the next button may not be enabled, it automatically clicks enabled back button. Check your inputs.
Use select class for drop down list. Also use explicit Wait to click next button.
Solved!
The problem that i found was:
Combobox was not holding the value selected in drop-down, just typed it.
System was taking me back because 'Back' button was the only one enabled.
That is why submit was taking me back every time.
I added whatAirline.click(); before submit and it worked out!
Please note, that i should have not write button click as on top of everything i had no button at all, just an element that looked like a button.

Writing text into another application's text controls (on mouse focus)

I need some advice on how to write text into another application's line edit when that control receives mouse focus.
For example:
I opened google.com and clicked in the "Search" field (so the mouse focus is in "Search" field).
I need to programmatically write text in that field.
I have used Robot class but some symbols are not supported. Are there any ways to solve this problem?

ActionListener running before focus listener

I have an application in which there is a textbox and a button. the textbox has focusListener(for incorrect values) and the button has actionListener(for saving the value into a file).
An error message window pops up when a wrong value is entered in the textfield as soon as it loses focus. Now I have 2 senarios.
when the focus is lost from tab out and if a wrong value is entered in the field then the pop up window shows up correctly.
But when i enter a wrong value in the field and without tab out I click the button then the actionListener is activated before the focusListener(Focus Lost) and it saves the wrong value in the text file and then shows the error message.
How should I stop the incorrect value to be saved into file by running the focuslistener first?
ActionListener running before focus listener
Focus, FocusListener, Focus Subsystem is asyncronous, you can sheduling those events, but can caused another side effects, I'd suggest don't do that
delay required events in EDT by using invokeLater,

Postpone Event Queue after Focus Lost

I have a JTable with a custom cell editor. The editor implements FocusListener so I can check if the cell's contents is valid if the user clicks away from the cell.
I'd like to use a JOptionPane within focusLost (in the EventDispatchThread) to allow the user to select whether to revert to an old value or accept an adjusted value.
Here's the problem; if the user is editing a cell, then clicks a button away from the table, the button's actionlisteners are alerted before JOptionPane has returned.
This is what I'd like to happen:
User edits cell
User clicks button
Cell detects focus lost
JOptionPane displayed and user selects action
JOptionPane closes and cell's value set
Button's actionListeners called
Instead, this is happening:
User edits cell
User clicks button
Cell detects focus lost
JOptionPane displayed and user selects action
Button's actionListeners called
JOptionPane closes and cell's value set
Is it possible to postpone the button's action events until after the JOptionPane has closed?
From other threads, I've read that JDialog does some magic to ensure event dispatching continues so the Dialog itself can handle events.
From what I gather, you don't want the button's action-listener to activate at all, until AFTER the user selects the correct value from the JOptionPane.
To me it seems like the solution would be to set up a 'disabled' flag which goes up once the focusLost is triggered. Once the selection is made, the disabled flag goes down. When the button action is triggered, it checks if the form is disabled; if it is, it does nothing. If it isn't it continues as normal.
Notice the button event won't go automatically once the user selected something in the JOptionPane, but instead he will have to click the button again. To me this seems like better functionality then having the button 'clicked' again for him after he is required to change the form.
Put your validation logic inside TableCellEditor#stopCellEditing(), showing your dialog and returning false if the value is not valid.
To automatically stop table editing on focus lost, use table.putClientProperty("terminateEditOnFocusLost", true);, but I don't think that will stop the buttons action listener from running. Instead I usually stop the table edit in the actionPerformed and do nothing when false is returned (or cancel editing when appropriate, for example if the action is to delete that table row).

Swing Events Trouble

I am new to Java and am developing a java swing application.
The main frame (JFrame) has a text box and an OK button. There is some long processing to be done when the focus from the text box is lost as well as different long processing when the OK button is clicked. Now if the user enters a value in the text box and clicks the OK button directly, ideally, first the focus lost event is fired and then the event on the OK button. The problem is that while the focus lost event is running a joption frame comes up asking the user for some input, but even before user enters the input here, the OK button event starts executing leading to problems in the application. How can I serialize the event calls.
Any help will be appreciated.
Your problem lies within the concept of the Event Dispatch Thread. For long running work loads, check out the SwingWorker class.

Categories

Resources