Vaadin树扩展问题

时间:2015-01-21 22:41:50

标签: vaadin

我使用Vaadin树组件来处理网页中的树状菜单GUI。我发现了一个问题。我有三个层次结构树菜单。当我第一次展开第二层树时,它没问题。但是,如果我展开与第一个展开的同一层中的另一个树菜单,则第一个展开的树菜单将折叠。崩溃并不完全。有时它会折叠部分树,有时它会折叠之前扩展的整个菜单。有人遇到这个问题吗?

HierarchicalContainer container = new HierarchicalContainer();
container addContainerProperty("caption", String.class, "");
container addContainerProperty("type", String.class, "");
container addContainerProperty("parameter", String.class, "");
Tree tree = new Tree();
tree.setImmediate(true);
tree.setItemCaptionPropertyId("caption");
tree.setContainerDataSource(container); 

当用户单击根节点时,我使用nodeExpand方法动态添加子节点。

节点展开方法:

public void nodeExpand(ExpandEvent event) {
            Item item = getContainer().getItem(event.getItemId());
            getTree().setValue(item);
            String type = String.valueOf(
                    item.getItemProperty("type").getValue()).trim();
            String caption = String.valueOf(
                    item.getItemProperty("caption").getValue()).trim();
            if (type.equalsIgnoreCase("modelSeries")) {
                ModelVariantDataWebservice mvws = new ModelVariantDataWebservice();
                mvws.init();
                ModelVariantDataResponse mvdr = mvws.doWSCall(caption);
                if (mvdr.getModelList() != null
                        && mvdr.getModelList().size() != 0) {
                    String variant;
                    for (ModelVariant mv : mvdr.getModelList()) {
                        variant = mv.getVariant().trim();
                        getContainer().addItem(variant);
                        getContainer().getItem(variant).getItemProperty("type")
                                .setValue("modelVariant");
                        getContainer().getItem(variant)
                                .getItemProperty("caption").setValue(variant);
                        getContainer().setParent(variant, caption);
                    }
                }
            } else if (type.equalsIgnoreCase("modelVariant")) {
                BodyTrimComboDataWebservice btcws = new BodyTrimComboDataWebservice();
                btcws.init();
                BodyTrimComboDataResponse btcdr = btcws.doWSCall(caption.trim()
                        .replaceAll(" ", "%20")
                        + "&series="
                        + String.valueOf(container.getParent(caption))
                                .replaceAll(" ", "%20"));
                    if (btcdr.getModelSeriesVariantlList() != null
                        && btcdr.getModelSeriesVariantlList().size() != 0) {
                    String bodyTrimTitle;
                    String bodyColour;
                    for (BodyTrimComboExtension btc : btcdr
                            .getModelSeriesVariantlList()) {
                        bodyColour = btc.getBodyColour();
                        bodyTrimTitle = "(" + btc.getBodyColour() + " "
                                + btc.getTrimColour() + ") "
                                + btc.getBodyColourDesc() + "-"
                                + btc.getTrimColourDesc();
                        getContainer().addItem(bodyColour);
                        getContainer().getItem(bodyColour)
                                .getItemProperty("type").setValue("bodyTrim");
                        getContainer().getItem(bodyColour)
                                .getItemProperty("caption")
                                .setValue(bodyTrimTitle);
                        getContainer().getItem(bodyColour).getItemProperty("parameter").setValue(caption+";"+btc.getBodyColour()+"-"+btc.getBodyColourDesc()+";"+btc.getTrimColour()+"-"+btc.getTrimColourDesc());
                        getContainer().setParent(bodyColour, caption);
                        getContainer().setChildrenAllowed(bodyColour, false);
                    }
                }
            }

        }

0 个答案:

没有答案