gwt-material icon indicating copy to clipboard operation
gwt-material copied to clipboard

Provide support to popup menus

Open Oberonc opened this issue 5 years ago • 3 comments

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 ?

Oberonc avatar Dec 06 '20 19:12 Oberonc

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.

kevzlou7979 avatar Dec 07 '20 21:12 kevzlou7979

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 ?

Oberonc avatar Dec 08 '20 22:12 Oberonc

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.

kevzlou7979 avatar May 28 '21 00:05 kevzlou7979