Package com.smartgwt.client.widgets.tree

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


                    platformServicesGrid.setData(platformServicesRecords
                        .toArray(new ListGridRecord[platformServicesRecords.size()]));
                    Tree tree = new Tree();
                    tree.setModelType(TreeModelType.CHILDREN);
                    tree.setChildrenProperty(ATTRIB_CHILDREN);
                    TreeNode rootNode = new TreeNode("0");
                    tree.setRoot(rootNode);

                    for (Integer topServerId : topServers) {
                        ResourceTypeTreeNode topServerNode = serversNodes.get(topServerId);
                        topServerNode = topServerNode.copy();
View Full Code Here


                // stop the browser right-click menu
                event.cancel();

                // don't select the node on a right click, since we're not navigating to it
                treeGrid.deselectRecord(event.getNode());
                TreeNode eventNode = event.getNode();

                // re-select the current node if necessary
                if (null != selectedNodeId) {
                    TreeNode selectedNode = treeGrid.getTree().findById(selectedNodeId);
                    if (!eventNode.equals(selectedNode)) {
                        treeGrid.selectRecord(selectedNode);
                    }
                }

                if (eventNode instanceof AutoGroupTreeNode) {
                    showContextMenu((AutoGroupTreeNode) eventNode);
                } else if (eventNode instanceof ResourceTreeNode) {
                    if (!((ResourceTreeNode) eventNode).isLocked()) {
                        showContextMenu((ResourceTreeNode) eventNode);
                    }
                }
            }
        });

        treeGrid.addDataArrivedHandler(new DataArrivedHandler() {

            public void onDataArrived(DataArrivedEvent dataArrivedEvent) {
                TreeNode parent = dataArrivedEvent.getParentNode();

                // always expand the parent when new data arrives underneath, it means the user has expanded the node
                if (parent instanceof EnhancedTreeNode) {
                    treeGrid.getTree().openFolder(parent);
                    treeGrid.markForRedraw();
                }

                // if for some reason expansion has caused our selection to be lost then make sure it is again properly selected
                ListGridRecord selectedRecord = treeGrid.getSelectedRecord();
                TreeNode selectedNode = null != selectedNodeId ? treeGrid.getTree().findById(selectedNodeId) : null;

                if (null != selectedNode && !selectedNode.equals(selectedRecord)) {
                    updateSelection();
                }
            }
        });
    }
