具有 I18N GWT 的 TreeItem

发布于 2024-09-30 15:05:20 字数 983 浏览 8 评论 0原文

我想知道如何使用 I18N 构建 TreeItem 并且菜单项没有不同的标记。

如果我像这样构建一个 TreeItem:

 @UiField
    Tree tree;

    TreeItem customer = new TreeItem(customerGroup");
       customer.addItem("searchCustomer");
       customer.addItem("create");
       customer.setState(true);

                            tree.clear();
   tree.addItem(customer);


                  @UiHandler("tree")
  public void onSelection(SelectionEvent<TreeItem> event) {
    eventBus.fireEvent(event);
   }

当用户单击“创建”节点时获得的 ValueChange 标记是“创建”,然后我得到如下代码

 public void onValueChange(ValueChangeEvent<String> event) {
  String token = event.getValue();
     if(token.equals("create") 
    {
    CreateCustomerView create = new CreateCustomerView(eventBus,
         customerService);
       content.setContent(create);
    } 

...

但是如果我想在 TreeItem 节点中使用不同的语言怎么办?我想要除文本之外的其他东西作为令牌,也许是一个 id。我可以使用 MVP 模式中的 Places 模式来解决这个问题吗?如果可以的话,它是如何工作的?

I am wondering how to build a TreeItem with I18N and not have different tokens for a menu item.

If I build a TreeItem like this:

 @UiField
    Tree tree;

    TreeItem customer = new TreeItem(customerGroup");
       customer.addItem("searchCustomer");
       customer.addItem("create");
       customer.setState(true);

                            tree.clear();
   tree.addItem(customer);


                  @UiHandler("tree")
  public void onSelection(SelectionEvent<TreeItem> event) {
    eventBus.fireEvent(event);
   }

the ValueChange token I get when a user clicks the "create" node is "create" and then I get code like

 public void onValueChange(ValueChangeEvent<String> event) {
  String token = event.getValue();
     if(token.equals("create") 
    {
    CreateCustomerView create = new CreateCustomerView(eventBus,
         customerService);
       content.setContent(create);
    } 

...

But what if I want to have different languages in the TreeItem nodes, then I want something other then the text as a token, perhaps an id. Can I solve this with the Places pattern from the MVP pattern, and if so how does that work?

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

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

发布评论

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

评论(2

梦断已成空 2024-10-07 15:05:20

TreeItem上有2个方法setUserObject(Object userObject)getUserObject。您可以使用它们或设置一个 Id,然后您可以用它来检查。但是,我不明白您如何从 SelectionEvent 转到 ValueChangeEvent。您会在两者之间丢失一些信息。

On TreeItem there are 2 method setUserObject(Object userObject) and getUserObject. You can use those to or set an Id, which you than can use to check against. However, I don't see how you come from a SelectionEvent to the ValueChangeEvent. You lose some information in between.

云裳 2024-10-07 15:05:20

为什么不将附加到 SelectionEvent 的所选项目与您之前添加的项目进行比较?像这样的:

public void onModuleLoad() {
    Tree tree = new Tree();
    final TreeItem item1 = new TreeItem("item 1");
    TreeItem item2 = new TreeItem("item 2");
    TreeItem item3 = new TreeItem("item 3");
    TreeItem item4 = new TreeItem("item 4");

    tree.addItem(item1);
    tree.addItem(item2);
    tree.addItem(item3);
    tree.addItem(item4);

    tree.addSelectionHandler(new SelectionHandler<TreeItem>() {

        @Override
        public void onSelection(SelectionEvent<TreeItem> event) {
            if (event.getSelectedItem().equals(item1)) {
                Window.alert("item1 selected");
            }
        }
    });

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

或者我错过了什么?

Why don't you compare the selected item attached to the SelectionEvent with the items you added previously? Something like this:

public void onModuleLoad() {
    Tree tree = new Tree();
    final TreeItem item1 = new TreeItem("item 1");
    TreeItem item2 = new TreeItem("item 2");
    TreeItem item3 = new TreeItem("item 3");
    TreeItem item4 = new TreeItem("item 4");

    tree.addItem(item1);
    tree.addItem(item2);
    tree.addItem(item3);
    tree.addItem(item4);

    tree.addSelectionHandler(new SelectionHandler<TreeItem>() {

        @Override
        public void onSelection(SelectionEvent<TreeItem> event) {
            if (event.getSelectedItem().equals(item1)) {
                Window.alert("item1 selected");
            }
        }
    });

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

Or am I missing something?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文