Package com.vaadin.data.util

Examples of com.vaadin.data.util.HierarchicalContainer


     * @see com.vaadin.data.Container.Viewer#setContainerDataSource(Container)
     */
    @Override
    public void setContainerDataSource(Container newDataSource) {
        if (newDataSource == null) {
            newDataSource = new HierarchicalContainer();
        }

        // Assure that the data source is ordered by making unordered
        // containers ordered by wrapping them
        if (Container.Hierarchical.class.isAssignableFrom(newDataSource
View Full Code Here


    }

    private void initGUI() {
        setSizeUndefined();
        setWidth("100%");
        hierarchicalContainer = new HierarchicalContainer();
        hierarchicalContainer.addContainerProperty("name", String.class, null);
        hierarchicalContainer.addContainerProperty("widget", Object.class, null);

        HorizontalLayout treeAndForm = new HorizontalLayout();
        final VerticalLayout formLayout = getFormLayout();
View Full Code Here

            Transferable t = dropEvent.getTransferable();
            Component src = t.getSourceComponent();
            Object sourceItemId;
            Object newItemId = null;
//            Item subItem = null;
            HierarchicalContainer container = (HierarchicalContainer) tree.getContainerDataSource();
            if (src instanceof WidgetDragAndDropWrapper) {
                WidgetDragAndDropWrapper dragAndDropWrapper = (WidgetDragAndDropWrapper) src;
                Class cls = dragAndDropWrapper.getCls();
                Object widgetElement = null;
                try {
                    widgetElement = cls.newInstance();
                    /*subItem = */addTreeItem(widgetElement);
                    newItemId = widgetElement;
                    sourceItemId = widgetElement;
                } catch (Throwable e) {
                    LOGGER.log(Level.SEVERE, e.getMessage(), e);
                    src.getApplication().getMainWindow().showNotification(getLocalizedMessage("widget-creation-failed"),
                            e.getClass().getName() + ", " + e.getMessage(),
                            Window.Notification.TYPE_ERROR_MESSAGE);
//                    if (subItem != null && widgetElement != null) {
//                        container.removeItem(widgetElement);
//                    }
                    return;
                }
            } else {
                if (src != tree || !(t instanceof DataBoundTransferable)) {
                    return;
                }
                sourceItemId = ((DataBoundTransferable) t).getItemId();
            }


            Tree.TreeTargetDetails dropData = ((Tree.TreeTargetDetails) dropEvent
                    .getTargetDetails());
            Object targetItemId = dropData.getItemIdOver();
            VerticalDropLocation location = dropData.getDropLocation();
            if (targetItemId instanceof WidgetsDefinitionElement) {  //the can be only one! ... root element2
                location = VerticalDropLocation.MIDDLE;
            }
            if (!moveNode(sourceItemId, targetItemId, location)) {
                if (newItemId != null) {
                    container.removeItem(newItemId);
                }
            } else {
                refreshRawXmlAndPreview();
            }
        }
View Full Code Here

        }


        private boolean moveNode(Object sourceItemId, Object targetItemId,
                                 VerticalDropLocation location) {
            HierarchicalContainer container = (HierarchicalContainer) tree.getContainerDataSource();
            if (sourceItemId == null || targetItemId == null) return false;
            Class srcClass = sourceItemId.getClass();
            Class targetClass = targetItemId.getClass();
            if (location == VerticalDropLocation.MIDDLE) {
                if (!checkIfParentChildRelationIsPossible(srcClass, targetClass)) return false;
                if (container.setParent(sourceItemId, targetItemId)
                        && container.hasChildren(targetItemId)) {
                    container.moveAfterSibling(sourceItemId, null);
                }
            } else if (location == VerticalDropLocation.TOP) {
                Object parentId = container.getParent(targetItemId);
                if (!checkIfParentChildRelationIsPossible(srcClass, parentId.getClass())) return false;
                if (container.setParent(sourceItemId, parentId)) {
                    container.moveAfterSibling(sourceItemId, targetItemId);
                    container.moveAfterSibling(targetItemId, sourceItemId);
                }
            } else if (location == VerticalDropLocation.BOTTOM) {
                Object parentId = container.getParent(targetItemId);
                if (!checkIfParentChildRelationIsPossible(srcClass, parentId.getClass())) return false;
                if (container.setParent(sourceItemId, parentId)) {
                    container.moveAfterSibling(sourceItemId, targetItemId);
                }
            }
            return true;
        }
View Full Code Here

    private static final String SEPARATOR = "|";

    private HierarchicalContainer getContainer() {

        HierarchicalContainer container = new HierarchicalContainer();

        container.addContainerProperty(TREE_ITEM_CAPTION_PROP_ID, String.class,
                "");

        for (DemoSeriesType demoSeriesType : DemoSeriesType.values()) {
            String itemId = demoSeriesType.getName();
            Item item = container.addItem(itemId);
            item.getItemProperty(TREE_ITEM_CAPTION_PROP_ID).setValue(
                    demoSeriesType.getName());
            container.setChildrenAllowed(itemId, true);
            // add child
            addChartNamesForSeriesType(container, itemId, demoSeriesType);
        }

        return container;
View Full Code Here

     * Creates a new empty tree with caption.
     *
     * @param caption
     */
    public Tree(String caption) {
        this(caption, new HierarchicalContainer());
    }
View Full Code Here

     * @see com.vaadin.data.Container.Viewer#setContainerDataSource(Container)
     */
    @Override
    public void setContainerDataSource(Container newDataSource) {
        if (newDataSource == null) {
            newDataSource = new HierarchicalContainer();
        }

        // Assure that the data source is ordered by making unordered
        // containers ordered by wrapping them
        if (Container.Hierarchical.class.isAssignableFrom(newDataSource
View Full Code Here

TOP

Related Classes of com.vaadin.data.util.HierarchicalContainer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.