使用 Smart GWT TreeGrid 进行导航

发布于 2025-01-01 08:45:19 字数 1334 浏览 0 评论 0原文

我正在开发一个 SmartGWT 项目,我希望通过树形网格完成主要导航。树形网格正确呈现,其数据源也正常运行。树形网格正确位于主视图画布的左侧。

我似乎无法弄清楚如何根据导航树中选择的内容切换 mainView Canvas 的内容。我通过向现有画布添加新窗口来模仿我想要的功能,但我找不到演示如何完全清除画布并将其替换为新窗口的示例。

我走在正确的轨道上吗?谁能给我举一个例子来大致说明我想要实现的目标吗?

public class NavigationTree extends TreeGrid {

    public NavigationTree(Canvas mainView)
    {
        setDataSource(NavigationDataSource.getInstance());
        setAutoFetchData(true);
        setShowHeader(false);

        addNodeClickHandler(new NavClickHandler(mainView));
    }

    // Handler for clicking an item on the Navigation Tree.
    private class NavClickHandler implements NodeClickHandler
    {
        private Canvas mainView;

        public NavClickHandler(Canvas mainView)
        {
            super();
            this.mainView = mainView;
        }

        @Override
        public void onNodeClick(NodeClickEvent event)
        {
            Window window = new Window();

            window.setWidth(300);  
            window.setHeight(230);  
            window.setCanDragReposition(true);  
            window.setCanDragResize(true);  

            window.setTitle(event.getNode().getAttribute("name"));
            window.addItem(new Label("huzzah!"));

            window.setParentElement(mainView);
            window.redraw();
        }
    }
}

I'm working on a SmartGWT project where I'd like my main navigation to be done via a treegrid. The treegrid renders proprerly and its DataSource is functioning appropriately as well. The treegrid is correctly situated to the left of the mainView Canvas.

What I can't seem to figure out is how to switch the contents of the mainView Canvas based on what is selected in the NavigationTree. I've mimicked the functionality I'd like by adding new windows to the existing Canvas, but I can't find an example demonstrating how to clear the canvas entirely and replace it with a new Window.

Am I on the right track here? Can anyone point me at an example that shows roughly what I'm trying to accomplish?

public class NavigationTree extends TreeGrid {

    public NavigationTree(Canvas mainView)
    {
        setDataSource(NavigationDataSource.getInstance());
        setAutoFetchData(true);
        setShowHeader(false);

        addNodeClickHandler(new NavClickHandler(mainView));
    }

    // Handler for clicking an item on the Navigation Tree.
    private class NavClickHandler implements NodeClickHandler
    {
        private Canvas mainView;

        public NavClickHandler(Canvas mainView)
        {
            super();
            this.mainView = mainView;
        }

        @Override
        public void onNodeClick(NodeClickEvent event)
        {
            Window window = new Window();

            window.setWidth(300);  
            window.setHeight(230);  
            window.setCanDragReposition(true);  
            window.setCanDragResize(true);  

            window.setTitle(event.getNode().getAttribute("name"));
            window.addItem(new Label("huzzah!"));

            window.setParentElement(mainView);
            window.redraw();
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烧了回忆取暖 2025-01-08 08:45:20

您可以保留 mainView 画布,清除其子窗口(如果设置了),然后将新创建的窗口设置为其新子窗口。单击处理程序的主体如下所示:

Window window = new Window();

window.setWidth(300);  
window.setHeight(230);  
window.setCanDragReposition(true);  
window.setCanDragResize(true);  

window.setTitle(event.getNode().getAttribute("name"));
window.addItem(new Label("huzzah!"));

for (Canvas child: mainView.getChildren()) {
    mainView.removeChild(child);
}

mainView.addChild(window);

You can keep the mainView canvas, clear its children (if any is set) and then set the newly created window as its new child. Something like the following as the body of your click handler:

Window window = new Window();

window.setWidth(300);  
window.setHeight(230);  
window.setCanDragReposition(true);  
window.setCanDragResize(true);  

window.setTitle(event.getNode().getAttribute("name"));
window.addItem(new Label("huzzah!"));

for (Canvas child: mainView.getChildren()) {
    mainView.removeChild(child);
}

mainView.addChild(window);
凹づ凸ル 2025-01-08 08:45:20

我成功地通过对事件处理程序代码进行以下更改来完成我所需要的:

public NavClickHandler(UI ui) //UI extends HLayout
{
    this.ui = ui;
}

@Override
public void onNodeClick(NodeClickEvent event) {
    Window window = new Window();

    window.setWidth100();
        window.setHeight100();
        window.setHeaderControls(HeaderControls.HEADER_LABEL);

    window.setTitle(event.getNode().getAttribute("name"));
    window.addItem(new Label("Huzzah!"));

    ui.setMainView(window);
}

...并对我的主 UI 布局进行以下更改:

public void setMainView(Canvas canvas)
{
    mainView.destroy();
    mainView = canvas;
    addMember(mainView);
    this.redraw();
}

I managed to accomplish what I needed with the following change to the event handler code:

public NavClickHandler(UI ui) //UI extends HLayout
{
    this.ui = ui;
}

@Override
public void onNodeClick(NodeClickEvent event) {
    Window window = new Window();

    window.setWidth100();
        window.setHeight100();
        window.setHeaderControls(HeaderControls.HEADER_LABEL);

    window.setTitle(event.getNode().getAttribute("name"));
    window.addItem(new Label("Huzzah!"));

    ui.setMainView(window);
}

...and the following change to my main UI layout:

public void setMainView(Canvas canvas)
{
    mainView.destroy();
    mainView = canvas;
    addMember(mainView);
    this.redraw();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文