Package com.smartgwt.client.widgets.tree

Examples of com.smartgwt.client.widgets.tree.TreeNode


        System.out.print(treeString);
        Log.info(treeString);
    }

    public static String getTreeString(Tree tree) {
        TreeNode rootNode = tree.getRoot();
        StringBuilder str = new StringBuilder();
        appendTreeNode(tree, rootNode, str);
        return str.toString();
    }
View Full Code Here


                // don't select the node on a right click, since we're not navigating to it, and
                // re-select the current node if necessary
                ResourceGroupEnhancedTreeNode contextNode = (ResourceGroupEnhancedTreeNode) event.getNode();

                if (null != currentNodeId) {
                    TreeNode currentNode = treeGrid.getTree().findById(currentNodeId);
                    if (!contextNode.equals(currentNode)) {
                        treeGrid.deselectRecord(contextNode);
                        treeGrid.selectRecord(currentNode);
                    }
                }

                // only show the context menu for cluster nodes and our top root node
                if (contextNode.isCompatibleGroupTopNode() || contextNode.isAutoClusterNode()) {
                    contextMenu.showContextMenu(ResourceGroupTreeView.this, treeGrid, contextNode);
                }
            }
        });

        treeGrid.addSelectionChangedHandler(new SelectionChangedHandler() {

            public void onSelectionChanged(SelectionEvent selectionEvent) {
                if (!selectionEvent.isRightButtonDown() && selectionEvent.getState()) {

                    ResourceGroupEnhancedTreeNode newNode = (ResourceGroupEnhancedTreeNode) selectionEvent.getRecord();
                    TreeNode currentNode = (null != currentNodeId) ? treeGrid.getTree().findById(currentNodeId) : null;

                    // if re-selecting the current node just return, otherwise deselect the currently selected node
                    if (null != currentNode) {
                        if (newNode.equals(currentNode)) {
                            return;
View Full Code Here

                // get this from the parent ResourceTreeNode as resource.parentResource may not be set with
                // anything more than the id.
                Resource parentResource = resource.getParentResource();
                String parentResourceNodeId = ResourceTreeNode.idOf(parentResource);
                Tree tree = treeGrid.getTree();
                TreeNode parentResourceNode = tree.findById(parentResourceNodeId);
                if (null != parentResourceNode) {
                    parentResource = ((ResourceTreeNode) parentResourceNode).getResource();
                    resource.setParentResource(parentResource);
                }
                if (null == parentResource.getName()) {
View Full Code Here

                if (selectionChangedHandlerDisabled || selectionEvent.isRightButtonDown()) {
                    return;
                }
                selectionChangedHandlerDisabled = true;

                final TreeNode selectedNode = treeGrid.getTree()
                    .findById(selectionEvent.getRecord().getAttribute("id"));
                TreeNode parentNode = treeGrid.getTree().getParent(selectedNode);
                boolean isPlatform = treeGrid.getTree().isRoot(parentNode);
                boolean isCheckboxMarked = treeGrid.isSelected(selectedNode);

                if (isPlatform) {
                    if (isCheckboxMarked) {
                        SC.ask(MSG.view_autoDiscoveryQ_confirmSelect(), new BooleanCallback() {
                            public void execute(Boolean confirmed) {
                                if (confirmed && !treeGrid.getTree().hasChildren(selectedNode)) {
                                    selectedNode.setAttribute("selectChildOnArrival", "true");
                                    treeGrid.getTree().loadChildren(selectedNode);
                                } else {
                                    if (confirmed) {
                                        selectAllPlatformChildren(selectedNode);
                                    }
                                    updateButtonEnablement(selectAllButton, deselectAllButton, importButton,
                                        ignoreButton, unignoreButton);
                                    selectionChangedHandlerDisabled = false;
                                }
                            }
                        });
                    } else {
                        selectedNode.setAttribute("autoSelectChildren", "false");
                        treeGrid.deselectRecords(treeGrid.getTree().getChildren(selectedNode));

                        // the immediate redraw below should not be necessary, but without it the deselected
                        // platform checkbox remained checked.
                        // treeGrid.redraw();
                        updateButtonEnablement(selectAllButton, deselectAllButton, importButton, ignoreButton,
                            unignoreButton);
                        selectionChangedHandlerDisabled = false;
                    }
                } else {
                    if (isCheckboxMarked) {
                        if (!treeGrid.isSelected(parentNode)) {
                            treeGrid.selectRecord(parentNode);
                        }
                    }
                    updateButtonEnablement(selectAllButton, deselectAllButton, importButton, ignoreButton,
                        unignoreButton);
                    selectionChangedHandlerDisabled = false;
                }
            }

        });

        treeGrid.addDataArrivedHandler(new DataArrivedHandler() {
            public void onDataArrived(DataArrivedEvent dataArrivedEvent) {
                if (treeGrid != null) {
                    TreeNode parent = dataArrivedEvent.getParentNode();
                    if (!treeGrid.getTree().isRoot(parent)) {
                        // This flag can be set when we select a platform or as part of selectAll button handling. It
                        // means that we want to immediately select the child server nodes.
                        boolean selectChildOnArrival = Boolean.valueOf(parent.getAttribute("selectChildOnArrival"));
                        if (selectChildOnArrival) {
                            // data includes the platform, just get the descendant servers
                            treeGrid.selectRecords(treeGrid.getData().getDescendantLeaves());
                        }
                    }

                    // This logic is relevant to what we do in the selectAll button
                    boolean endDisable = true;
                    if (loadAllPlatforms) {
                        TreeNode rootNode = treeGrid.getTree().getRoot();
                        TreeNode[] platformNodes = treeGrid.getTree().getChildren(rootNode);

                        for (TreeNode platformNode : platformNodes) {
                            if (!treeGrid.getTree().isLoaded(platformNode)) {
                                endDisable = false;
                                break;
                            }
                        }
                    }
                    if (endDisable) {
                        updateButtonEnablement(selectAllButton, deselectAllButton, importButton, ignoreButton,
                            unignoreButton);
                        selectionChangedHandlerDisabled = false;
                    }

                    // NOTE: Due to a SmartGWT bug, the TreeGrid is not automatically redrawn upon data arrival, and
                    //       calling treeGrid.markForRedraw() doesn't redraw it either. The user can mouse over the grid
                    //       to cause it to redraw, but it is obviously not reasonable to expect that. So we must
                    //       explicitly call redraw() here.
                    treeGrid.redraw();
                }
            }
        });

        dataSource.addFailedFetchListener(new AsyncCallback() {

            // just in case we have a failure while fetching, try to make sure we don't lock up the view.
            public void onFailure(Throwable caught) {
                loadAllPlatforms = false;
                updateButtonEnablement(selectAllButton, deselectAllButton, importButton, ignoreButton, unignoreButton);
                selectionChangedHandlerDisabled = false;
            }

            public void onSuccess(Object result) {
                // never called
            }
        });

        selectAllButton.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent clickEvent) {
                SC.ask(MSG.view_autoDiscoveryQ_confirmSelectAll(), new BooleanCallback() {
                    public void execute(Boolean selectChildServers) {

                        selectionChangedHandlerDisabled = true;
                        TreeNode rootNode = treeGrid.getTree().getRoot();
                        TreeNode[] platformNodes = treeGrid.getTree().getChildren(rootNode);

                        if (selectChildServers) {
                            disableButtons(selectAllButton, deselectAllButton, importButton, ignoreButton,
                                unignoreButton);
View Full Code Here

    // a timeout for a large import request.
    private void importResources(final List<TreeNode> platforms) {

        int[] idsToImport = null;
        for (Iterator<TreeNode> i = platforms.iterator(); i.hasNext();) {
            TreeNode platformNode = i.next();
            int[] uncommittedIdsForPlatform = getPlatformSelectedIds(platformNode);
            // remove this platform, it either has nothing to import, or its resources will be imported
            i.remove();
            if (uncommittedIdsForPlatform.length > 0) {
                idsToImport = uncommittedIdsForPlatform;
View Full Code Here

        boolean importOk = false;
        boolean ignoreOk = false;
        boolean unignoreOk = false;

        for (ListGridRecord listGridRecord : treeGrid.getSelectedRecords()) {
            TreeNode node = treeGrid.getTree().findById(listGridRecord.getAttribute("id"));
            String status = node.getAttributeAsString("status");

            importOk |= InventoryStatus.NEW.name().equals(status);
            unignoreOk |= InventoryStatus.IGNORED.name().equals(status);
            ignoreOk |= InventoryStatus.NEW.name().equals(status);
        }
View Full Code Here

            button.setDisabled(true);
        }
    }

    private List<TreeNode> getSelectedPlatforms() {
        TreeNode rootNode = treeGrid.getTree().getRoot();
        TreeNode[] platformNodes = treeGrid.getTree().getChildren(rootNode);
        List<TreeNode> result = new ArrayList<TreeNode>(platformNodes.length);

        for (TreeNode platformNode : platformNodes) {
            if (treeGrid.isSelected(platformNode)) {
View Full Code Here

            nodes = new ArrayList<TreeNode>(resourceTypes.size() + 1 /* at least this size*/);
            // Add a dummy node so that if the user selects a plugin or resource type, he has
            // the ability to undo the selection. This data source is used with a IPickTreeItem
            // and that widget does not allow you to select the initial value once the user
            // selects a value. See https://bugzilla.redhat.com/show_bug.cgi?id=749801.
            nodes.add(new TreeNode(""));

            for (ResourceType type : resourceTypes) {
                String plugin = type.getPlugin();
                Set<ResourceType> parentTypes = type.getParentResourceTypes();
                if (parentTypes == null || parentTypes.isEmpty() || parentTypes.size() > 1) {
View Full Code Here

    }

    protected Tree buildTree() {
        Tree tree = new Tree();

        TreeNode root = new TreeNode(MSG.view_configCompare_configCompare());

        ArrayList<TreeNode> children = new ArrayList<TreeNode>();

        List<PropertyDefinition> nonGroupDefs = definition.getNonGroupedProperties();
        if (nonGroupDefs != null && !nonGroupDefs.isEmpty()) {
            TreeNode groupNode = new TreeNode(MSG.common_title_generalProp());
            buildNode(groupNode, nonGroupDefs, configs);
            children.add(groupNode);
        }

        for (PropertyGroupDefinition group : definition.getGroupDefinitions()) {
            TreeNode groupNode = new TreeNode(group.getDisplayName());
            buildNode(groupNode, definition.getPropertiesInGroup(group.getName()), configs);
            children.add(groupNode);
        }

        root.setChildren(children.toArray(new TreeNode[children.size()]));
View Full Code Here

                    parent.setAttribute(ATTRIB_ALL_SAME, false);
                }
                children.add(node);
            } else if (definition instanceof PropertyDefinitionMap) {
                PropertyDefinitionMap defMap = (PropertyDefinitionMap) definition;
                TreeNode mapNode = new TreeNode(defMap.getDisplayName());
                ArrayList<PropertyMap> properties = new ArrayList<PropertyMap>();
                for (AbstractPropertyMap map : maps) {
                    if (map instanceof PropertyMap) {
                        properties.add((PropertyMap) map);
                    } else {
                        // map is a Configuration
                        String name = definition.getName();
                        PropertyMap innerMap = map.getMap(name);
                        properties.add(innerMap);
                        // TODO recursively add the map's items
                    }
                }
                buildNode(mapNode, defMap.getOrderedPropertyDefinitions(), properties);
                if (!mapNode.getAttributeAsBoolean(ATTRIB_ALL_SAME)) {
                    parent.setAttribute(ATTRIB_ALL_SAME, false);
                }
                children.add(mapNode);
            } else if (definition instanceof PropertyDefinitionList) {
                PropertyDefinitionList defList = (PropertyDefinitionList) definition;
                TreeNode listNode = new TreeNode(defList.getDisplayName());
                listNode.setAttribute(ATTRIB_ALL_SAME, true);
                if (defList.getMemberDefinition() instanceof PropertyDefinitionMap) { // support list-o-maps only
                    PropertyDefinition memberDef = defList.getMemberDefinition();
                    Collection<PropertyDefinition> memberDefColl = new ArrayList<PropertyDefinition>(1);
                    memberDefColl.add(memberDef);

                    int max = 0; // will be the largest size of any of our lists that are being compared
                    for (AbstractPropertyMap map : maps) {
                        try {
                            int size = map.getList(defList.getName()).getList().size();
                            if (size > max) {
                                max = size;
                            }
                        } catch (Throwable t) {
                            // paranoia - just skip so we don't kill entire compare window if our config doesn't have proper list-o-map
                        }
                    }
                    ArrayList<TreeNode> innerChildren = new ArrayList<TreeNode>();
                    for (int i = 0; i < max; i++) {
                        TreeNode listItemNode = new TreeNode(String.valueOf(i));
                        ArrayList<PropertyMap> properties = new ArrayList<PropertyMap>();
                        for (AbstractPropertyMap map : maps) {
                            try {
                                List<Property> list = map.getList(defList.getName()).getList();
                                if (list.size() < (i + 1)) {
                                    properties.add(new PropertyMap()); // this list didn't have an i-th item, just use an empty map
                                } else {
                                    properties.add((PropertyMap) list.get(i));
                                }
                            } catch (Throwable t) {
                                // paranoia - just skip so we don't kill entire compare window if our config doesn't have proper list-o-map
                                properties.add(new PropertyMap());
                            }
                        }
                        buildNode(listItemNode, memberDefColl, properties);
                        if (!listItemNode.getAttributeAsBoolean(ATTRIB_ALL_SAME)) {
                            parent.setAttribute(ATTRIB_ALL_SAME, false);
                            listNode.setAttribute(ATTRIB_ALL_SAME, false); // any diffs always causes this to indicate the diff
                        }
                        innerChildren.add(listItemNode);
                    }
View Full Code Here

TOP

Related Classes of com.smartgwt.client.widgets.tree.TreeNode

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.