View Full Code Here

        updateSelection(false);
    }

    private void updateSelection(boolean isRefresh) {

        TreeNode selectedNode;

        if (treeGrid != null && treeGrid.getTree() != null
            && (selectedNode = treeGrid.getTree().findById(selectedNodeId)) != null) {

            TreeNode[] parents = treeGrid.getTree().getParents(selectedNode);
            treeGrid.getTree().openFolders(parents);
            treeGrid.getTree().openFolder(selectedNode);

            if (!selectedNode.equals(treeGrid.getSelectedRecord())) {
                treeGrid.deselectAllRecords();
                treeGrid.selectRecord(selectedNode);
            }

            if (isRefresh) {
View Full Code Here

        // determine if the refresh node is an ancestor of the selected node.
        boolean isAncestor = false;

        ListGridRecord selectedRecord = treeGrid.getSelectedRecord();
        if (null != selectedRecord) {
            TreeNode ancestor = (TreeNode) selectedRecord;
            while (null != (ancestor = treeGrid.getTree().getParent(ancestor))) {
                if (node.equals(ancestor)) {
                    isAncestor = true;
                    break;
                }
            }
        }

        // Case 1: An ancestor
        if (isAncestor) {
            // prune the existing subtree rooted at the refresh node, it will be rebuilt when we re-navigate to the
            // selected node.
            treeGrid.getTree().remove(node);

            if (selectedRecord instanceof ResourceTreeNode) {
                setSelectedResource(((ResourceTreeNode) selectedRecord).getResource().getId(), false);
            } else if (selectedRecord instanceof AutoGroupTreeNode) {
                Integer backingGroupId = ((AutoGroupTreeNode) selectedRecord).getResourceGroupId();
                if (null != backingGroupId) {
                    setSelectedAutoGroup(backingGroupId);
                }
            }
            return;
        }

        // Case 2: Not an ancestor

        // refresh the view. This won't refresh the tree since the resource hasn't changed, and
        // we don't really want to refresh the whole tree anyway.
        if (!treeOnly) {
            CoreGUI.refresh();
        }

        // if this is the root just refresh from the top
        Tree tree = treeGrid.getTree();
        TreeNode refreshNode = tree.getParent(node);
        if (null == refreshNode.getName()) {
            tree.reloadChildren(node);
            return;
        }

        // reloads are performed only on resource nodes. find the first parental resource node, traversing
View Full Code Here

                                        ResourceTreeDatasource.buildNodes(lineage, lockedData, treeGrid));

                                    CoreGUI.showBusy(false);;

                                    if (updateSelection) {
                                        TreeNode selectedNode = treeGrid.getTree().findById(selectedNodeId);
                                        if (selectedNode != null && updateSelection) {
                                            updateSelection();

                                        } else {
                                            CoreGUI.getMessageCenter().notify(
View Full Code Here

                            ListGridRecord[] dataRecords = buildRecords(allVisibleBundleGroups);
                            for (ListGridRecord dataRecord : dataRecords) {
                                // we only want to examine bundle group records - and they are the only ones
                                // with ID attributes that are a simple number without "_" character.
                                // Ignore the Unassigned Bundle Group (whose id = "0") - never show a lock for that.
                                TreeNode dataRecordNode = (TreeNode) dataRecord;
                                String idString = dataRecordNode.getAttribute("id");
                                if (!idString.contains("_") && !idString.equals("0")
                                    && !permittedBundleGroups.contains(Integer.valueOf(idString))) {
                                    dataRecordNode.setIcon(ImageManager.getLockedIcon());
                                    dataRecordNode.setEnabled(false);
                                }
                            }
                            response.setData(dataRecords);
                            response.setTotalRows(allVisibleBundleGroups.size());
                            processResponse(request.getRequestId(), response);
View Full Code Here

                Set<Bundle> bundles = bundleGroup.getBundles();
                if (bundles != null) {
                    for (Bundle bundle : bundles) {
                        records.add(copyValuesForKnownBundle(bundle, bundleGroup.getId(), bundle.getId()));
                        // while we are here, automatically add the two direct children - the versions and destinations folders
                        TreeNode versionNode = new TreeNode(MSG.view_bundle_versions());
                        versionNode.setID(bundleGroup.getId() + "_" + bundle.getId() + "_versions");
                        versionNode.setParentID(bundleGroup.getId() + "_" + bundle.getId());
                        versionNode.setName(MSG.view_bundle_versions());
                        records.add(versionNode);

                        TreeNode deploymentsNode = new TreeNode(MSG.view_bundle_destinations());
                        deploymentsNode.setID(bundleGroup.getId() + "_" + bundle.getId() + "_destinations");
                        deploymentsNode.setParentID(bundleGroup.getId() + "_" + bundle.getId());
                        deploymentsNode.setName(MSG.view_bundle_destinations());
                        records.add(deploymentsNode);
                    }
                }

            } else if (item instanceof Bundle) {
                Bundle bundle = (Bundle) item;

                // each bundle has two direct children - the versions and destinations folders
                TreeNode versionNode = new TreeNode(MSG.view_bundle_versions());
                versionNode.setID(bundleGroupId.toString() + "_" + bundle.getId() + "_versions");
                versionNode.setParentID(bundleGroupId.toString() + "_" + bundle.getId());
                versionNode.setName(MSG.view_bundle_versions());
                records.add(versionNode);

                TreeNode deploymentsNode = new TreeNode(MSG.view_bundle_destinations());
                deploymentsNode.setID(bundleGroupId.toString() + "_" + bundle.getId() + "_destinations");
                deploymentsNode.setParentID(bundleGroupId.toString() + "_" + bundle.getId());
                deploymentsNode.setName(MSG.view_bundle_destinations());
                records.add(deploymentsNode);

            } else if (item instanceof BundleDestination) {
                BundleDestination dest = (BundleDestination) item;
View Full Code Here

        return copyValuesForKnownBundle(from, null, null);
    }

    private ListGridRecord copyValuesForKnownBundle(Object from, Integer bundleGroupId, Integer bundleId) {
        String parentID;
        TreeNode node = new TreeNode();
        String sortValue = "";

        if (from instanceof BundleGroup) {
            BundleGroup bundleGroup = (BundleGroup) from;
            node.setIsFolder(true);
            node.setIcon("subsystems/bundle/BundleGroup_16.png");
            node.setID(String.valueOf(bundleGroup.getId()));
            node.setName(StringUtility.escapeHtml(bundleGroup.getName()));

            if (bundleGroup.getId() == 0) {
                node.setEnabled(false);
                sortValue = "\uFFFDZZZZ"; // always show this as the last folder node in the tree
            } else{
                sortValue = bundleGroup.getName();
            }
        } else if (from instanceof Bundle) {
            Bundle bundle = (Bundle) from;
            node.setIsFolder(true);
            node.setIcon("subsystems/bundle/Bundle_16.png");
            node.setID(String.valueOf(bundleGroupId) + "_" + bundle.getId());
            node.setParentID(String.valueOf(bundleGroupId));
            node.setName(StringUtility.escapeHtml(bundle.getName()));
            sortValue = bundle.getName();
        } else if (from instanceof BundleVersion) {
            BundleVersion version = (BundleVersion) from;
            node.setIsFolder(false);
            node.setIcon("subsystems/bundle/BundleVersion_16.png");
            parentID = bundleGroupId.toString() + "_" + version.getBundle().getId() + "_versions";
            node.setParentID(parentID);
            node.setID(parentID + '_' + version.getId());
            node.setName(version.getVersion());
            sortValue = NumberFormat.getFormat("000000").format(version.getVersionOrder());

        } else if (from instanceof BundleDeployment) {
            BundleDeployment deployment = (BundleDeployment) from;
            node.setIsFolder(false);
            node.setIcon("subsystems/bundle/BundleDeployment_16.png");
            parentID = bundleGroupId.toString() + "_" + bundleId + "_destinations_" + deployment.getDestination().getId();
            node.setParentID(parentID);
            node.setID(bundleGroupId.toString() + "_" + bundleId + "_deployments_" + deployment.getId());
            String name = StringUtility.escapeHtml(deployment.getName());
            if (deployment.isLive()) {
                node.setName("<span style=\"color: green; font-weight: bold\">(live)</span> " + name);
            } else {
                node.setName(name);
            }
            sortValue = deployment.getName();

        } else if (from instanceof BundleDestination) {
            BundleDestination destination = (BundleDestination) from;
            node.setIsFolder(true);
            node.setIcon("subsystems/bundle/BundleDestination_16.png");
            parentID = bundleGroupId.toString() + "_" + destination.getBundle().getId() + "_destinations";
            node.setParentID(parentID);
            node.setID(parentID + '_' + destination.getId());
            node.setName(StringUtility.escapeHtml(destination.getName()));
            sortValue = destination.getName();
        }

        node.setAttribute(FIELD_SORT_VALUE, sortValue.toLowerCase());

        return node;
    }
View Full Code Here

        setDataSource(new BundleTreeDataSource());

        addNodeClickHandler(new NodeClickHandler() {
            public void onNodeClick(NodeClickEvent event) {
                TreeNode node = event.getNode();
                String path = node.getAttribute("id").replaceAll("_", "/");

                // the node ID is the path the form <bundleGroupId>_<the rest of the node ID>
                String[] splitPath = path.split("/", 2);

                try {
View Full Code Here

                    key = String.valueOf(currentlySelectedBundleGroupId) + '_'; // all keys start with the parent group ID
                }

                key += view.getPath();

                TreeNode node = theTree.findById(key);

                // special case code to handle a "deployments" path. the path structure does not mirror the
                // tree structure, so we may have to manually force the "destinations" folder to open.
                if (node == null) {
                    if (key.endsWith("deployments")) {
                        String tempKey = key.replace("deployments", "destinations");
                        node = theTree.findById(tempKey);
                    }
                }

                if (node != null) {
                    // open the node, this will force a fetch of child data if necessary
                    theTree.openFolder(node);

                    // special case code to handle a "deployments" path. the path structure does not mirror the
                    // tree structure, so we may have to manually force the "destinations" folder to open, and
                    // then its children (deployment nodes)
                    if (key.endsWith("deployments")) {
                        theTree.openFolders(theTree.getChildren(node));
                    }
                } else {
                    // wait for data to get loaded...
                    pendingPath = new ViewPath(viewPath.toString());
                    return;
                }
            }

            // we found the node, so keep going
            pendingPath = null;

            final String finalKey = key;
            GWT.runAsync(new RunAsyncCallback() {
                public void onFailure(Throwable reason) {
                }

                public void onSuccess() {
                    TreeNode node = getTree().findById(finalKey);
                    if (node != null) {
                        deselectAllRecords();
                        selectRecord(node);
                    }
                }
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.