I want to avoid Mouse click event handled by both child and parent handlers in javafx 8 - javafx-2

Currently in my javafx program I have structure like
AnchorPane[Parent] - > Group[Child] ... Both have setOnMouseClicked event code..
My problem is When click on child node, child node's setOnMouseClicked executed first and then Parent node's setOnMouseClicked gets executed ...
Now I have situation where I want to have functionality like
If child node's setOnMouseClicked is executed then
Parent node's setOnMouseClicked should not get executed ..
How do I achieve this ? For more information please check below image.
Now if I click on parent node - > selected child node should be deselected .. So I write parent Node.setOnMouseClicked -> de-select child node ..
But even when I click on child node to select it - > it also execute parent node's setOnMouseClicked - > And immediately deselect the child node ..
I find this problem as an architectural issue so as not posting code example.
Please let me know your valuable suggestions. Your help would be highly appreciated.

Here is a small example of consuming events - events that have been consumed will not bubble through to the next listeners:
#Override
public void start(Stage stage) throws Exception {
Canvas c = new Canvas(400, 400);
Pane p = new Pane(c);
p.setOnMouseClicked(me -> {
System.out.println("Pane mouse click: " + me.getX() + ", " + me.getY());
});
c.setOnMouseClicked(me -> {
System.out.println("Canvas mouse click: " + me.getX() + ", " + me.getY());
if (me.getX()>200) {
System.out.println("Consuming event");
me.consume();
}
});
stage.setScene(new Scene(p));
stage.show();
}
When clicking the left part and then the right part of the Canvas you will get something like this:
Canvas mouse click: 96.0, 174.0
Pane mouse click: 96.0, 174.0
Canvas mouse click: 373.0, 180.0
Consuming event
Notice how the second time the Pane event listener wasn't executed. Of course, you can use any logic to decide whether you consume the event.

Related

Focus, blur, focusin, focusout, don't work with D3 and SVG Elements? Is there an alternative?

I'm using the d3 library to create a widget within a SVG. Within the SVG I'm trying to do the following:
There are small rectangles that are clickable. Once clickable, they should "enlarge" and show some input fields. When I click outside the rectangles I want them to "un-enlarge" and remove the input fields again.
Small rectangle:
Once clicked, they enlarge (no input fields yet):
When I click outside of the white rectangle, I want it to revert back to picture 1:
I trigger the enlargement with an on click event:
let whiteRect = node.append("g")
.on('click', function(a) {
// Trigger enlarge function
return a;
})};
And I would like to trigger the "click outside" using a blur or focusout event. But this doesn't seem to work for SVG. Something like this:
let whiteRect = node.append("g")
.on('blur', function(a) {
// Trigger "un-enlarge" function
return a;
})};
I've been doing some searching, and it seems that in SVG 2 this might be supported, but this doesn't seem to be implemented by any browsers.
Anyone have an idea how I could implement this? I know I can add an onclick event listener for the whole SVG and write some logic there to identify if I'm clicking on an enlarged rectangle. But I'd prefer using something easier like blur or focusout if possible. Any ideas?
Shortly after posting I found this tutorial on focusing svg elements: https://allyjs.io/tutorials/focusing-in-svg.html
Turns out if you add a focus event to an element it becomes focusable and also gets a blur event. So what I did was add an empty focus event to be able to use the blur.
let whiteRect = node.append("g")
.on('click', function(a) {
// Trigger enlarge function
return a;
})}
.on('focus', function(a) {
// Empty focus event
return a;
})}
.on('blur', function(a) {
// Trigger un-enlarge function
return a;
})};
Which worked for me.

Problem with a non-modal, self-closing dialog in combination with other dialogs

It is about a MFC-MDI application. I have added a popup window, which should be closed after some duration. Therefore, I create a non-modal dialog
CPopupDlg* pDlg = new CPopupDlg(this);
if (pDlg)
{
pDlg->Create(IDD, this);
pDlg->ShowWindow(SW_SHOW);
}
It will be closed by a Timer and destroyed in OnNcDestroy()
void CPopupDlg::OnTimer(UINT_PTR nIDEvent)
{
if (nIDEvent == m_CounterEventID)
{
KillTimer(nIDEvent);
EndDialog(IDCANCEL);
DestroyWindow();
}
}
void CPopupDlg::OnNcDestroy()
{
__super::OnNcDestroy();
delete this;
}
My problem are many other (modal) dialogs and message boxes, which may appear, while the CPopupDlg is open. These modal dialogs often does not specify a parent window in my project (CDialogconstructor with pParentWnd=NULL). Hence, the method CDialog::DoModal() use ::GetLastActivePopup() to determine its parent window. The CPopupDlg dialog is chosen as the parent window. As a consequence, DoModal() crashes, when the CPopupDlg window is closed by the timer.
How can I tackle this problem?
Is there a way to exclude the CPopupDlg dialog from the results of ::GetLastAcitvePopup()?
Sometimes I have seen, that non-modal dialogs uses RunModalLoop(). Would this be the solution?
popupDlg.Create(IDD, this);
popupDlg.RunModalLoop(MLF_SHOWONIDLE);
popupDlg.DestroyWindow();
What would happen, if the popup dialog would never be closed and destroyed, but only hidden. Would other modal dialog windows, which are undesired childs of the CPopupDlg wnd, also disappear, if popupDlg.ShowWindow(SW_HIDE) is called?
My solution is to create the popup window as a separate desktop child window. It is not a child window of the application and will not be chosen by ::GetLastActivePopup().
CPopupDlg* pDlg = new CPopupDlg(this);
if (pDlg)
{
pDlg->Create(IDD, GetDesktopWindow());
pDlg->ShowWindow(SW_SHOW);
}

