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

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

Introduction

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

Prototype

public boolean isSelected() 

Source Link

Document

Determines whether this item is currently selected.

Usage

From source file:com.edgenius.wiki.gwt.client.page.widgets.PageTreeWidget.java

License:Open Source License

/**
 * Create HorizontalPanel for expand, collapse, etc. functions
 * @return//from  www  .  j a  va  2 s.  c  om
 */

public HorizontalPanel getFunctionButtons() {
    HorizontalPanel panel = new HorizontalPanel();
    Image expand = new Image(IconBundle.I.get().expand());
    expand.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            expand();
        }
    });
    Image collapse = new Image(IconBundle.I.get().collapse());
    collapse.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            collapse();
        }
    });
    Image refresh = new Image(IconBundle.I.get().refresh());
    refresh.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            String selected = null;
            if (rootItem != null)
                selected = (String) rootItem.getUserObject();
            for (Iterator<TreeItem> iter = tree.treeItemIterator(); iter.hasNext();) {
                TreeItem item = iter.next();
                if (item.isSelected()) {
                    selected = (String) item.getUserObject();
                    break;
                }
            }
            refreshTree(spaceUname, selected);
        }
    });

    panel.add(expand);
    panel.add(collapse);
    panel.add(refresh);
    return panel;
}

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.
 * //from  ww w .  j a  v a  2  s.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;
}