Announcement

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

    Drag and drop for menu items

    Hi,

    I am using SmartClient Version: v8.2p_2012-04-02/LGPL Development Only (built 2012-04-02).
    I am trying to make drag and drop menu item sorting. Here is my sample code, to illustrate basic code structure:
    Code:
            // menu
            ToolStrip toolstrip = new ToolStrip();
    
            // 1st level buttons
            ToolStripButton button1 = new ToolStripButton("File", null);
            button1.setCanDrag(true);
            button1.setCanDrop(true);
            toolstrip.addButton(button1);
    
            // submenu
            Menu submenu = new Menu();
            MenuItem item1 = new MenuItem("Button 1");
            MenuItem item2 = new MenuItem("Button 2");
            submenu.setItems(item1, item2);
    
            ToolStripMenuButton menuButton = new ToolStripMenuButton("Show menu", submenu);
            toolstrip.addMenuButton(menuButton);
    As far as I found - you can easily make draggable ToolStripButton (button1) item, but when I want to make the same functionality for item1 and item2 (which are items of submenu), then I can't find any suitable methods of doing it.
    OK, I found one example: http://www.smartclient.com/smartgwt/showcase/#effects_drag_menu_grid
    But when looking closer - this menu is not the same as normal menu, in this example there is menu created from datasource and it even doesn't contain valid menuitems, but list grid instead, so this is not a right method for me.
    In conclusion, I am wondering - why there is no drag and drop support for typical menu items. Or maybe there is some workaround to do so?

    #2
    There is a way around it.

    At first you need to make submenu items draggable:
    Code:
    submenu.setCanDragRecordsOut(true);
    submenu.setSelectionType(SelectionStyle.SINGLE);
    submenu.setDragDataAction(DragDataAction.COPY);
    Afterwards add DropHandler on widget you want to drag your submenu items to
    Code:
    new DropHandler() {
    	@Override
    	public void onDrop(DropEvent event) {
    		Object target = EventHandler.getDragTarget();
    		if (target instanceof Menu) {
    			ListGridRecord lgr = ((Menu) target).getSelectedRecord();
    			if (lgr instanceof MenuItem) {
    				// Do what you need to do with your submenu item
    			}
    		}
    	}
    }

    Comment

    Working...
    X