Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Adding Menu to SectionStack header

    Hey All,

    I have a requirement to add a menu to a sectionstack header and I am running into some trouble. There is no setContextMenu() method on section stack so instead I am adding a right mouse handler, and building a menu myself at the given coordinates for the event. This works fine only(!) in Chrome when compiled, and in IE and Firefox when I don't use any of the SmartGWT themes. When I do use the themes IE will first show the Menu and then show the regular browser right-click menu on top of it, and ask me if I want to save an image. Firefox does not show the GWT menu but shows its right click menu as well. The image to be saved is blank.gif, and when looking at the javascript for SectionStack it seems like there is some magic going on with CSS/JS and the header portion of the stack when using Themes.

    So, I am a little stuck as to how to proceed. I need to use the TreeFrog theme but I also need this to work in IE and FireFox, not just Chrome. I have tried event.cancel() to no avail and I think this menu is popping up from the blank.gif image (CSS/JS magic) and not anything GWT related.

    Any Ideas for making this work?

    Sample code that fails with TreeFrog but works when no theme specified.

    Code:
    /**
     * Entry point classes define <code>onModuleLoad()</code>.
     */
    public class SmartTest implements EntryPoint {
    
    	
    	public void onModuleLoad() {
    	     	final HLayout hLayout = new HLayout();
    	     	hLayout.setHeight100();
    	     	hLayout.setWidth100();
    
    	     	SmartGridPanel panel = new SmartGridPanel("testing");
    	     	
    	     	
    	     	hLayout.addMember(panel);
    	     	hLayout.draw();
    	}
    
    
    private class SmartGridPanel extends SectionStack
    {
    	
    		private VLayout vLayout = new VLayout();
    		private SectionStackSection section = new SectionStackSection();
    
    		private String name = null;
    
    		
    		
    		public SmartGridPanel(String category)
    		{
    			
    			vLayout.setHeight100();
    			vLayout.setWidth100();
    			
    			this.setHeight100();
    			this.setWidth100();
    			
    			
    			this.name = category;
    
    			section.setTitle(category);
    			section.setCanCollapse(false);
    		
    			
    			Label label = new Label(category);
    			vLayout.addMember(label);
    			section.addItem(vLayout);
    			this.addSection(section);
    
    
    			
    			this.addRightMouseDownHandler(new RightMouseDownHandler(){
    				public void onRightMouseDown(RightMouseDownEvent event)
    				{
    					int z = SmartGridPanel.this.getZIndex();
    					GWT.log("z index is " + z, null);
    					event.cancel();
    					int panelY = SmartGridPanel.this.getAbsoluteTop();
    					int x = event.getX();
    					int y = event.getY();
    					
    					if(panelY + 30 < y)
    					{
    						GWT.log("right click was not on header, ignoring",null);
    						return;
    					}
    					
    					
    					GWT.log("right mouse down",null);
    					Menu menu = new Menu();
    					MenuItem item = new MenuItem("test");
    					menu.addItem(item);
    					menu.addRightMouseDownHandler(new RightMouseDownHandler(){
    						public void onRightMouseDown(RightMouseDownEvent event)
    						{
    							GWT.log("in menu handler",null);
    						}
    					});
    				
    					GWT.log("event x is " + x + " and y is " + y,null);
    					
    					menu.show();
    					menu.hide();
    					int width = menu.getWidth(); 
    					int height = menu.getHeight();
    					menu.setRect(x,y,width,height);
    					menu.show();
    				
    					GWT.log("event cancelled is " + event.isCancelled(),null);
    					
    					
    				}
    			});
    
    
    		
    		}
    
    	}
    }

    #2
    No "magic" involved, you just need to cancel contextClick instead of rightMouseDown in order to get rid of the context menu. This could be done via JSNI, but it seems like adding an icon or similar item to SectionStack.controls as a more obvious way of launching your menu would be better UI and avoid this issue?

    Comment


      #3
      Thanks, I think we will just go with extra controls instead of doing the right click menu.

      adrian

      Comment

      Working...
      X