Search in sources :

Example 6 with ResourceNode

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

the class PlainJavaPagePresenterTest method selectedNodeShouldBeWithRelativePath.

@Test
public void selectedNodeShouldBeWithRelativePath() throws Exception {
    when(view.getLibraryFolder()).thenReturn("lib1,   lib2");
    when(view.getSourceFolder()).thenReturn("src1,   src2");
    List<Node> selectedNodes = new ArrayList<>();
    ResourceNode selectedNode1 = mock(ResourceNode.class);
    ResourceNode selectedNode2 = mock(ResourceNode.class);
    Resource resource1 = mock(Resource.class);
    Resource resource2 = mock(Resource.class);
    selectedNodes.add(selectedNode1);
    selectedNodes.add(selectedNode2);
    when(selectedNode1.getData()).thenReturn(resource1);
    when(resource1.getLocation()).thenReturn(Path.valueOf("projectName/folder1/folder2"));
    when(selectedNode2.getData()).thenReturn(resource2);
    when(resource2.getLocation()).thenReturn(Path.valueOf("projectName/folder"));
    when(dataObject.getName()).thenReturn("projectName");
    page.setUpdateDelegate(updateDelegate);
    page.init(dataObject);
    page.onNodeSelected(selectedNodes);
    verify(view).setLibraryFolder(eq("folder1/folder2,   folder"));
}
Also used : 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) ResourceNode(org.eclipse.che.ide.resources.tree.ResourceNode) Test(org.junit.Test)

Example 7 with ResourceNode

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

the class ProjectExplorerStateComponent method getState.

@Override
public JsonObject getState() {
    final List<Path> paths = new ArrayList<>();
    outer: for (Node node : projectExplorer.getTree().getNodeStorage().getAll()) {
        if (projectExplorer.getTree().isExpanded(node) && node instanceof ResourceNode) {
            final List<Node> childrenToStore = projectExplorer.getTree().getNodeStorage().getChildren(node);
            for (Node children : childrenToStore) {
                if (children instanceof ResourceNode) {
                    paths.add(((ResourceNode) children).getData().getLocation());
                    continue outer;
                }
            }
        }
    }
    JsonObject state = Json.createObject();
    JsonArray array = Json.createArray();
    state.put(PATH_PARAM_ID, array);
    int i = 0;
    for (Path path : paths) {
        array.set(i++, path.toString());
    }
    state.put(SHOW_HIDDEN_FILES, projectExplorer.isShowHiddenFiles());
    return state;
}
Also used : Path(org.eclipse.che.ide.resource.Path) JsonArray(elemental.json.JsonArray) Node(org.eclipse.che.ide.api.data.tree.Node) ResourceNode(org.eclipse.che.ide.resources.tree.ResourceNode) ArrayList(java.util.ArrayList) JsonObject(elemental.json.JsonObject) ArrayList(java.util.ArrayList) List(java.util.List) ResourceNode(org.eclipse.che.ide.resources.tree.ResourceNode)

Example 8 with ResourceNode

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

the class TreeResourceRevealer method expand.

protected void expand(final ResourceNode parent, final Path segment, final boolean select, final AsyncCallback<ResourceNode> callback) {
    if (parent.getData().getLocation().equals(segment)) {
        if (select) {
            if (toSelect == null) {
                toSelect = new Node[] { parent };
            } else {
                final int index = toSelect.length;
                toSelect = copyOf(toSelect, index + 1);
                toSelect[index] = parent;
            }
            selectTask.delay(200);
        }
        callback.onSuccess(parent);
        return;
    }
    final HandlerRegistration[] handler = new HandlerRegistration[1];
    handler[0] = tree.getNodeLoader().addPostLoadHandler(new PostLoadHandler() {

        @Override
        public void onPostLoad(PostLoadEvent event) {
            if (!event.getRequestedNode().equals(parent)) {
                return;
            }
            if (handler[0] != null) {
                handler[0].removeHandler();
            }
            final List<Node> children = tree.getNodeStorage().getChildren(event.getRequestedNode());
            for (Node child : children) {
                if (child instanceof ResourceNode && ((ResourceNode) child).getData().getLocation().isPrefixOf(segment)) {
                    expand((ResourceNode) child, segment, select, callback);
                    return;
                }
            }
            callback.onFailure(new IllegalStateException("Not found"));
        }
    });
    tree.getNodeLoader().loadChildren(parent);
}
Also used : HandlerRegistration(com.google.gwt.event.shared.HandlerRegistration) PostLoadEvent(org.eclipse.che.ide.ui.smartTree.event.PostLoadEvent) Node(org.eclipse.che.ide.api.data.tree.Node) ResourceNode(org.eclipse.che.ide.resources.tree.ResourceNode) PostLoadHandler(org.eclipse.che.ide.ui.smartTree.event.PostLoadEvent.PostLoadHandler) ResourceNode(org.eclipse.che.ide.resources.tree.ResourceNode)

Example 9 with ResourceNode

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

the class ExplorerCurrentProjectNameMacro 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().getName());
    }
    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 10 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);
    delegate.setSelectedNode(((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)

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