View Full Version : Beta 1 - Draggable.setContainer doesn't work properly?

29 Dec 2011, 9:32 AM
Ok, first, I'll admit that I don't know if this is a bug, or I'm doing something incorrectly and misunderstanding the purpose of Draggable.setContainer

So, I have my sample program, and the arrangement is as follows (as I've posted in another thread asking a different question:
- Add a Viewport to the RootPanel
- Add a TopBottomComponent to the Viewport
- Set the top widget of the TopBottomComponent component to a MenuBar
- Set the bottom widget of the TopBottomComponent component to a FlowLayoutContainer
- Set the widget of the TopBottomComponent to a ContentPanel

So, the MenuBar is on top, the FlowLayoutContainer is on bottom, and the ContentPanel takes up the remainder of the space in the middle.

Let's say the instance of ContentPanel is cp.

After this, I'm creating Window objects. For each window I do the following:

This makes sure that when I maximize the window, it doesn't cover the MenuBar or FlowLayoutContainer.

However, I also wanted to control the dragging, so that the window cannot be dragged over the MenuBar or the FlowLayoutContainer.

I have tried doing the following:
window.getDraggable().setConstrainClient(false); // so as to not constrain to the Viewport
window.getDraggable().setContainer(cp); // constrain to my ContentPanel

This, however, seems to have no effect.

I've also eliminated the setConstrainClient, again to no effect.

What am I doing wrong? How do I set the window object so that it does not allow the window to be dragged outside of cp (my ContentPanel instance)?

6 Jan 2012, 8:24 AM
I guess I'm just giving this one a bounce . . . really, if anything to find out if anyone knows: is this actually a bug, or am I just trying to accomplish my goal incorrectly?

(and, naturally, if the latter, then what's the correct way to do what I want?)

Colin Alworth
6 Jan 2012, 10:14 AM
Window.setContainer doesn't seem to be valid for a ContentPanel - instead, you need to pass an Element instance. For Window, as you noted, it appears only to have an effect when maximizing or restoring the Window. Passing window.setContainer(cp.getElement()) should constrain it to the full bounds of the content panel, whereas window.setContainer(cp.getBody()) should keep it within the content panel.

Similarly, as you've indicated, window.getDraggable.setContainer ought to keep the window from being dragged outside those bounds. Draggable:155 or so is the part that checks for a container, and records those bounds - set a breakpoint there to make sure the container isn't null (you are modifying the correct instance) and the bounds make sense (the min values are not 0,0, the max are reasonably large as well) - this code should run when you begin to drag the window.

Assuming those are all correct, 567-574 should be actually constraining as you drag, preventing the window from moving outside its allotted position.

This code hasn't changed substantially from 2.x, so I would be surprised if Draggable's logic is messed up. Instead, I would imagine that either the ContentPanel is not providing correct values for its size (which would make for nonsense bounds in onMouseDown), or there is some kind of configuration issue.

Your example is a pretty straightforward one, but if you can provide us with an EntryPoint that does all of that, we can more easily test, rather than point you in the direction where you might find the issue.

6 Jan 2012, 1:30 PM
Ah, my mistake - I actually WAS using the line:


And further, mea cupla! I apparently wasn't doing


but instead of cp had another instance whose variable name was ep, that was the NorthSouthContainer in the Viewport (uh, I kept saying TopBottomComponent, didn't I?) - so, basically I kept misreading ep as cp and was wondering why things weren't working.

Ugh . . thanks for replying - it helped point out my error, even though it was my mistake from the beginning!


Colin Alworth
6 Jan 2012, 3:27 PM
This works well from both sides - I know that the functionality is being tested, and you got enough of a pointer to find the root cause of your issue.

Two other things:

Does the window.setContainer correctly constrain then? I had thought I understood that neither functionality was working.

Also: It used to be called TopBottomContainer, pre-beta, but changed to NorthSouthContainer to be more consistent with the border layout container.

9 Jan 2012, 7:42 AM
Yes, it actually constrains, assuming the following is what is supposed to happen:


will correctly constrain the window for maximizing purposes.


will correctly constrain the window for dragging purposes.

So, those two lines together give me what I want.