I am new to GWT. Here is my checkBox code, I want to know whether it is chose or not when user click button.
CheckBox checkBox = new CheckBox("Disable Credential");
checkBox.setValue(false);
flexTable3.setWidget(0, 0, checkBox);
checkBox.getElement().setId("checkBox");
flexTable3.getFlexCellFormatter().setColSpan(0, 0, 2);
flexTable3.getFlexCellFormatter().setHorizontalAlignment(0, 0,
HasHorizontalAlignment.ALIGN_CENTER);
Here is my getting checkbox value code in onclick handler class :
InputElement checkBoxElement = (InputElement) (Element) DOM
.getElementById("checkBox");
if (checkBoxElement.getValue() != null) {
checkBox = checkBoxElement.getValue() != null;}
Based on my code, the checkBox result is always false no matter it's chose or not. Any idea how to figure it out?
In GWT you almost never need to set an id on an element and get an element by id. You already have your CheckBox widget in your code - use it.
checkbox.addValueChangeHandler(new ValueChangeHandler<Boolean> () {
#Override
public void onValueChange(ValueChangeEvent<Boolean> event) {
if (event.getValue()) {
// check box is selected
}
}
}
Have you tried the onValueChange handler?
Related
I converted some old Java Swing code to JavaFX. The JavaFX code had explicit doClick() for the right mouse button calls:
myButton.addMouseListener(new MouseAdapter() {
#Override
public final void mousePressed(MouseEvent e) {
if (SwingUtilities.isLeftMouseButton(e)) {
// ...
}
else if (SwingUtilities.isRightMouseButton(e)) {
// ...
myButton.doClick();
}
}
});
Left clicks make the button visually appear to be clicked in Java Swing. However right clicks do not visually do this without adding myButton.doClick()
I am seeing the same visual behavior in JavaFX and I want right clicks to visually make the button look clicked. Below is my JavaFX code:
myButton.setOnMouseClicked(new EventHandler<MouseEvent>() {
#Override
public void handle(final MouseEvent event) {
if (event.getButton() == MouseButton.PRIMARY) {
// ...
}
else if (event.getButton() == MouseButton.SECONDARY) {
// ...
}
}
});
What do I have to add to make right clicks visually click myButton?
That visual appearance of button click is usually referred as "armed" pseudo state. So you can turn on/off the armed pseudo state of the button when doing right button pressed&released.
Something like..
myButton.setOnMousePressed(e->{
if(e.getButton()== MouseButton.SECONDARY){
myButton.pseudoClassStateChanged(PseudoClass.getPseudoClass("armed"), true);
}
});
myButton.setOnMouseReleased(e->{
if(e.getButton()== MouseButton.SECONDARY){
myButton.pseudoClassStateChanged(PseudoClass.getPseudoClass("armed"), false);
}
});
Updating the :armed pseudo class is not enough if you want the Button's action to be fired by a right click. You actually need to arm the Button. In other words, you need to make the armed property change to true. Also, updating the armed property will update the pseudo class for you.
As the armed property is read-only, you can't set it directly; you need to call arm() and disarm(). You may also need to manually call fire() (expanded on below). Here's an example:
Button button = new Button("Click Me!");
button.setOnAction(event -> System.out.println("Button clicked!"));
button.setOnMousePressed(event -> {
if (event.getButton() == MouseButton.SECONDARY) {
button.arm();
}
});
button.setOnMouseReleased(event -> {
if (button.isArmed()) {
button.disarm();
button.fire();
}
});
However, you don't appear to need the onMouseReleased handler at all—at least in JavaFX 11 and 12, using the default Button's skin/behavior. The Button's behavior class will fire the action if said Button is armed at the time the mouse is released (and no keys are down). Note that the default behavior class does a more complex check regarding which MouseButton was used (i.e. it does more then just check event.getButton() == MouseButton.PRIMARY). You can see the implementation for yourself here.
All that said, if you only want the visuals to change then you should use the approach shown in Sai's answer.
Im finding it hard to select the items from the combobox element. This combobox is something different. When i drag down the items, i could see the actual value of the item(i.e. aria-activedescendant="react-select-4--option-3"). After selecting the particular item, the value has got changed to "aria-activedescendant="react-select-4--value"". Plz suggest me the best solution to click the item. You have to specifically note this "aria-activedescendant="react-select-4--value"" in input section under html code.
Tried with below code. I was able to just click the combo box element but not the value. I used id="react-select-4--value" to click the combo box, It errors as "element not clickable at point". Technically the system understands something wrong.
public void ScrollAndClickOnElement(String loacator,String LocatorValue)
{
WebElement element = null;
if(loacator.equalsIgnoreCase("cssSelector"))
element = driver.findElement(By.cssSelector(LocatorValue));
else if(loacator.equalsIgnoreCase("xpath"))
element = driver.findElement(By.xpath(LocatorValue));
else if(loacator.equalsIgnoreCase("id"))
element = driver.findElement(By.id(LocatorValue));
((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView(true);",element);
element.click();
}
public void WaitAndClickElement(String locatorType,String locatorVaue)
{
WebDriverWait wait = new WebDriverWait(driver,50);
if(locatorType.equalsIgnoreCase("cssSelector"))
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(locatorVaue))).click();
else if(locatorType.equalsIgnoreCase("xpath"))
wait.until(ExpectedConditions.elementToBeClickable(By.xpath(locatorVaue))).click();
else if(locatorType.equalsIgnoreCase("id"))
wait.until(ExpectedConditions.elementToBeClickable(By.id(locatorVaue))).click();
}
ScrollAndClickOnElement("id", AssessmentPageData.ElevatorManufacturer);
WaitAndClickElement("cssSelector",AssessmentPageData.Appollo);
Referred to this link and used 'select' method, but it errors as "Element should have been "select" but was "span""
Found the below solution finally,
public void SelectBootStrap(String textval){
WebElement listElement = driver.findElement(By.xpath("//div[#class='Select-menu-outer']//div[text()='"+textval+"']"));
((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView(true);",listElement);
listElement.click();
}
I have StaticText fields in my flash project and I need to run some code when the mouse is hovering over them. So I tried this code
stage.addEventListener(MouseEvent.MOUSE_OVER, mouseRollOver);
function mouseRollOver(event:MouseEvent):void {
var tf:StaticText = event.target as StaticText;
if (tf){
//my code
}
}
but it doesn't work. When I use dynamic text fields and replace StaticText with TextField in the var tf, it works fine. I also thought that I could get this thing working with static text fields if I could make the mouse detect not StaticText as a target but some kind of object that has certain text properties (like "selectable" set to true), but I couldn't figure out how to do this. Anyway, I need to detect a static text field as a target somehow. Any help would be appreciated.
Thanks in advance
Your best option would be to put the static text box in a movieclip, and then assign your code based around that. Static text boxes don't have instance names, and can't be manipulated.
It is hard to do this. See this link enter link description here
As you can see you can check if the DisplayObject is StaticText and by checking the mousX and MouseY properties you can find if the rollover is related to this field. By if you use Dynamic text and uncheck selectable field you will get a textfield that acts as StaticField
EDIT
this is an explanation what I mean:
Let we have a StaticText field into stage in Black flash document.
var myFieldLabel:StaticText
var i:uint;
//This for check for all staticFields in state and trace its text. It is possible and it is working. I my case I have only one field and I get reference to it in myFieldLabel:StaticText var. Also I change it's alpha to 0.3.
for (i = 0; i < this.numChildren; i++)
{
var displayitem:DisplayObject = this.getChildAt(i);
if (displayitem instanceof StaticText) {
trace("a static text field is item " + i + " on the display list");
myFieldLabel = StaticText(displayitem);
trace("and contains the text: " + myFieldLabel.text);
trace( myFieldLabel.mouseX);
myFieldLabel.alpha = 0.3;
}
}
//Adds event listener to the stage for mouse move event
stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseRollOver);
//This is an event handler. I check if the mouse position is within the static field
function mouseRollOver(evnt:MouseEvent):void
{
if ( 0 <= myFieldLabel.mouseX && myFieldLabel.mouseX <= myFieldLabel.width && 0 <= myFieldLabel.mouseY && myFieldLabel.mouseY <= myFieldLabel.height )
{
mouseOverStaticText( evnt)
}
else
{
mouseNotOverStaticText( evnt)
}
}
// this two methods change the static field alpha. Thay are only to show that is posible to detect and manipulate some properties of the StaticField.
function mouseOverStaticText( evnt)
{
myFieldLabel.alpha = 1;
}
function mouseNotOverStaticText( evnt)
{
myFieldLabel.alpha = 0.3;
}
I'm not sure what is the purpose of the managing of the StaticText field. StaticText is not design to be managed if you have to do something this is almost sure that the field must not be a static - they can be dynamic ( without selectible property ) or can be capsulated with MovieClip or there can be a different solution in your case.
I have a webpage with a flash header. In the flash header (block), different dropdownmenus are present together with a 'submit' button.
When the user presses 'enter', i want to submit the form.
However, I can't seem to be able to catch any key :
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDownFunc);
root.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDownFunc);
optiesPanelNew.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDownFunc);
optiesPanelNew.ddOptiesMerk.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDownFunc);
function onKeyDownFunc(evt)
{
if (evt.keyCode == Keyboard.ENTER)
{
submitForm();
}
}
This javascript works if the html part of the page (non flash) has focus :
document.body.onkeydown = function theFunction()
{
alert("keydown");
}
Edit: Oh no, the flash file was written in AS2 ... sorry :-/
FYI : the code I ended up using was : (AS2) :
var keyListener:Object = new Object();
keyListener.onKeyDown = function():Void
{
if(Key.getCode()==13)
submitForm();
}
Key.addListener(keyListener);
I think you need to specify the event's type in the handler (i.e. KeyboardEvent) because this way the dispatched object will be cast to a Event object when its instance is passed to the handler. The Event class doesn't have the keyCode property, and subsequently the condition to submit the form is not met. That's why the form doesn't get submitted.
So, try replacing the
function onKeyDownFunc(evt)
line, with
function onKeyDownFunc(evt:KeyboardEvent)
and it should do the trick.
Have a great day.
I am trying to cancel a tooltip event (I only want it to display when the mouse is hovered over a certain area), and can't seem to figure it out. I tried stopPropagation, preventDefault, and stopImmediatePropagation, but none of them seem to work.
Here the code I am using:
private function toolTipCreateHandler(event:ToolTipEvent):void {
if(event.currentTarget.mouseX < 130) {
var tooltip:PhotoToolTip = new PhotoToolTip();
tooltip.src = event.currentTarget.toolTip;
event.toolTip = tooltip;
}
else {
event.stopImmediatePropagation();
}
}
Any ideas?
Thanks
Step one, add an event listener to detect when the mouse leaves the area you want the tooltip, run a function and title it something like "toolTipDestroyer"
Step two, You need to call the destroy method of the tooltip manager
private function toolTipDestroyer():void {
if (myToolTip) {
ToolTipManager.destroyToolTip(myToolTip);
myToolTip= null;
}
}
Also, just for readability, give your tooltip some other name than "tooltip", you'll find it easier to follow up on your code later. My example names it "myToolTip"