GwtMaterialDesign / gwt-material

A Google Material Design wrapper for GWT
https://gwtmaterialdesign.github.io/gmd-core-demo/
Apache License 2.0
412 stars 124 forks source link

Provide support to popup menus #993

Open Oberonc opened 3 years ago

Oberonc commented 3 years ago

One of the things I feel is missing in your framework is an example on how to use a drop down menu (popup menu). Suppose I capture a right click ("contextmenu") event and want to provide my own menu instead of the browser default. How do I do that ?

kevzlou7979 commented 3 years ago

As I remember we have implemented this to addins (We call it MaterialPopupMenu - See here. YOu can call setPopupPosition(int popupX, int popupY) to specify the position of the popup then you will need to listen to the context menu and prevent the default behaviour.

Oberonc commented 3 years ago

I have a problem using that widget inside a context menu event handler

The following native GWT code works:

                                   PopupPanel popup = new PopupPanel(true);
                MenuBar menu = new MenuBar(true);

                menu.addSeparator();

                popup.add(menu);

                popup.setPopupPosition((int)clicked.getPointer().getDOM().getX(), (int)clicked.getPointer().getDOM().getY());
                popup.show();

.. and the following code does nothing visible:

                MaterialPopupMenu popupMenu = new MaterialPopupMenu();
                popupMenu.setPopupPosition((int)clicked.getPointer().getDOM().getX(), (int)clicked.getPointer().getDOM().getY());

                MaterialLink pdfLink = new MaterialLink();
                pdfLink.setPadding(12.0);
                pdfLink.setDisplay(Display.BLOCK);
                pdfLink.setText("Export as PDF");
                pdfLink.setIconType(IconType.PICTURE_AS_PDF);
                pdfLink.setTextColor(Color.BLUE);

                popupMenu.add(pdfLink);

                    popupMenu.open();

I saw this code here: https://www.javatips.net/api/ABMS-master/Abms/src/main/java/com/andreiolar/abms/client/widgets/PersonalCostsWidget.java

I see no errors in the browser console.

Any idea why I dont see any popup ?

kevzlou7979 commented 3 years ago

I think I used the native context-menu event from Javascript and JInterop it. You can DIY it using this link https://stackoverflow.com/questions/36307167/using-jquery-how-to-get-right-click-coordinates-on-the-target-element and wrap those methods to JSInterop.