Update main window DOM from other window in electron js

Let's take a TODO app as example, there is a Main window - A, that will list all of the TODO items and a button 'Add Item'. So when click on the 'Add Item' , it will open up a second window - B, where there is a form for adding item. After the form is submitted, the newly added item will be append to the list in WIndow A.
So the problem here is, how can I update the Item list in WIndow A when when WIndow B form is submitted? I am using react js for the renderer. So, how can react component listen to the changes?
Ok, got the answer.
Turn out we can use webContents to send the message to the desired window. And that message can be listened in the window.
#main.js
mainWindow = new BrowserWindow({width: 800, height: 600});
mainWindow.webContents.send('addingitem','...blahblah balh ');
and in render
ipc.on("addingitem", (event, arg)=>{
//doing the update DOM here.
}

dijit menu onmouseover

I am using menu using dijit.menu and Its work with right click and left click.
How I open the menu on mouse over and close on onmouseout?
dijitActionMenu = new dijit.Menu({
targetNodeIds:[actionMenuId],
leftClickToOpen:"true"
});
Have you tried something like
// Create a new Tooltip
var tip = new dijit.Tooltip({
// Label - the HTML or text to be placed within the Tooltip
label: '<div class="myTipType">This is the content of my Tooltip!</div>',
// Delay before showing the Tooltip (in milliseconds)
showDelay: 250,
// The nodes to attach the Tooltip to
// Can be an array of strings or domNodes
connectId: ["myElement1","myElement2"]
});
More details are here dialogs_tooltips.Even dijit.Menu have onMouseOver even.
onMouseOver Event
I am able to get the dijit/Menu onmouseover.
Create an element which will invoke onmouseover event.
Element
show() will call custom widget which will create menu for you.
E.g.,
show = function() {
var roll = new rollover()
}
And rollover.js will be the custom widget.
From the constructor of it, you can invoke the function and create the menu.
pMenu = new Menu({ class: "rollovermenu", id: "rolloverid" });

Can WatiN handle the CuteWebUI Uploader popup dialog?

My Background:
I am new to WatiN, but not new to writing automated Web UI tests. At my new job, we are trying to use WatiN for our Web UI tests (thanks to a few CUIT fails).
I've solved this problem in the past using ArtOfTest.WebAii, by using a Win32 mouse click with a magic number offset from the containing element, but I can't seem to find documentation on how to do that in WatiN and I can't figure it out myself :\
My problem:
This dialog appears and I can't seem to find a way for WatiN to click it.
The dialog has the following markup:
<OBJECT style="FILTER: alpha(opacity=1); WIDTH: 329px; HEIGHT: 100px; mozOpacity: 0.01; opacity: 0.01; mozopacity: 0.01" data="data:application/x-oleobject;base64, <a bunch of data>" width=329 height=100 type=application/x-silverlight-2></OBJECT>
<param name="source" value="/CuteWebUI_Uploader_Resource.axd?type=file&file=silverlight.xap&_ver=634334311861475176"/>
<param name="windowless" value="true" object="" <=""/>
my test code:
[TestMethod]
public void SomeTest()
{
Settings.MakeNewIeInstanceVisible = true;
Settings.AutoStartDialogWatcher = true;
Settings.AutoMoveMousePointerToTopLeft = false;
using (IE ie2 = new IE())
{
ie2.GoTo(URL);
ie2.Link(SomeButtonID).Click();
ie2.Image(AnotherButtonID).FireEvent("onclick");
// some debugging code wrapped around the next user action
// which is clicking on the attach file button
var helper = new DialogHandlerHelper();
using (new UseDialogOnce(ie2.DialogWatcher, helper))
{
Thread.Sleep(1 * 1000); // wait for attach button to be "ready"
// Click button that triggers the dialog that states:
// "file browsing dialog has been blocked"
// "please click here and try again"
//
ie2.Button(FileAttachButtonID).FireEvent("onclick");
}
foreach(string dialogHandler in helper.CandidateDialogHandlers)
{
// nothing prints out here :(
Console.Out.WriteLine(dialogHandler);
}
// debug print out all elements with tagname = object
foreach (Element objectElement in ie2.ElementsWithTag("object"))
{
StringBuilder elementInfo = new StringBuilder();
elementInfo.AppendLine("--------------------------------------------");
elementInfo.AppendLine("element.tagname = " + objectElement.TagName);
elementInfo.AppendLine("element.style = " + objectElement.Style);
elementInfo.AppendLine("element.type = " + objectElement.GetAttributeValue("type"));
elementInfo.AppendLine("element.data = " + objectElement.GetAttributeValue("data"));
elementInfo.AppendLine("--------------------------------------------");
Console.Out.WriteLine(elementInfo.ToString());
// none of these clicks make the dialog go away
objectElement.ClickNoWait();
objectElement.Click();
objectElement.DoubleClick();
objectElement.MouseEnter();
objectElement.MouseDown();
Thread.Sleep(500);
objectElement.MouseUp();
}
// wait to see if dialog disappears after click
Thread.Sleep(300 * 1000);
}
}
Any and all help will be very much appreciated.
Thanks!
Your control is a silverlight component which can't be automated with WatiN. Fortunately this you can combine WatiN and White to get the job done.
Following code is created and published by Leo Bartnik so ALL the credits go to him! Have a look at his blog post here. The following code in the comments:
He used the following versions.
watin-2.0.50.1179.zip from 2011-02-08 http://sourceforge.net/projects/watin/files/WatiN%202.x/2.0%20Final/
white 0.20 Binaries http://white.codeplex.com/releases/view/29694
public void WatiN_and_White_join_forces()
{
// Navigate to your webpage with WatiN
string url = "http://localhost[port#]/WatinWhiteTestLandingPage.aspx";
WatiN.Core.IE watin = new WatiN.Core.IE(url);
watin.Link(Find.ByText("click here)).Click();
// Attach the IE instance used by WatiN to White
InternetExplorerFactory.Plugin();
string title = "[browser title here]"; // will be something like "WatinWhiteHybrid - Internet Explorer provided by ..."
var ie = (InternetExplorerWindow)Application.Attach(watin.ProcessID).GetWindow(title);
White.WebBrowser.Silverlight.SilverlightDocument sl = ie.SilverlightDocument;
// Click the button in the silverlight control using White
sl.Get(SearchCriteria.ByAutomationId("ClickMeId")).Click();
}
btw don't know why the formating of this code is so way off....
So this was my hack solution:
Use Microsoft's Coded UI Test to click on the Silverlight dialog. However, CUIT is inferior to WatiN, so I run my test in WatiN and load CUIT for one, magical, click.
Additionally, I was not able to easily find the Silverlight object using CUIT, so I find the window behind it, find the window's center pixel and force a Microsoft.VisualStudio.TestTools.UITesting.Mouse.Click(). Yes, a hack inside of a hack, I am a very bad person, but I ran out of time and just needed something working.
If anyone has a more elegant solution, please share.
My solution code:
FileUploadDialogHandler helper = new FileUploadDialogHandler(attachmentPath);
using (new UseDialogOnce(ie.DialogWatcher, helper))
{
Thread.Sleep(1 * 1000); // wait for attach button to be "ready"
ie.Button(browseButtonID).FireEvent("onclick");
// When automating a file upload, there is a Silverlight popup in IE that forces an extra click
// before opening the file open dialog. WatiN does not support Silverlight automation
// and the popup element was acting quirky in Microsoft's Coded UI Test, so we find the
// dialog box UNDERNEATH the Silverlight popup and force one, lovely, mouse click.
//===== Entering Coded UI Test land, beware! =====================================
// initialize Coded UI Test
Playback.Initialize();
BrowserWindow.CurrentBrowser = "IE";
Process watinBrowserProcess = Process.GetProcessById(ie.ProcessID);
BrowserWindow cuitBrowser = BrowserWindow.FromProcess(watinBrowserProcess); // attach Coded UI Test to the IE browser WatiN initialized
// get the window underneath the Silverlight popup
UITestControl modalUnderSilverlightPopup = new UITestControl(cuitBrowser.CurrentDocumentWindow);
modalUnderSilverlightPopup.SearchProperties.Add("id", windowElementUnderPopupID);
// get the X and Y pixel center of the window
int centerX = modalUnderSilverlightPopup.BoundingRectangle.X + modalUnderSilverlightPopup.BoundingRectangle.Width / 2;
int centerY = modalUnderSilverlightPopup.BoundingRectangle.Y + modalUnderSilverlightPopup.BoundingRectangle.Height / 2;
// Click!
Mouse.Click(new Point(centerX, centerY));
// Shutdown Coded UI Test
Playback.Cleanup();
//===== End Coded UI Test land, you survived! yay! ============================
}

Resources