Example usage for com.vaadin.ui Tree addListener

List of usage examples for com.vaadin.ui Tree addListener

Introduction

In this page you can find the example usage for com.vaadin.ui Tree addListener.

Prototype

@Override
    public Registration addListener(Component.Listener listener) 

Source Link

Usage

From source file:com.invient.vaadin.InvientChartsDemoWin.java

License:Apache License

private Tree createChartsTree() {
    final Tree tree = new Tree("Chart Type");
    tree.setContainerDataSource(getContainer());
    tree.setImmediate(true);/*from  www . ja  v  a 2  s. c  o  m*/
    tree.setItemCaptionPropertyId(TREE_ITEM_CAPTION_PROP_ID);
    tree.setItemCaptionMode(Tree.ITEM_CAPTION_MODE_PROPERTY);
    tree.setNullSelectionAllowed(false);

    for (Object id : tree.rootItemIds()) {
        tree.expandItemsRecursively(id);
    }

    tree.addListener(new Tree.ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            try {
                Object selectedId = event.getProperty().getValue();
                if (tree.getParent(selectedId) != null) {
                    Object parentId = tree.getParent(selectedId);
                    String demoSeriesTypeName = (String) tree
                            .getContainerProperty(parentId, TREE_ITEM_CAPTION_PROP_ID).getValue();
                    String seriesInstanceName = (String) tree
                            .getContainerProperty(selectedId, TREE_ITEM_CAPTION_PROP_ID).getValue();

                    System.out.println("parent : " + demoSeriesTypeName + ", selected : " + seriesInstanceName);
                    showChart(demoSeriesTypeName, seriesInstanceName);
                } else {
                    String demoSeriesTypeName = (String) tree
                            .getContainerProperty(selectedId, TREE_ITEM_CAPTION_PROP_ID).getValue();
                    System.out.println("Selected " + demoSeriesTypeName);
                    showChartInstancesForSeriesType(demoSeriesTypeName);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

    return tree;
}

From source file:org.generationcp.breeding.manager.crossingmanager.SelectGermplasmListTreeComponent.java

License:Open Source License

private Tree createGermplasmListTree(Database database) {
    List<GermplasmList> germplasmListParent = new ArrayList<GermplasmList>();

    try {/*from   w ww  .ja  va  2s  . c o m*/
        germplasmListParent = this.germplasmListManager.getAllTopLevelListsBatched(BATCH_SIZE, database);
    } catch (MiddlewareQueryException e) {
        LOG.error(e.toString() + "\n" + e.getStackTrace());
        e.printStackTrace();
        if (getWindow() != null) {
            MessageNotifier.showWarning(getWindow(), messageSource.getMessage(Message.ERROR_DATABASE),
                    messageSource.getMessage(Message.ERROR_IN_GETTING_TOP_LEVEL_FOLDERS),
                    Notification.POSITION_CENTERED);
        }
        germplasmListParent = new ArrayList<GermplasmList>();
    }

    Tree germplasmListTree = new Tree();

    for (GermplasmList parentList : germplasmListParent) {
        germplasmListTree.addItem(parentList.getId());
        germplasmListTree.setItemCaption(parentList.getId(), parentList.getName());
    }

    germplasmListTree.addListener(new SelectListTreeExpandListener(this));
    germplasmListTree.addListener(new SelectListItemClickListener(this));

    return germplasmListTree;
}

From source file:org.s23m.cell.editor.semanticdomain.ui.components.ContainmentTreePanel.java

License:Mozilla Public License

private Tree buildContainmentTree() {
    final Tree tree = new Tree("");
    tree.setImmediate(true);//from   w  ww  . j  ava2s . c om
    tree.setSelectable(true);
    tree.setDragMode(TreeDragMode.NODE);
    tree.setItemCaptionPropertyId(TreeContainer.NAME);
    tree.addActionHandler(new TreeActionHandler(application));

    tree.addListener(new ItemClickEvent.ItemClickListener() {
        public void itemClick(final ItemClickEvent event) {
            final TreeNode node = (TreeNode) event.getItemId();
            final DetailsData detailsData = new DetailsData(node.getSet());
            final BeanItem<DetailsData> detailsItem = new BeanItem<DetailsData>(detailsData);
            application.getDetailsForm().setItemDataSource(detailsItem);
            application.getDetailsForm().setVisibleItemProperties(DetailsData.getDisplayOrder());
        }
    });

    tree.setItemStyleGenerator(new Tree.ItemStyleGenerator() {
        public String getStyle(final Object itemId) {
            final TreeNode node = (TreeNode) itemId;
            if (isEditMode && !isInScope(node.getUrr())) {
                return "disabled";
            }
            return null;
        }

        private boolean isInScope(final String uuid) {
            return scopeMap.containsKey(uuid);
        }
    });

    return tree;
}