PDA

View Full Version : How-to add and remove LayoutContainers dynamically?



sukharevd
2 Feb 2012, 3:14 AM
Hello,

I'm trying to implement dynamical change of LayoutContainers inside another LayoutContainer.
I want internal container to fit to all space of external container. I tried two following approaches
http://www.sencha.com/forum/showthread.php?78914-Add-Dynamically-Component-to-a-Container
http://stackoverflow.com/questions/3961379/dynamically-add-widget-to-gxt-sencha-widget (setLayoutOnChange),
but without luck.

The problem is that internal container is rendered, but its size is 100px x 100px. After resizing browser window, the size of internal container is 100% x 100% again (as I want), but I can't get this before resizing browser. UPD: Forgot to said that initially everything is good, but after the first remove/add (see code) the problem appears.


import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.google.gwt.user.client.Element;

public class MainContainer extends LayoutContainer {

public enum ViewType { TYPE1, TYPE2 }
private ViewType viewType;
private LayoutContainer contentContainer;

public ViewType getViewType() {
return viewType;
}

public void setViewType(ViewType viewType) {
this.viewType = viewType;
updateContantContainer(viewType);
}

private void updateContantContainer(ViewType viewType) {
if (contentContainer != null) {
remove(contentContainer);
}
if (viewType == null || viewType == ViewType.TYPE1) {
contentContainer = new TreeLayoutContainer();
} else {
contentContainer = new GridLayoutContainer();
}
add(contentContainer);
}

protected void onRender(Element target, int index) {
super.onRender(target, index);
setLayout(new FitLayout());
//setSize("100%", "100%");
setId("grcMainContainer");
setStyleAttribute("margin", "0px");
setLayoutOnChange(true);
updateContantContainer(viewType);
}

}

I check it in FF9, Chome 16, IE8.

Best regards, Dmitriy.

smiletolead
2 Feb 2012, 6:36 PM
It is not clear what you want to do. Please post a working prototype which will be helpful for others to try out and help you.

sukharevd
6 Feb 2012, 5:16 AM
I wrote simple example, and now it works :) It is in the attached archive.

I solved my particular problem (not in the example I wrote) using with full clear of RootPanel several days ago.

Anyway it's kind of strange because I faced several times with the problem of addition UI components after removing other ones... Maybe I haven't known about layout() method then.