PDA

View Full Version : LayoutContainer resize listener



Pandaman
23 Jul 2009, 9:54 AM
I have a LayoutContainer that uses a RowLayout. The widgets are added to this container with RowData(1,-1), so that when they change in height, the container also changes height accordingly. I want to do something when this LayoutContainer's changes size. How can I add a listener that does this? So far I have tried:
layoutContainer.addListener(Events.Resize, new Listener<ComponentEvent>() {
public void handleEvent(final ComponentEvent event) {
//do something
}
} But handleEvent never gets called.

Pandaman
24 Jul 2009, 10:18 AM
please advise

sven
24 Jul 2009, 10:19 AM
How do you change size of the layoutcontainer?

Pandaman
24 Jul 2009, 11:39 AM
As I said before, it uses RowLayout, and all the widgets that it contains are added with RowData(1,-1). This means that the LayoutContainer dynamically changes its height according to the heights of the widgets it contains, right?

sven
24 Jul 2009, 11:59 AM
A layout changes the children size. Not the one from the container that holds the layout.

Pandaman
24 Jul 2009, 12:17 PM
Yes but if you add a child with RowData(1,-1), the "row" will fit to child height-wise, right? If this happens, then the LayoutContainer's size will change when the "row" changes height (i.e. when the child changes height).

At any rate, we agree that the LayoutContainer changes size, correct? I've debugged my LayoutContainer an I have noticed that it changes size. My question is: how do I add a listener that does something when this LayoutContainer's size changes?

sven
24 Jul 2009, 12:21 PM
The event is correct. Please post your code.

Pandaman
7 Aug 2009, 5:51 AM
Here's my code. If resizing were to work correctly, the "status" text field would be set to the number of times the layout container has been resized.

Edit: I meant to say that I expect this resizing when the user expands a parent in the TreeGrid.



public void onModuleLoad() {
final LayoutContainer layoutContainer = new LayoutContainer();
layoutContainer.setLayout(new RowLayout());

final Text status = new Text();
layoutContainer.add(status, new RowData(1,-1));

final ArrayList<ColumnConfig> columns = new ArrayList<ColumnConfig>();
final ColumnConfig treeColumn = new ColumnConfig("name","name", 150);
treeColumn.setRenderer(new TreeGridCellRenderer<BaseModel>());
columns.add(treeColumn);
columns.add(new ColumnConfig("details","details", 150));
final ColumnModel cm = new ColumnModel(columns);

final TreeStore<BaseModel> treeStore = new TreeStore<BaseModel>();
addDummyData(0, treeStore);
addDummyData(1, treeStore);
addDummyData(2, treeStore);

final TreeGrid<BaseModel> treeGrid = new TreeGrid<BaseModel>(treeStore, cm);
treeGrid.setAutoHeight(true);

layoutContainer.add(treeGrid, new RowData(1,-1));

layoutContainer.addListener(Events.Resize, new Listener<ComponentEvent>() {
private int changeSizeCount = 0;
public void handleEvent(final ComponentEvent event) {
changeSizeCount++;
status.setText("The panel has changed size " + changeSizeCount + " times");
layout();
}
});

RootPanel.get().add(layoutContainer);
}

private void addDummyData(final int i, final TreeStore<BaseModel> treeStore) {
final BaseModel data = new BaseModel();
data.set("name", "data " + i);
data.set("details", "details about " + i);

final BaseModel child1Data = new BaseModel();
child1Data.set("name", "child1 data " + i);
child1Data.set("details", "child1 details about " + i);

final BaseModel child2Data = new BaseModel();
child2Data.set("name", "child2 data " + i);
child2Data.set("details", "child2 details about " + i);

treeStore.add(data, false);
treeStore.add(data, child1Data, false);
treeStore.add(data, child2Data, false);
}

sven
7 Aug 2009, 5:55 AM
The event will never be fired. Nothing is resizing there a component.

Pandaman
7 Aug 2009, 5:58 AM
So the TreeGrid doesn't resize the LayoutContainer when you expand a parent? Please see my previous post for more clarification, I editted it.

sven
7 Aug 2009, 6:00 AM
No, it is not resizing it.

Pandaman
7 Aug 2009, 6:12 AM
So the layout container doesn't change size even when its children start to take up more space?

sven
7 Aug 2009, 6:14 AM
It changes size, but that is browserflow. No events are fired with that.

It is not an actual resize.

Pandaman
7 Aug 2009, 6:17 AM
Ah, ok. Thanks for the help.