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

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

Introduction

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

Prototype

public TreeItem getParentItem() 

Source Link

Document

Gets this item's parent.

Usage

From source file:org.gss_project.gss.web.client.Groups.java

License:Open Source License

private void onSelection(TreeItem item) {
    final Object selected = item.getUserObject();
    // Preserve the previously selected item, so that the current's
    // onClick() method gets a chance to find it.
    if (getPrevious() != null)
        getPrevious().getWidget().removeStyleName("gss-SelectedRow");
    setCurrent(item);//from w ww. j  a  v  a  2  s  .c  om
    getCurrent().getWidget().addStyleName("gss-SelectedRow");
    setPrevious(getCurrent());
    GSS.get().setCurrentSelection(selected);
    //cache the latest top level node (group) for selecting and expanding on refresh
    if (item.getParentItem() == null)
        selectedGroup = item.getText();
    else
        selectedGroup = item.getParentItem().getText();
}

From source file:org.gss_project.gss.web.client.rest.resource.FolderResource.java

License:Open Source License

/**
 * this method constructs the partial path of a given TreeItem using it's text
 *
 * @param selectedItem the selectedItem to check
 *//*from w w  w .j  av a  2 s. c  o  m*/
private String constructPartialPath(TreeItem selectedItem) {
    String result = DisplayHelper.trim(selectedItem.getText());
    TreeItem parent = selectedItem.getParentItem();
    while (!(DisplayHelper.trim(parent.getText()).equals("My Shared")
            || DisplayHelper.trim(parent.getText()).equals("Other's Shared")
            || DisplayHelper.trim(parent.getText()).equals("Trash"))) {
        result = DisplayHelper.trim(parent.getText()) + "/" + result;
        if (result.equals("My Shared") || result.equals("Other's Shared"))
            return result;
        parent = parent.getParentItem();
    }

    return result;
}

From source file:org.gss_project.gss.web.client.rest.resource.FolderResource.java

License:Open Source License

/**
 * examine whether a folder name like "Trash", "My Shared", "Other's Shared" is inside path
 *
 * @param selectedItem the selectedTreeItem to check
 *///from   ww  w .j  a v a2 s  .com

private boolean containsFolder(TreeItem selectedItem, String folderName) {
    TreeItem parent = selectedItem.getParentItem();
    while (parent != null) {
        String parentItemText = parent.getText();
        String parentItemTextTr = DisplayHelper.trim(parentItemText);
        if (parentItemTextTr.equals(folderName))
            return true;
        parent = parent.getParentItem();
    }
    return false;
}

From source file:org.gss_project.gss.web.client.rest.resource.FolderResource.java

License:Open Source License

@Override
public String constructUri(TreeItem treeItem, String path) {
    String constructedUri = "";
    if (containsFolder(treeItem, "My Shared")) {
        //case: selected folders below My Shared folder
        String partialUri = constructPartialPath(treeItem);
        constructedUri = constructedUri + "Files/shared/" + partialUri;
        return constructedUri;
    } else if (containsFolder(treeItem, "Other's Shared")) {
        //case: selected folders below Other's Shared folder
        String partialPath = constructPartialPath(treeItem);
        constructedUri = constructedUri + "Files/others/" + partialPath;
        return constructedUri;
    } else if (getParentURI() == null) {
        if (containsFolder(treeItem, "Trash")) {
            //case: selected folders below Trash folder
            String partialUri = constructPartialPath(treeItem);
            constructedUri = constructedUri + "Files/trash/" + partialUri;
            return constructedUri;
        }// w ww  . j  a  v  a 2s  .c  om
        //case: home folder is selected
        constructedUri = constructedUri + "Files/files/" + getName();
        return constructedUri;
    } else if (treeItem.getParentItem() == null) {
        //this is the case when the user uses the browser's forward arrow to navigate through other's
        //shared folders and item.getParentItem is null only inside other's shared folder
        String apiPath = GSS.get().getApiPath();
        String newPath = getParentURI().substring(apiPath.lastIndexOf("/"));
        constructedUri = constructedUri + "Files" + newPath + getName();
        return constructedUri;
    } else {
        String finalUri = getParentURI().substring(path.lastIndexOf("/")) + getName();
        constructedUri = constructedUri + "Files" + finalUri;
        return constructedUri;
    }

}

From source file:org.iucn.sis.client.ui.TreeTable.java

License:Apache License

/**
 * Constructs an empty tree.//from w w w.j av  a 2  s . c  o m
 */
