Example usage for com.google.gwt.user.client.ui TreeItem getChild

List of usage examples for com.google.gwt.user.client.ui TreeItem getChild

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui TreeItem getChild.

Prototype

public TreeItem getChild(int index) 

Source Link

Document

Gets the child at the specified index.

Usage

From source file:com.ikon.frontend.client.widget.Dragable.java

License:Open Source License

/**
 * Prevents folder incosistences changing moved path on childs recursivelly
 * nodes drawed//from w w  w.j a  v  a  2s. co  m
 * 
 * @param item The tree node
 */
public void preventFolderInconsitences(TreeItem item, String oldPath, String newPath, String parentPath) {
    GWTFolder folderItem = (GWTFolder) item.getUserObject();

    folderItem.setPath(folderItem.getPath().replaceFirst(oldPath, newPath));
    folderItem.setParentPath(parentPath);

    // Recursively changing paht value
    for (int i = 0; i < item.getChildCount(); i++) {
        preventFolderInconsitences(item.getChild(i), oldPath, newPath, folderItem.getPath());
    }
}

From source file:com.ikon.frontend.client.widget.foldertree.ExtendedTree.java

License:Open Source License

/**
 * findItemByChain/*from ww  w. j  a va 2 s  . c o m*/
 */
private TreeItem findItemByChain(Vector<Element> chain, int idx, TreeItem root) {
    if (idx == chain.size())
        return root;

    Element hCurElem = (Element) chain.get(idx);

    if (root == null) {
        for (int i = 0, n = this.getItemCount(); i < n; ++i) {
            TreeItem child = this.getItem(i);
            if (child.getElement() == hCurElem) {
                TreeItem retItem = findItemByChain(chain, idx + 1, child);
                if (retItem == null)
                    return child;
                return retItem;
            }
        }
    } else {
        for (int i = 0, n = root.getChildCount(); i < n; ++i) {
            TreeItem child = root.getChild(i);
            if (child.getElement() == hCurElem) {
                TreeItem retItem = findItemByChain(chain, idx + 1, root.getChild(i));
                if (retItem == null)
                    return child;
                return retItem;
            }
        }
    }

    return findItemByChain(chain, idx + 1, root);
}

From source file:com.ikon.frontend.client.widget.foldertree.FolderTree.java

License:Open Source License

/**
 * Change recursivelly all the childs path
 * //from  w w  w .  j  a v  a 2s .co  m
 * @param oldPath
 *            The old path
 * @param newPath
 *            The new path
 * @param itemToChange
 *            The tree item to change the path
 */
public void changePathBeforeRenaming(String oldPath, String newPath, TreeItem itemToChange) {
    for (int i = 0; i < itemToChange.getChildCount(); i++) {
        TreeItem tmpItem = itemToChange.getChild(i);
        GWTFolder gwtFolder = ((GWTFolder) tmpItem.getUserObject());
        gwtFolder.setPath(gwtFolder.getPath().replaceAll(oldPath, newPath));
        gwtFolder.setParentPath(gwtFolder.getParentPath().replaceAll(oldPath, newPath));
        if (tmpItem.getChildCount() > 0) {
            changePathBeforeRenaming(oldPath, newPath, tmpItem);
        }
    }
}

From source file:com.ikon.frontend.client.widget.popup.FolderSelectTree.java

License:Open Source License

/**
 * Prevents folder incosistences between server ( multi user deletes folder ) and tree
 * nodes drawed/* w  ww.  jav a2  s.  co  m*/
 * 
 * @param item The tree node
 */
public void preventFolderInconsitences(TreeItem item) {
    GWTFolder folderItem = (GWTFolder) item.getUserObject();

    // Case that must remove all items node
    if (item.getChildCount() > 0 && !folderItem.isHasChildren()) {
        while (item.getChildCount() > 0) {
            item.getChild(0).remove();
        }
    }
    if (item.getChildCount() < 1 && !folderItem.isHasChildren()) {
        folderItem.setHasChildren(false);
    }
}

From source file:com.qtitools.editor.client.ProjectExplorer.java

License:Open Source License

/**
 * get titles from assessment/*from   www .  j  av a 2  s .  c  om*/
 */
private void updateItemList() {

    TreeItem treeItem;
    TreeItem root;

    root = itemsTree.addItem(assessment.getTitle());

    for (int i = 0; i < assessment.getItemCount(); i++) {
        treeItem = root.addItem(assessment.getItemTitle(i));
        treeItemsId.put(treeItem, new Integer(i));
    }

    root.setState(true);
    if (treeItemsId.size() > 0)
        itemsTree.setSelectedItem(root.getChild(0), false);

}

From source file:com.qualogy.qafe.gwt.client.component.QTree.java

License:Apache License

