Search in sources :

Example 1 with StoreRemoveEvent

use of org.eclipse.che.ide.ui.smartTree.event.StoreRemoveEvent in project che by eclipse.

the class NodeStorage method remove.

public boolean remove(Node node) {
    NodeDescriptor nodeDescriptor = idToNodeMap.get(getKeyProvider().getKey(node));
    if (nodeDescriptor != null) {
        Node parent = getParent(node);
        List<Node> children = getAllChildren(node);
        int visibleIndex = nodeDescriptor.getParent().getChildren().indexOf(nodeDescriptor);
        nodeDescriptor.getParent().remove(nodeDescriptor);
        if (visibleIndex != -1) {
            fireEvent(new StoreRemoveEvent(visibleIndex, node, parent, children));
        } else {
            List<NodeDescriptor> descriptors = new LinkedList<>();
            descriptors.add(nodeDescriptor);
            for (int i = 0; i < descriptors.size(); i++) {
                nodeDescriptor = descriptors.get(i);
                descriptors.addAll(nodeDescriptor.getChildren());
                idToNodeMap.remove(getKeyProvider().getKey(nodeDescriptor.getNode()));
            }
        }
        return true;
    }
    return false;
}
Also used : Node(org.eclipse.che.ide.api.data.tree.Node) StoreRemoveEvent(org.eclipse.che.ide.ui.smartTree.event.StoreRemoveEvent) LinkedList(java.util.LinkedList)

Example 2 with StoreRemoveEvent

use of org.eclipse.che.ide.ui.smartTree.event.StoreRemoveEvent in project che by eclipse.

the class NodeStorage method removeChildren.

private void removeChildren(NodeDescriptor parent) {
    if (parent.getChildren().size() != 0) {
        List<NodeDescriptor> models = new LinkedList<>();
        models.addAll(parent.getChildren());
        parent.clear();
        for (int i = 0; i < models.size(); i++) {
            NodeDescriptor wrapper = models.get(i);
            models.addAll(wrapper.getChildren());
            List<Node> children = getAllChildren(wrapper.getNode());
            idToNodeMap.remove(getKeyProvider().getKey(wrapper.getNode()));
            if (wrapper.getParent() == parent) {
                fireEvent(new StoreRemoveEvent(0, wrapper.getNode(), parent.getNode(), children));
            }
        }
    }
}
Also used : Node(org.eclipse.che.ide.api.data.tree.Node) StoreRemoveEvent(org.eclipse.che.ide.ui.smartTree.event.StoreRemoveEvent) LinkedList(java.util.LinkedList)

Aggregations

LinkedList (java.util.LinkedList)2 Node (org.eclipse.che.ide.api.data.tree.Node)2 StoreRemoveEvent (org.eclipse.che.ide.ui.smartTree.event.StoreRemoveEvent)2