Search in sources :

Example 1 with Node

use of org.eclipse.che.ide.api.data.tree.Node 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 Node

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

the class ProjectExplorerStateComponent method loadState.

@Override
public void loadState(@NotNull JsonObject state) {
    if (state.hasKey(SHOW_HIDDEN_FILES)) {
        projectExplorer.showHiddenFiles(state.getBoolean(SHOW_HIDDEN_FILES));
    }
    JsonArray paths = state.hasKey(PATH_PARAM_ID) ? state.getArray(PATH_PARAM_ID) : Json.createArray();
    if (paths.length() == 0) {
        return;
    }
    Promise<Node> revealPromise = null;
    final MessageLoader loader = loaderFactory.newLoader("Restoring project structure...");
    loader.show();
    for (int i = 0; i < paths.length(); i++) {
        final String path = paths.getString(i);
        if (revealPromise == null) {
            revealPromise = revealer.reveal(Path.valueOf(path), false).thenPromise(new Function<Node, Promise<Node>>() {

                @Override
                public Promise<Node> apply(Node node) throws FunctionException {
                    if (node != null) {
                        projectExplorer.getTree().setExpanded(node, true, false);
                    }
                    return revealer.reveal(Path.valueOf(path), false);
                }
            });
            continue;
        }
        revealPromise.thenPromise(new Function<Node, Promise<Node>>() {

            @Override
            public Promise<Node> apply(Node node) throws FunctionException {
                if (node != null) {
                    projectExplorer.getTree().setExpanded(node, true, false);
                }
                return revealer.reveal(Path.valueOf(path), false);
            }
        }).catchError(new Function<PromiseError, Node>() {

            @Override
            public Node apply(PromiseError error) throws FunctionException {
                Log.info(getClass(), error.getMessage());
                return null;
            }
        });
    }
    if (revealPromise != null) {
        revealPromise.then(new Operation<Node>() {

            @Override
            public void apply(Node node) throws OperationException {
                loader.hide();
            }
        }).catchError(new Operation<PromiseError>() {

            @Override
            public void apply(PromiseError error) throws OperationException {
                loader.hide();
            }
        });
    }
}
Also used : Node(org.eclipse.che.ide.api.data.tree.Node) ResourceNode(org.eclipse.che.ide.resources.tree.ResourceNode) JsonArray(elemental.json.JsonArray) MessageLoader(org.eclipse.che.ide.ui.loaders.request.MessageLoader)

Example 3 with Node

use of org.eclipse.che.ide.api.data.tree.Node 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 4 with Node

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

the class DefaultGoInto method reset.

/** {@inheritDoc} */
public void reset() {
    //reset selection
    tree.getSelectionModel().deselectAll();
    Element rootContainer = tree.getContainer(null);
    rootContainer.setInnerHTML("");
    //restore root nodes
    for (Node rootNode : rootNodes) {
        NodeDescriptor descriptor = tree.getNodeDescriptor(rootNode);
        rootContainer.appendChild(descriptor.getRootContainer());
    }
    //then re-add our go into node
    Node parent = node.getParent();
    if (parent != null) {
        tree.getNodeStorage().add(parent, node);
    }
    tree.scrollIntoView(node);
    tree.getSelectionModel().select(node, false);
    tree.update();
    active = false;
    fireEvent(new GoIntoStateEvent(DEACTIVATED, node));
}
Also used : Element(com.google.gwt.dom.client.Element) Node(org.eclipse.che.ide.api.data.tree.Node) GoIntoStateEvent(org.eclipse.che.ide.ui.smartTree.event.GoIntoStateEvent)

Example 5 with Node

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

the class NodeStorage method getPreviousSibling.

/**
     * Returns the item's previous sibling.
     *
     * @param item
     * @return
     */
public Node getPreviousSibling(Node item) {
    Node parent = getParent(item);
    List<Node> children = parent == null ? getRootItems() : getChildren(parent);
    int index = children.indexOf(item);
    if (index > 0) {
        return children.get(index - 1);
    }
    return null;
}
Also used : Node(org.eclipse.che.ide.api.data.tree.Node)

Aggregations

Node (org.eclipse.che.ide.api.data.tree.Node)60 ArrayList (java.util.ArrayList)20 ResourceNode (org.eclipse.che.ide.resources.tree.ResourceNode)20 List (java.util.List)7 MutableNode (org.eclipse.che.ide.api.data.tree.MutableNode)7 Project (org.eclipse.che.ide.api.resources.Project)7 Resource (org.eclipse.che.ide.api.resources.Resource)7 Element (com.google.gwt.dom.client.Element)5 LinkedList (java.util.LinkedList)4 Map (java.util.Map)4 Promise (org.eclipse.che.api.promises.client.Promise)4 DivElement (com.google.gwt.dom.client.DivElement)3 Inject (com.google.inject.Inject)3 Assisted (com.google.inject.assistedinject.Assisted)3 Collectors (java.util.stream.Collectors)3 NotNull (javax.validation.constraints.NotNull)3 AsyncPromiseHelper.createFromAsyncRequest (org.eclipse.che.api.promises.client.callback.AsyncPromiseHelper.createFromAsyncRequest)3 NodePresentation (org.eclipse.che.ide.ui.smartTree.presentation.NodePresentation)3 JsonArray (elemental.json.JsonArray)2 HashMap (java.util.HashMap)2