public TreeTable() {
    Element tableElem = getElement();
    headElem = DOM.createElement("thead");
    Element tr = DOM.createTR();
    DOM.appendChild(headElem, tr);
    DOM.insertChild(tableElem, headElem, 0);

    DOM.setStyleAttribute(getElement(), "position", "relative");
    // focusable = impl.createFocusable();
    // DOM.setStyleAttribute(focusable, "fontSize", "0");
    // DOM.setStyleAttribute(focusable, "position", "absolute");
    // DOM.setIntStyleAttribute(focusable, "zIndex", -1);
    // DOM.appendChild(getElement(), focusable);

    sinkEvents(Event.MOUSEEVENTS | Event.ONCLICK | Event.KEYEVENTS);
    // DOM.sinkEvents(focusable, Event.FOCUSEVENTS | Event.KEYEVENTS |
    // DOM.getEventsSunk(focusable));

    // The 'root' item is invisible and serves only as a container
    // for all top-level items.
    root = new TreeItem() {
        @Override
        public void addItem(TreeItem item) {
            // If this element already belongs to a tree or tree item,
            // remove it.
            if ((item.getParentItem() != null) || (item.getTreeTable() != null)) {
                item.remove();
            }
            item.setTreeTable(this.getTreeTable());

            // Explicitly set top-level items' parents to null.
            item.setParentItem(null);
            getChildren().add(item);

            // Use no margin on top-most items.
            DOM.setIntStyleAttribute(item.getElement(), "marginLeft", 0);
        }

        @Override
        public void removeItem(TreeItem item) {
            if (!getChildren().contains(item)) {
                return;
            }
            // Update Item state.
            item.setTreeTable(null);
            item.setParentItem(null);
            getChildren().remove(item);
        }
    };
    root.setTreeTable(this);
    setStyleName("gwt-TreeTable");
}

From source file:org.iucn.sis.client.ui.TreeTable.java

License:Apache License

/**
 * Ensures that the currently-selected item is visible, opening its parents
 * and scrolling the tree as necessary.//from  w w  w. ja v a 2s.c o m
 */
public void ensureSelectedItemVisible() {
    if (curSelection == null) {
        return;
    }

    TreeItem parent = curSelection.getParentItem();
    while (parent != null) {
        parent.setState(true);
        parent = parent.getParentItem();
    }
}

From source file:org.iucn.sis.client.ui.TreeTable.java

License:Apache License

protected TreeItem getNextNonChild(TreeItem item) {
    TreeItem next = getNextSibling(item);
    if (next != null) {
        return next;
    }//w ww  .j  a  v  a 2s  .  c om
    TreeItem p = item.getParentItem();
    if (p != null) {
        return getNextNonChild(p);
    } else {
        return null;
    }
}

From source file:org.iucn.sis.client.ui.TreeTable.java

License:Apache License

protected TreeItem getNextSibling(TreeItem item) {
    TreeItem p = item.getParentItem();
    if (p == null) {
        int idx = root.getChildIndex(item) + 1;
        if (idx < root.getChildCount()) {
            // Gets the next sibling
            return root.getChild(idx);
        }/*w ww.  j  a v a 2  s . c om*/
    } else {
        int idx = p.getChildIndex(item) + 1;
        if (idx < p.getChildCount()) {
            // Gets the next sibling
            return p.getChild(idx);
        }
    }
    return null;
}

From source file:org.iucn.sis.client.ui.TreeTable.java

License:Apache License

/**
 * Updates table rows to include children.
 * /*  www .j  a  va  2s  .  c  o m*/
 * @param item
 */
void insertItem(TreeItem item, int r) {
    // inserts this item into the tree
    insertRow(r);
    setWidget(r, getTreeColumn(), item);
    item.setRow(r);
    render(item);

    ArrayList chlds = item.getChildren();
    for (int i = 0, s = chlds.size(); i < s; i++) {
        TreeItem chld = (TreeItem) chlds.get(i);
        insertItem(chld, r + 1);
    }

    TreeItem p = item.getParentItem();
    if (p != null) {
        if (!p.isOpen()) {
            setVisible(false, item.getRow());
            setChildrenVisible(item, false);
        }
    }
}

From source file:org.iucn.sis.client.ui.TreeTable.java

License:Apache License

/**
 * Moves to the next item, going into children as if dig is enabled.
 *///w w  w  .  j a v a  2 s . c o  m
private void moveSelectionDown(TreeItem sel, boolean dig) {
    if (sel == root) {
        return;
    }

    TreeItem parent = sel.getParentItem();
    if (parent == null) {
        parent = root;
    }
    int idx = parent.getChildIndex(sel);

    if (!dig || !sel.getState()) {
        if (idx < parent.getChildCount() - 1) {
            onSelection(parent.getChild(idx + 1), true);
        } else {
            moveSelectionDown(parent, false);
        }
    } else if (sel.getChildCount() > 0) {
        onSelection(sel.getChild(0), true);
    }
}