Search in sources :

Example 1 with ResourceNode

use of org.eclipse.che.ide.resources.tree.ResourceNode 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 ResourceNode

use of org.eclipse.che.ide.resources.tree.ResourceNode in project che by eclipse.

the class ExplorerCurrentProjectTypeMacro method expand.

/** {@inheritDoc} */
@Override
public Promise<String> expand() {
    List<Node> selectedNodes = projectExplorer.getTree().getSelectionModel().getSelectedNodes();
    if (selectedNodes.isEmpty() || selectedNodes.size() > 1) {
        return promises.resolve("");
    }
    final Node node = selectedNodes.get(0);
    if (node instanceof ResourceNode) {
        final Optional<Project> project = ((ResourceNode) node).getData().getRelatedProject();
        if (!project.isPresent()) {
            return promises.resolve("");
        }
        return promises.resolve(project.get().getType());
    }
    return promises.resolve("");
}
Also used : Project(org.eclipse.che.ide.api.resources.Project) Node(org.eclipse.che.ide.api.data.tree.Node) ResourceNode(org.eclipse.che.ide.resources.tree.ResourceNode) ResourceNode(org.eclipse.che.ide.resources.tree.ResourceNode)

Example 3 with ResourceNode

use of org.eclipse.che.ide.resources.tree.ResourceNode in project che by eclipse.

the class SelectNodeViewImpl method acceptButtonClicked.

private void acceptButtonClicked() {
    List<Node> nodes = tree.getSelectionModel().getSelectedNodes();
    if (nodes.isEmpty()) {
        return;
    }
    Node selectedNode = nodes.get(0);
    if (selectedNode instanceof ResourceNode) {
        final Resource resource = ((ResourceNode) selectedNode).getData();
        delegate.setSelectedNode(resource, resolveFQN(resource));
    }
    hide();
}
Also used : Node(org.eclipse.che.ide.api.data.tree.Node) ResourceNode(org.eclipse.che.ide.resources.tree.ResourceNode) Resource(org.eclipse.che.ide.api.resources.Resource) ResourceNode(org.eclipse.che.ide.resources.tree.ResourceNode)

Example 4 with ResourceNode

use of org.eclipse.che.ide.resources.tree.ResourceNode in project che by eclipse.

the class FindResultPresenter method onResourceChanged.

@Override
@SuppressWarnings("unchecked")
public void onResourceChanged(ResourceChangedEvent event) {
    final ResourceDelta delta = event.getDelta();
    final Tree tree = view.getTree();
    if (delta.getKind() == REMOVED) {
        for (Node node : tree.getNodeStorage().getAll()) {
            if (node instanceof ResourceNode && ((ResourceNode) node).getData().getLocation().equals(delta.getResource().getLocation())) {
                tree.getNodeStorage().remove(node);
                return;
            }
        }
    }
}
Also used : 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) Tree(org.eclipse.che.ide.ui.smartTree.Tree) ResourceNode(org.eclipse.che.ide.resources.tree.ResourceNode)

Example 5 with ResourceNode

use of org.eclipse.che.ide.resources.tree.ResourceNode in project che by eclipse.

the class SelectPathViewImpl method acceptButtonClicked.

private void acceptButtonClicked() {
    List<Node> nodes = tree.getSelectionModel().getSelectedNodes();
    if (nodes.isEmpty()) {
        return;
    }
    Node selectedNode = nodes.get(0);
    if (selectedNode instanceof ResourceNode) {
        delegate.setSelectedPath(((ResourceNode) selectedNode).getData().getLocation().toString());
    }
    hide();
}
Also used : Node(org.eclipse.che.ide.api.data.tree.Node) ResourceNode(org.eclipse.che.ide.resources.tree.ResourceNode) ResourceNode(org.eclipse.che.ide.resources.tree.ResourceNode)

Aggregations

Node (org.eclipse.che.ide.api.data.tree.Node)12 ResourceNode (org.eclipse.che.ide.resources.tree.ResourceNode)12 Resource (org.eclipse.che.ide.api.resources.Resource)4 Project (org.eclipse.che.ide.api.resources.Project)3 ArrayList (java.util.ArrayList)2 ResourceDelta (org.eclipse.che.ide.api.resources.ResourceDelta)2 Path (org.eclipse.che.ide.resource.Path)2 Tree (org.eclipse.che.ide.ui.smartTree.Tree)2 HandlerRegistration (com.google.gwt.event.shared.HandlerRegistration)1 JsonArray (elemental.json.JsonArray)1 JsonObject (elemental.json.JsonObject)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 NodeSettings (org.eclipse.che.ide.api.data.tree.settings.NodeSettings)1 Container (org.eclipse.che.ide.api.resources.Container)1 JavaUtil.isJavaProject (org.eclipse.che.ide.ext.java.client.util.JavaUtil.isJavaProject)1 SyntheticNode (org.eclipse.che.ide.project.node.SyntheticNode)1 PostLoadEvent (org.eclipse.che.ide.ui.smartTree.event.PostLoadEvent)1 PostLoadHandler (org.eclipse.che.ide.ui.smartTree.event.PostLoadEvent.PostLoadHandler)1 Test (org.junit.Test)1