JPro-one / JPro-Tickets

The right place to report about bugs or suggest improvements for JPro.
https://www.jpro.one
9 stars 4 forks source link

Context menus - isPopupTrigger always returns false #95

Open mipastgt opened 3 years ago

mipastgt commented 3 years ago

Whatever I do I can't get context menus to work. I have an application which normally displays a context menu when I click on a route point which I want to edit but when running with JPro no context menu is shown.

Bildschirmfoto 2021-04-20 um 16 54 45

I have configured the index.html file to use JavaFX context menus like this:

<jpro-app loader="none" href="/app/mpCoPilot" fullscreen="true" fxContextMenu="true" ></jpro-app>

What else can I do to get my context menus shown? To show the context menu I use a mouse handler like this:

        this.mousePressedHandler = e -> {
            if (e.isPopupTrigger()) {
                System.out.println("mousePressedHandler - e.isPopupTrigger()");
                showContextMenu();              
            } else {
                System.out.println("mousePressedHandler - NOT e.isPopupTrigger()");
            }
            e.consume();
        };

The problem seems to be that e.isPopupTrigger() always returns false because I always get the output

mousePressedHandler - NOT e.isPopupTrigger()

on the console.

I am running locally on a Mac with the following config:

[info] c.j.i.s.Initializer$ -  *** Starting JPro: https://www.jpro.one/ ***
[info] c.j.i.s.Initializer$ - OS: Mac OS X
[info] c.j.i.s.Initializer$ - JPro: 2021.1.0-PREVIEW2
[info] c.j.i.s.Initializer$ - Java version: 15.0.2
[info] c.j.i.s.Initializer$ - JVM: 15.0.2 Oracle Corporation
[info] c.j.i.s.Initializer$ - redirected OUT / ERR
[info] c.j.i.s.Initializer$ - installed SLF4JBridge
[info] c.j.i.s.MonocleInitializer$ - screen: null
[warn] javafx - Unsupported JavaFX configuration: classes were loaded from 'unnamed module @74e95e3d'
[info] c.j.i.s.Initializer$ - finished init!
[info] c.j.i.s.Initializer$ - JavaFX version: 16.0.0.1-jpro+0-2021-04-15-155901
FlorianKirmaier commented 3 years ago

I can confirm the problem. JPro uses Monocle to generate the MouseEvents. It seems like Monocle doesn't support isPopupTrigger and always returns false. But JPro creates ContextMenuEvent, which can be accessed by the method setOnContextMenuRequested

mipastgt commented 3 years ago

After changing my code accordingly it works now. Nevertheless this is not really nice because it makes the distinction between context menu handling and other mouse activities more difficult. I don't know much about Monocle but do you think this is a bug in it that should be filed or would you consider this as normal behaviour?

FlorianKirmaier commented 3 years ago

I would say it's a bug in Monocle. Someone marked the field "isPopupTrigger" with "ToDo", so someone planned to finish it. People using Monocle for UnitTests should encounter the same issue.

I've created a ticket for JavaFX: https://bugs.openjdk.java.net/browse/JDK-8265633

Currently JPro has special code to generate the ContextMenu, which would no longer be necessary after fixing this issue.