com.vaadin.ui.Tree Java Examples

The following examples show how to use com.vaadin.ui.Tree. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TreeContextMenu.java    From cuba with Apache License 2.0 6 votes vote down vote up
public void addTreeContextMenuListener(final TreeContextMenuOpenListener<T> listener) {
    addContextMenuOpenListener((final ContextMenuOpenEvent event) -> {
        if (!isEnabled()) {
            return;
        }

        if (event
                .getContextClickEvent() instanceof Tree.TreeContextClickEvent) {
            @SuppressWarnings("unchecked")
            TreeContextClickEvent<T> treeEvent = (TreeContextClickEvent<T>) event
                    .getContextClickEvent();
            listener.onContextMenuOpen(new TreeContextMenuOpenListener.TreeContextMenuOpenEvent<>(
                    TreeContextMenu.this, treeEvent ));
        }
    });
}
 
Example #2
Source File: ContextMenuUI.java    From context-menu with Apache License 2.0 6 votes vote down vote up
private void addTree(VerticalLayout layout) {
    TreeData<String> data = new TreeData<>();
    data.addItem(null, "Dad");
    data.addItem("Dad", "Daughter");
    data.addItem("Daughter", "Granddaughter");
    data.addItem("Dad", "Son");
    data.addItem("Daughter", "Grandson");

    Tree<String> tree = new Tree<>("A family", data);
    TreeContextMenu<String> treeContextMenu = new TreeContextMenu<>(tree);
    treeContextMenu.addTreeContextMenuListener(e -> {
        treeContextMenu.removeItems();
        //The path is /resources/images/kitten.jpg
        ClassResource ico = new ClassResource("/images/kitten.jpg");
        treeContextMenu.addItem("Who?",ico, menuItem -> Notification.show(e.getItem()));
    });

    layout.addComponent(tree);
}
 
Example #3
Source File: WrappedYangNode.java    From anx with Apache License 2.0 5 votes vote down vote up
int applyExpand(Tree<WrappedYangNode> tree, int limit) {
    if (expand && limit > 0) {
        int limitBefore = limit;
        tree.expand(this);

        for (WrappedYangNode child: tree.getTreeData().getChildren(this))
            limit = child.applyExpand(tree, limit);

        if (limit == limitBefore)
            --limit;
    }
    return limit;
}
 
Example #4
Source File: TreeContextMenu.java    From context-menu with Apache License 2.0 5 votes vote down vote up
public void addTreeContextMenuListener(final TreeContextMenuOpenListener<T> listener) {
    addContextMenuOpenListener((final ContextMenuOpenEvent event) -> {
        if (event
                .getContextClickEvent() instanceof Tree.TreeContextClickEvent) {
            @SuppressWarnings("unchecked")
            TreeContextClickEvent<T> treeEvent = (TreeContextClickEvent<T>) event
                    .getContextClickEvent();
            listener.onContextMenuOpen(new TreeContextMenuOpenListener.TreeContextMenuOpenEvent<>(
                    TreeContextMenu.this, treeEvent ));
        }
    });
}
 
Example #5
Source File: ExpressionEditorWindow.java    From XACML with MIT License 5 votes vote down vote up
@AutoGenerated
private VerticalLayout buildMainLayout() {
	// common part: create layout
	mainLayout = new VerticalLayout();
	mainLayout.setImmediate(false);
	mainLayout.setWidth("-1px");
	mainLayout.setHeight("-1px");
	mainLayout.setMargin(true);
	mainLayout.setSpacing(true);
	
	// top-level component properties
	setWidth("-1px");
	setHeight("-1px");
	
	// comboBox
	comboBox = new ComboBox();
	comboBox.setImmediate(false);
	comboBox.setWidth("-1px");
	comboBox.setHeight("-1px");
	mainLayout.addComponent(comboBox);
	
	// treeExpression
	treeExpression = new Tree();
	treeExpression.setImmediate(false);
	treeExpression.setWidth("100.0%");
	treeExpression.setHeight("-1px");
	mainLayout.addComponent(treeExpression);
	mainLayout.setExpandRatio(treeExpression, 1.0f);
	
	return mainLayout;
}
 
Example #6
Source File: TreeContextMenu.java    From cuba with Apache License 2.0 4 votes vote down vote up
public TreeContextMenu(Tree<T> parentComponent) {
    super(parentComponent, true);
}
 
Example #7
Source File: TreeContextMenu.java    From cuba with Apache License 2.0 4 votes vote down vote up
public Tree<T> getComponent() {
    return component;
}
 
Example #8
Source File: TreeContextMenu.java    From context-menu with Apache License 2.0 4 votes vote down vote up
public TreeContextMenu(Tree<T> parentComponent) {
    super(parentComponent, true);
}
 
Example #9
Source File: TreeContextMenu.java    From context-menu with Apache License 2.0 4 votes vote down vote up
public Tree<T> getComponent() {
    return component;
}
 
Example #10
Source File: TreeToolEditor.java    From chipster with MIT License 4 votes vote down vote up
private void initTree() {
	this.setSizeFull();
	this.setImmediate(true);
	this.setSelectable(true);
	this.addItemClickListener(this);
	this.addContainerProperty("", String.class, null);
	this.addContainerProperty(ACTIONS, HorizontalLayout.class, null	);
	this.addItem(new Object[] {TOOL, getActionLayout(false, false, TOOL)}, TOOL);
	this.setItemDescriptionGenerator(new ItemDescriptionGenerator() {
		private static final long serialVersionUID = -1913286695570843896L;

		@Override
		public String generateDescription(Component source, Object itemId,
				Object propertyId) {
			String description = "Show all ";
			if(itemId.equals(TOOL))
				description += "elements";
			else if (itemId.equals(INPUTS))
				description += "inputs";
			else if (itemId.equals(OUTPUTS))
				description += "outputs";
			else if (itemId.equals(PARAMETERS))
				description += "parameters";
			else
				return null;
			return description;
		}
	});
	this.setCollapsed(TOOL, false);
	String[] rootToolElements = new String[] {INPUTS, OUTPUTS, PARAMETERS};
	for(String element : rootToolElements) {
		this.addItem(new Object[] {element, getActionLayout(true, false, element)}, element);
		this.setParent(element, TOOL);
		this.setCollapsed(element, false);
	}
	this.setDragMode(TableDragMode.ROW);
	this.setDropHandler(new DropHandler() {
		private static final long serialVersionUID = -4415321436294383112L;

		@Override
		public AcceptCriterion getAcceptCriterion() {
			return new Or(Tree.TargetItemAllowsChildren.get(), new Not(VerticalLocationIs.MIDDLE));
		}
		
		@Override
		public void drop(DragAndDropEvent event) {
            final Transferable t = event.getTransferable();
            if (t.getSourceComponent() != TreeToolEditor.this
                    || !(t instanceof DataBoundTransferable)) {
                return;
            }

            final AbstractSelectTargetDetails dropData = ((AbstractSelectTargetDetails) event.getTargetDetails());

            final Object sourceItemId = ((DataBoundTransferable) t).getItemId();
            final Object targetItemId = dropData.getItemIdOver();
            final VerticalDropLocation location = dropData.getDropLocation();

            moveNode(sourceItemId, targetItemId, location);
		}
	});

}