Announcement

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

    Dragging content onto LayoutPortal

    I'd like to be able to create portlets at runtime by dragging items onto a portal layout like shown in http://www.smartclient.com/#portletContentsDragging & http://www.smartclient.com/#portal on the examples site. But It won't work.

    I've created a menu button with a menu that contains a couple MenuItems for testing. Then in the PortalLayout I've overriden getDropPortlet to create a portlet based on which menu item was dragged. The problem is that the MenuItem is not whats being dragged instead its the entire menu, so in getDropPortlet I have no idea which type of portlet to create. I can create an empty portlet and add it but its not related to the menuItem. I've tried menu.getDragData() but that either returns null or all of the records of a menu. Any advice or suggestions would be appreciated.

    GWT 2.4, SmartGWTEE 3.0p

    Thanks,
    Chris

    Code:
    public Canvas getDropPortlet(Canvas dragTarget, Integer colNum, Integer rowNum, Integer dropPosition)  {
    		if (dragTarget.getID() == "ConfigureMenu") {
    //In here I need to know what menu Item was dragged into the PortalLayout but right now its just the entire menu
    			Menu dragMenu = (Menu)dragTarget;
    			Record[] recs = dragMenu.getDragData();
    			return new Portlet();
    		}
    		else
    			return super.getDropPortlet(dragTarget, colNum, rowNum, dropPosition);
    	}
    Code:
                    MenuButton menuBtn = new MenuButton("Configure Layout");
    		menuBtn.setSnapTo("BR");
    		Menu configureMenu = new Menu();
    		configureMenu.setID("ConfigureMenu");
    		configureMenu.setDragType("Portlet");
    		configureMenu.setAnimateFadeTime(250);
    		configureMenu.setShowAnimationEffect("slide");
    		configureMenu.setCanDragRecordsOut(true);
    		configureMenu.setSelectionType(SelectionStyle.SIMPLE);
    		
    		MenuItem mi = new MenuItem("Chart");
                    mi.setCanDrag(true); //this has no affect
                    MenuItem mi2 = new MenuItem("Table");
    		
    		configureMenu.addItem(mi);
                    configureMenu.addItem(mi2);
    		configureMenu.setDragDataAction(DragDataAction.COPY);
    		
    		configureMenu.addDragStartHandler(new DragStartHandler() {
    
    			@Override
    			public void onDragStart(DragStartEvent event) {
    				Menu menu = (Menu)event.getSource();
    				//menu.selectRecord(0);
    				menu.animateHide(AnimationEffect.FADE, new AnimationCallback () {
    
    					@Override
    					public void execute(boolean earlyFinish) {
    						Menu.hideAllMenus();
    					}
    				});
    			}
    		});
    		
    		menuBtn.setMenu(configureMenu);

    #2
    Among other solutions, you could just track the most recent item to receive mouseDown.

    Comment


      #3
      Yes that is a solution that I'll look into today. But I was hoping to get it to work as simply as the examples make it look. Why can't I just drag a MenuItem? In one of the examples a MenuPalette is used. But I cannot find this object defined anywhere. Is there more to the examples than what is being shown?

      Thanks,
      Chris

      Comment


        #4
        Ok so I've made some progress only to run into another problem. I changed how I was adding the the MenuItems to the menu and it made a huge difference. Instead of using setItem I used setData.
        New code below:

        Code:
        MenuItem mi = new MenuItem("Chart");
        MenuItem mi2 =  new MenuItem("Table");
        MenuItem mi3 =  new MenuItem("Map");
        		
        configureMenu.setData(mi, mi2, mi3);
        Now in getDropPortlet the getDragData function returns the MenuItem that is being dragged. But it only works properly the first time. Steps below:

        1) Drag MenuItem Map and getDragData returns Map
        2) Drag MenuItem Table and getDragData returns Table
        3) Drag MenuItem Map again and getDragData returns Table; not what its supposed to return. After this point I can never get it to return map again.
        4) Drag MenuItem Chart and getDragData returns Chart but now if I try to drag either Map or Table getDragData will only return Chart from here on out.

        Am I doing something wrong? Do I need to reset the list somehow after a drag operation?

        Thanks,
        Chris

        Comment


          #5
          I've come up with a solution that I'll post in case someone else runs into the same problems I've had. You need to override the addDragStopHandler of the menu and reset all of the records. It feels like a hack, but it works for now. Hope this helps others.

          Code:
          configureMenu.addDragStopHandler(new DragStopHandler () {
          
          @Override
          	public void onDragStop(DragStopEvent event) {
          		Menu menu = (Menu)event.getSource();
          		ListGridRecord[] recs = menu.getRecords();
          		menu.setData(recs);
                  }
          });

          Comment

          Working...
          X