Announcement

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

    PortalLayout problem override of getDropComponent

    I am using SC_SNAPSHOT-2011-01-04/PowerEdition.

    I am trying to override the getDropComponent method of PortalLayout to create a new Window to add rather than the button I drag to the layout. I can get this to work with I override the method in Layout, but cannot get it to work in PortalLayout.

    Here is code to reproduce the problem:

    Code:
    public void onModuleLoad() 
    	{
    		final Canvas mainCanvas = new Canvas();
    		mainCanvas.setHeight100();
    		mainCanvas.setWidth100();
    		mainCanvas.setBackgroundColor("palegreen");
    
    		mainCanvas.addChild(createDragDropTester());
    		
    		mainCanvas.draw();
    	}
    
    	
    	private HLayout createDragDropTester()
    	{
    		
    		final VLayout left = new VLayout();
    		left.setHeight100();
    		left.setWidth("20%");
    		left.setBackgroundColor("whitesmoke");
    		left.setMembersMargin(10);
    		
    		IButton button = new IButton("drag me");
    		button.setCanDrag(true);
    		button.setCanDrop(true);
    		button.setDragAppearance(DragAppearance.OUTLINE);
    		button.setDragType("Portlet");
    
    		
    		left.addMember(button);
    		
    		final VLayout right = new VLayout();
    		right.setHeight100();
    		right.setWidth("*");
    		
    		final Layout layout = new Layout() {
    			@Override
    		    protected Canvas getDropComponent(Canvas dragTarget, int dropPosition) {
    				Canvas canvas = super.getDropComponent(dragTarget, dropPosition);
    				
    				SC.logWarn("layout gDc:" + canvas.getClass());
    				final Window window = new Window();
    				window.setWidth(100);
    				return window;
    
    //				return canvas;
    			}
    		};
    		layout.setWidth100();
    		layout.setHeight100();
    		layout.setCanAcceptDrop(true);
    		layout.setCanDropComponents(true);
    		layout.setBackgroundColor("azure");
    		
    		right.addMember(layout);
    		
    		final PortalLayout playout = new PortalLayout(2) {
    			@Override
    		    protected Canvas getDropComponent(Canvas dragTarget, int dropPosition) {
    				Canvas canvas = super.getDropComponent(dragTarget, dropPosition);
    				
    				SC.logWarn("PLAYOUT gDc:" + canvas.getClass());
    				
    				final Window window = new Window();
    				return window;
    
    //				return canvas;
    			}
    		};
    		playout.setWidth100();
    		playout.setHeight100();
    		playout.setCanAcceptDrop(true);
    		playout.setCanDropComponents(true);
    		playout.setBackgroundColor("beige");
    		right.addMember(playout);
    		
    
    		final HLayout hlayout = new HLayout();
    		hlayout.setMargin(10);
    		hlayout.setWidth100();
    		hlayout.setHeight100();
    		hlayout.addMember(left);
    		hlayout.addMember(right);
    				
    		return hlayout;
    	}
    }
    When I drag the "drag me" button to the Layout canvas, it creates a new Window. When I drag the "drag me" button to the PortalLayout canvas, it drops the button. It seems to ignore the getDropComponent override.

    #2
    I have tried this now against SC_SNAPSHOT-2011-01-31/PowerEdition and see the same problem with the PortalLayout getDropComponent override not being used.

    Comment


      #3
      getDropComponent() is not set up as an override point on PortalLayout because PortalLayout's drag and drop behavior is rather different from the base Layout component. What are you trying to do?

      Comment


        #4
        I need a means to drag-and-drop a widget (such as a button, label, or image) from a Canvas onto a PortalLayout and have it create a Portlet that was represented by it.

        Comment


          #5
          There basically is not currently an API that would allow you to cleanly auto-generate a Portlet around a dropped Canvas - the PortalLayout expects that whatever is dropped is already a Portlet.

          A moderately bad hack could be added where you directly add event handlers to the PortalLayout's generated subcomponents so that you can see when a new component has been added, then remove this component immediately and replace it by calling addPortlet() with the component wrapped in a Portlet.

          Or, we could add new APIs for you - a good approach here would be to discuss the broader use case, discover all the new APIs that may be needed, and implement those as a sponsorship.

          Comment

          Working...
          X