Search in sources :

Example 1 with NodeSettings

use of org.eclipse.che.ide.api.data.tree.settings.NodeSettings in project che by eclipse.

the class ProjectExplorerPresenter method onResourceChanged.

@Override
@SuppressWarnings("unchecked")
public void onResourceChanged(ResourceChangedEvent event) {
    final Tree tree = view.getTree();
    final ResourceDelta delta = event.getDelta();
    final Resource resource = delta.getResource();
    final NodeSettings nodeSettings = settingsProvider.getSettings();
    // process root projects, they have only one segment in path
    if (resource.getLocation().segmentCount() == 1) {
        if (delta.getKind() == ADDED) {
            if ((delta.getFlags() & (MOVED_FROM | MOVED_TO)) != 0) {
                Node node = getNode(delta.getFromPath());
                if (node != null) {
                    boolean expanded = tree.isExpanded(node);
                    tree.getNodeStorage().remove(node);
                    node = nodeFactory.newContainerNode((Container) resource, nodeSettings);
                    tree.getNodeStorage().add(node);
                    if (expanded) {
                        tree.setExpanded(node, true);
                    }
                }
            } else if (getNode(resource.getLocation()) == null) {
                tree.getNodeStorage().add(nodeFactory.newContainerNode((Container) resource, nodeSettings));
            }
        } else if (delta.getKind() == REMOVED) {
            Node node = getNode(resource.getLocation());
            if (node != null) {
                tree.getNodeStorage().remove(node);
            }
        } else if (delta.getKind() == UPDATED) {
            for (Node node : tree.getNodeStorage().getAll()) {
                if (node instanceof ResourceNode && ((ResourceNode) node).getData().getLocation().equals(delta.getResource().getLocation())) {
                    final String oldId = tree.getNodeStorage().getKeyProvider().getKey(node);
                    ((ResourceNode) node).setData(delta.getResource());
                    tree.getNodeStorage().reIndexNode(oldId, node);
                    tree.refresh(node);
                    updateTask.submit(delta.getResource().getLocation());
                }
            }
        }
    } else {
        if ((delta.getFlags() & (MOVED_FROM | MOVED_TO)) != 0) {
            final Node node = getNode(delta.getFromPath());
            if (node != null && tree.isExpanded(node)) {
                expandQueue.add(delta.getToPath());
            }
        }
        updateTask.submit(resource.getLocation());
        if (delta.getFromPath() != null) {
            updateTask.submit(delta.getFromPath());
        }
    }
}
Also used : NodeSettings(org.eclipse.che.ide.api.data.tree.settings.NodeSettings) Container(org.eclipse.che.ide.api.resources.Container) ResourceDelta(org.eclipse.che.ide.api.resources.ResourceDelta) Node(org.eclipse.che.ide.api.data.tree.Node) ResourceNode(org.eclipse.che.ide.resources.tree.ResourceNode) SyntheticNode(org.eclipse.che.ide.project.node.SyntheticNode) SVGResource(org.vectomatic.dom.svg.ui.SVGResource) Resource(org.eclipse.che.ide.api.resources.Resource) Tree(org.eclipse.che.ide.ui.smartTree.Tree) ResourceNode(org.eclipse.che.ide.resources.tree.ResourceNode)

Example 2 with NodeSettings

use of org.eclipse.che.ide.api.data.tree.settings.NodeSettings in project che by eclipse.

the class SelectPathPresenter method show.

public void show(Resource[] resources, boolean showFiles, SelectionPathHandler handler) {
    checkArgument(resources != null, "Null resources occurred");
    if (resources.length == 0) {
        view.setStructure(Collections.<Node>emptyList(), showFiles);
        return;
    }
    final List<Node> nodes = new ArrayList<>();
    final NodeSettings settings = settingsProvider.getSettings();
    for (Resource resource : resources) {
        if (resource.getResourceType() == Resource.FILE && !showFiles) {
            continue;
        }
        final Node node;
        if (resource.getResourceType() == Resource.FILE) {
            node = nodeFactory.newFileNode((File) resource, settings);
        } else {
            node = nodeFactory.newContainerNode((Container) resource, settings);
        }
        nodes.add(node);
    }
    view.setStructure(nodes, showFiles);
    this.handler = handler;
    view.show();
}
Also used : NodeSettings(org.eclipse.che.ide.api.data.tree.settings.NodeSettings) Container(org.eclipse.che.ide.api.resources.Container) Node(org.eclipse.che.ide.api.data.tree.Node) ResourceNode(org.eclipse.che.ide.resources.tree.ResourceNode) ArrayList(java.util.ArrayList) Resource(org.eclipse.che.ide.api.resources.Resource) File(org.eclipse.che.ide.api.resources.File)

Aggregations

Node (org.eclipse.che.ide.api.data.tree.Node)2 NodeSettings (org.eclipse.che.ide.api.data.tree.settings.NodeSettings)2 Container (org.eclipse.che.ide.api.resources.Container)2 Resource (org.eclipse.che.ide.api.resources.Resource)2 ResourceNode (org.eclipse.che.ide.resources.tree.ResourceNode)2 ArrayList (java.util.ArrayList)1 File (org.eclipse.che.ide.api.resources.File)1 ResourceDelta (org.eclipse.che.ide.api.resources.ResourceDelta)1 SyntheticNode (org.eclipse.che.ide.project.node.SyntheticNode)1 Tree (org.eclipse.che.ide.ui.smartTree.Tree)1 SVGResource (org.vectomatic.dom.svg.ui.SVGResource)1