private void clearItems() {
    if (showRootItem) {
        TreeItem rootItem = getItem(0);
        if (rootItem != null) {
            int childCount = rootItem.getChildCount();
            for (int i = childCount - 1; i >= 0; i--) {
                rootItem.getChild(i).remove();
            }/*from   w  ww  .j  av a 2 s  .  co  m*/
        }
    } else {
        int childCount = this.getItemCount();
        for (int i = childCount - 1; i >= 0; i--) {
            this.getItem(i).remove();
        }
    }
}

From source file:com.xpn.xwiki.watch.client.ui.feedtree.FeedTreeWidget.java

License:Open Source License

/**
 * Check if tree needs to be rebuilt. This happens when a feed has been added or deleted or a feed has been moved
 * from a group to another, or when a feed / group has been renamed and the order of the nodes has changed due to
 * this rename. The comparison is made by comparing the current tree with the data from config. TODO: implement
 * correctly the notification mechanism to pass events to the UI so that we know exactly which type of update we are
 * doing and this function is not needed any more. see http://jira.xwiki.org/jira/browse/XWATCH-83
 * //from   www. j av a 2 s.co m
 * @return true if a rebuild of the whole feed tree is needed, false if widgets update is enough
 */
private boolean remakeTreeRequired() {
    if (this.groupTree == null) {
        return true;
    }
    Map feedsbygroup = watch.getConfig().getFeedsByGroupList();
    Map groups = watch.getConfig().getGroups();
    // check groups and their order
    List groupNames = new ArrayList(feedsbygroup.keySet());
    if (groupNames.size() != this.groupTree.getItemCount()) {
        return true;
    }
    Collections.sort(groupNames, new GroupComparator(groups, "All"));
    for (int i = 0; i < groupNames.size(); i++) {
        TreeItem currentGroupItem = this.groupTree.getItem(i);
        GroupTreeItemObject groupUserObject = (GroupTreeItemObject) currentGroupItem.getUserObject();
        String treeGroupName = ((Group) groupUserObject.getData()).getName();
        if (!(((Group) groups.get(groupNames.get(i))).getName()).equals(treeGroupName)) {
            // the group on this position does not match
            return true;
        }
        Map groupFeeds = (Map) feedsbygroup.get(groupNames.get(i));
        // check feed names in this group, and their order
        List feedNames = new ArrayList(groupFeeds.keySet());
        if (feedNames.size() != currentGroupItem.getChildCount()) {
            return true;
        }
        Collections.sort(feedNames, new FeedComparator(groupFeeds, null));
        for (int j = 0; j < feedNames.size(); j++) {
            if (!feedNames.get(j).equals(
                    ((Feed) ((FeedTreeItemObject) currentGroupItem.getChild(j).getUserObject()).getData())
                            .getName())) {
                return true;
            }
        }
    }
    return false;
}

From source file:com.xpn.xwiki.watch.client.ui.feedtree.FeedTreeWidget.java

License:Open Source License

