google-code-export / gwt-ext

Automatically exported from code.google.com/p/gwt-ext
0 stars 0 forks source link

NestedLayoutPanel has no ID #20

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Since NestedLayoutPanel extends ContentPanel, one should be able to set the
ID for the NestedLayoutPanel, but this is not possible.

Could you please add a ID property to the constructor, or create a new
constuctor taking an ID (like ContentPanel)?

Original issue reported on code.google.com by mathias....@gmail.com on 20 Jul 2007 at 8:36

GoogleCodeExporter commented 9 years ago
Can you explain what you're trying to do and why you need this? 
NestedLayoutPanel
serves a different purpose from ContentPanel so I want to understand your
requirements before making any changes.

Original comment by sanjiv.j...@gmail.com on 24 Jul 2007 at 12:36

GoogleCodeExporter commented 9 years ago
I'm trying to put multiple NestedLayoutPanels as tabs in a BorderLayout. I need 
the
ID to re-display a panel depending on an incoming ID, like so:

final String id = convertToId(plant.getKey());
NestedLayoutPanel panel = (NestedLayoutPanel) mainLayout.findPanel(id);
if (panel != null) {
    mainLayout.showPanel(id);
}
else {
    // create the nested layout panel..
    panel = new NestedLayoutPanel(innerLayout, new ContentPanelConfig() {
        {
            setTitle(plant.getName());
            setClosable(true);
            setAutoScroll(true);
            setFitToContainer(true);
        }
    });

    mainLayout.add(LayoutRegionConfig.CENTER, panel);
    mainLayout.showPanel(id);
}

Original comment by mathias....@gmail.com on 26 Jul 2007 at 9:32

GoogleCodeExporter commented 9 years ago
hi any update concerning this issue?

Original comment by pvi2...@gmail.com on 1 Oct 2007 at 2:50

GoogleCodeExporter commented 9 years ago
Try this:
-------------------------
package <you package>;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.RootPanel;
import com.gwtext.client.core.Ext;
import com.gwtext.client.util.JavaScriptObjectHelper;
import com.gwtext.client.widgets.BaseExtWidget;
import com.gwtext.client.widgets.layout.BorderLayout;
import com.gwtext.client.widgets.layout.LayoutRegionConfig;

public class AdvancedLayout extends BorderLayout {
    public AdvancedLayout(String id, LayoutRegionConfig north, LayoutRegionConfig south,
LayoutRegionConfig west,
                          LayoutRegionConfig east, LayoutRegionConfig center) {
        this(newElement(id), "100%", "100%", north, south, west, east, center);
    }

    protected AdvancedLayout(Element elem, String width, String height,
LayoutRegionConfig north,
                             LayoutRegionConfig south, LayoutRegionConfig west, LayoutRegionConfig east,
                             LayoutRegionConfig center){
        super(newLayout(elem, width, height, north, south, west, east, center));
    }

    private static Element newElement(String id) {
        Element div = DOM.createDiv();
        DOM.setElementProperty(div, "id", id == null ? Ext.generateId() : id);
        return div;
    }

    private static JavaScriptObject newLayout(final Element elem, final String width,
final String height,
                                              LayoutRegionConfig north, LayoutRegionConfig south,
                                              LayoutRegionConfig west, LayoutRegionConfig east,
                                              LayoutRegionConfig center) {
        BaseExtWidget layout = new BaseExtWidget() {
            {
                setElement(elem);
                setWidth(width);
                setHeight(height);
            }
        };

        RootPanel.get().add(layout);
        JavaScriptObject config = JavaScriptObjectHelper.createObject();

        if (north != null) JavaScriptObjectHelper.setAttribute(config, "north",
north.getJsObj());
        if (south != null) JavaScriptObjectHelper.setAttribute(config, "south",
south.getJsObj());
        if (west != null) JavaScriptObjectHelper.setAttribute(config, "west", west.getJsObj());
        if (east != null) JavaScriptObjectHelper.setAttribute(config, "east", east.getJsObj());
        if (center != null) JavaScriptObjectHelper.setAttribute(config, "center",
center.getJsObj());

        return create(elem, config);
    }

    private static native JavaScriptObject create(Element elem, JavaScriptObject config)/*-{
        return new $wnd.Ext.BorderLayout(elem, config);
    }-*/;
}

--------------------------------
final BorderLayout innerLayout = new AdvancedLayout(id, null, null, null, 
null,   new
LayoutRegionConfig());

NestedLayoutPanel panel = new NestedLayoutPanel(innerLayout, new 
ContentPanelConfig(){
    {
        setClosable(true);
        setFitToFrame(true);
        setFitToContainer(true);
    }
});

mainLayout.add(LayoutRegionConfig.CENTER, panel);
mainLayout.showPanel(id);

Original comment by stroipor...@gmail.com on 4 Dec 2007 at 8:20

GoogleCodeExporter commented 9 years ago
That AdvancedLayout code works great; thanks!

I had tried to subclass NestedLayoutPanel give it an ID, but this is the wrong
approach; the trick is discovering you have to set the ID on the inner 
BorderLayout,
not on the NestedLayoutPanel, for findPanel(id) to work.

Original comment by timva...@gmail.com on 30 Dec 2007 at 11:51

GoogleCodeExporter commented 9 years ago

Original comment by sanjiv.j...@gmail.com on 11 Feb 2008 at 8:31