/**
 * Updates the feed tree with the new data. Iterates through all the groups and feeds and resets their data with the
 * new data obtained from config, refreshing the displayed widget. It also resets selection of the tree widget
 * according to the tree item selection.
 * /* www.  j a  v a2s .  c  o  m*/
 * @return true if update has succeeded, false if inconsistencies have been found during the update process. call
 *         {@link FeedTreeWidget#makeFeedTree()} to create the tree from scratch if this function fails.
 */
private boolean updateFeedTree() {
    // update the feed tree according to the new data
    Map feedsbygroup = watch.getConfig().getFeedsByGroupList();
    Map groups = watch.getConfig().getGroups();
    List groupKeys = new ArrayList(feedsbygroup.keySet());
    Collections.sort(groupKeys, new GroupComparator(groups, "All"));
    for (int i = 0; i < this.groupTree.getItemCount(); i++) {
        TreeItem currentGroupItem = this.groupTree.getItem(i);
        GroupTreeItemObject groupUserObject = (GroupTreeItemObject) currentGroupItem.getUserObject();
        String currentGroupKey = (String) groupKeys.get(i);
        Group foundGroup = (Group) groups.get(currentGroupKey);
        // special case for the All group
        if (foundGroup == null) {
            foundGroup = new Group();
            foundGroup.setName(currentGroupKey);
        }
        groupUserObject.setData(foundGroup, true);
        // set selected if needed
        groupUserObject.setSelected(currentGroupItem.isSelected());
        Map groupFeeds = (Map) feedsbygroup.get(currentGroupKey);
        // for each feed in the tree, find it in the data map and update it
        for (int j = 0; j < currentGroupItem.getChildCount(); j++) {
            TreeItem currentFeedItem = currentGroupItem.getChild(j);
            FeedTreeItemObject feedUserObject = (FeedTreeItemObject) currentFeedItem.getUserObject();
            Feed currentTreeFeed = (Feed) feedUserObject.getData();
            // get feed from the new data
            Feed foundFeed = (Feed) groupFeeds.get(currentTreeFeed.getName());
            if (foundFeed == null) {
                // then there is an inconsistency of some sort, better remake tree
                return false;
            } else {
                // otherwise, reset the feed of this FeedTreeItemObject and refresh it
                feedUserObject.setData(foundFeed, true);
                // set widget's state to tree item state
                feedUserObject.setSelected(currentFeedItem.isSelected());
            }
        }
    }
    return true;
}

From source file:com.xpn.xwiki.watch.client.ui.feedtree.FeedTreeWidget.java

License:Open Source License

public void resetSelections() {
    // Check the validity of the current selection with respect to the filter
    FilterStatus fstatus = watch.getFilterStatus();
    Feed filterFeed = fstatus.getFeed();
    String filterGroupPageName = fstatus.getGroup();
    // Get currently selected item
    TreeItem selectedTreeItem = this.groupTree.getSelectedItem();
    // Get user object to check the correspondence
    TreeItemObject selectedTreeItemObject = null;
    boolean isValidTreeSelection = true;
    if (selectedTreeItem != null) {
        selectedTreeItemObject = (TreeItemObject) selectedTreeItem.getUserObject();
        if (selectedTreeItemObject instanceof GroupTreeItemObject) {
            if (filterGroupPageName != null) {
                if (!((Group) selectedTreeItemObject.getData()).getPageName().equals(filterGroupPageName)) {
                    // The filter group is not the tree group
                    isValidTreeSelection = false;
                }/*from w w  w  . ja  v a  2 s.c  om*/
            } else {
                // Group is selected in the tree but not in the filter
                isValidTreeSelection = false;
            }
        }
        if (selectedTreeItemObject instanceof FeedTreeItemObject) {
            if (filterFeed != null) {
                if (!((Feed) selectedTreeItemObject.getData()).getPageName().equals(filterFeed.getPageName())) {
                    // The filter feed is not the tree selected feed
                    isValidTreeSelection = false;
                }
            } else {
                // Feed is selected in the tree but not in the filter
                isValidTreeSelection = false;
            }
        }
    } else {
        if (filterFeed != null || filterGroupPageName != null) {
            isValidTreeSelection = false;
        }
    }

    // Now change selection if needed
    if (!isValidTreeSelection) {
        TreeItem newSelectedTreeItem = null;
        // Find the new SelectedItem
        if (filterGroupPageName != null) {
            // Iterate groups level and find the current group
            for (int i = 0; i < this.groupTree.getItemCount(); i++) {
                TreeItem currentItem = this.groupTree.getItem(i);
                Group currentGroup = (Group) (((GroupTreeItemObject) currentItem.getUserObject()).getData());
                if (currentGroup.getPageName().equals(filterGroupPageName)) {
                    // Found the item
                    newSelectedTreeItem = currentItem;
                    break;
                }
            }
        } else if (filterFeed != null) {
            // Iterate through the All group and find the current feed
            TreeItem allTreeGroup = null;
            if (this.groupTree.getItemCount() > 0) {
                allTreeGroup = this.groupTree.getItem(0);
            }
            if (allTreeGroup != null) {
                // Iterate in this group and find the selected feed
                for (int i = 0; i < allTreeGroup.getChildCount(); i++) {
                    TreeItem currentItem = allTreeGroup.getChild(i);
                    Feed currentFeed = (Feed) (((FeedTreeItemObject) currentItem.getUserObject()).getData());
                    if (currentFeed.getPageName().equals(filterFeed.getPageName())) {
                        // Found the item
                        newSelectedTreeItem = currentItem;
                        break;
                    }
                }
            }
        }
        // Unselect old selected widget
        if (selectedTreeItemObject != null) {
            selectedTreeItemObject.setSelected(false);
        }
        // Select the new tree item
        this.groupTree.setSelectedItem(newSelectedTreeItem, false);
        // Also get the widget and select it
        if (newSelectedTreeItem != null) {
            ((TreeItemObject) newSelectedTreeItem.getUserObject()).setSelected(true);
        }
    }
}

From source file:de.novanic.gwteventservice.demo.conversationapp.client.conversation.ui.GWTConversationChannelPanel.java

License:Open Source License

private boolean removeItem(TreeItem aParentItem, String anEntry) {
    for (int i = 0; i < aParentItem.getChildCount(); i++) {
        final TreeItem theChild = aParentItem.getChild(i);
        if (theChild != null) {
            if (anEntry.equals(theChild.getText())) {
                aParentItem.removeItem(theChild);
                return true;
            }/*  w w w.  j a va2s  .  c o m*/
        }
    }
    return false;
}