Search in sources :

Example 6 with Resource

use of org.eclipse.che.ide.api.resources.Resource in project che by eclipse.

the class RenameItemAction method updateInPerspective.

/** {@inheritDoc} */
@Override
public void updateInPerspective(@NotNull ActionEvent e) {
    final Resource[] resources = appContext.getResources();
    e.getPresentation().setVisible(true);
    if (resources == null || resources.length != 1) {
        e.getPresentation().setEnabled(false);
        return;
    }
    for (RenamingSupport validator : renamingSupport) {
        if (!validator.isRenameAllowed(resources[0])) {
            e.getPresentation().setEnabled(false);
            return;
        }
    }
    e.getPresentation().setEnabled(true);
}
Also used : RenamingSupport(org.eclipse.che.ide.api.resources.RenamingSupport) Resource(org.eclipse.che.ide.api.resources.Resource)

Example 7 with Resource

use of org.eclipse.che.ide.api.resources.Resource in project che by eclipse.

the class AppContextImpl method onResourceChanged.

/** {@inheritDoc} */
@Override
public void onResourceChanged(ResourceChangedEvent event) {
    final ResourceDelta delta = event.getDelta();
    final Resource resource = delta.getResource();
    if (!(resource.getResourceType() == PROJECT && resource.getLocation().segmentCount() == 1)) {
        return;
    }
    if (projects == null) {
        //Normal situation, workspace config updated and project has not been loaded fully. Just skip this situation.
        return;
    }
    if (delta.getKind() == ADDED) {
        Project[] newProjects = copyOf(projects, projects.length + 1);
        newProjects[projects.length] = (Project) resource;
        projects = newProjects;
        sort(projects, ResourcePathComparator.getInstance());
    } else if (delta.getKind() == REMOVED) {
        int size = projects.length;
        int index = java.util.Arrays.binarySearch(projects, resource, ResourcePathComparator.getInstance());
        int numMoved = projects.length - index - 1;
        if (numMoved > 0) {
            System.arraycopy(projects, index + 1, projects, index, numMoved);
        }
        projects = copyOf(projects, --size);
        if (currentResource != null && currentResource.equals(delta.getResource())) {
            currentResource = null;
        }
        if (currentResources != null) {
            for (Resource currentResource : currentResources) {
                if (currentResource.equals(delta.getResource())) {
                    currentResources = Arrays.remove(currentResources, currentResource);
                }
            }
        }
    } else if (delta.getKind() == UPDATED) {
        int index = -1;
        if (delta.getFlags() == MOVED_FROM) {
            for (int i = 0; i < projects.length; i++) {
                if (projects[i].getLocation().equals(delta.getFromPath())) {
                    index = i;
                    break;
                }
            }
        } else {
            index = binarySearch(projects, resource);
        }
        if (index != -1) {
            projects[index] = (Project) resource;
        }
        sort(projects, ResourcePathComparator.getInstance());
    } else if (delta.getKind() == SYNCHRONIZED && resource.isProject() && resource.getLocation().segmentCount() == 1) {
        for (int i = 0; i < projects.length; i++) {
            if (projects[i].getLocation().equals(resource.getLocation())) {
                projects[i] = (Project) resource;
            }
        }
        if (currentResources != null) {
            for (int i = 0; i < currentResources.length; i++) {
                if (currentResources[i].getLocation().equals(resource.getLocation())) {
                    currentResources[i] = resource;
                    break;
                }
            }
        }
        if (currentResource != null && currentResource.getLocation().equals(resource.getLocation())) {
            currentResource = resource;
        }
    }
}
Also used : Project(org.eclipse.che.ide.api.resources.Project) ResourceDelta(org.eclipse.che.ide.api.resources.ResourceDelta) Resource(org.eclipse.che.ide.api.resources.Resource)

Example 8 with Resource

use of org.eclipse.che.ide.api.resources.Resource 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 9 with Resource

use of org.eclipse.che.ide.api.resources.Resource in project che by eclipse.

the class FullTextSearchPresenterTest method searchWholeWordSelect.

@Test
public void searchWholeWordSelect() throws Exception {
    when(view.getPathToSearch()).thenReturn("/search");
    when(view.isWholeWordsOnly()).thenReturn(true);
    when(appContext.getWorkspaceRoot()).thenReturn(workspaceRoot);
    when(workspaceRoot.getContainer(any(Path.class))).thenReturn(optionalContainerPromise);
    when(searchContainer.search(anyString(), anyString())).thenReturn(searchResultPromise);
    final String search = NameGenerator.generate("test", 10);
    fullTextSearchPresenter.search(search);
    verify(optionalContainerPromise).then(optionalContainerCaptor.capture());
    optionalContainerCaptor.getValue().apply(Optional.of(searchContainer));
    verify(searchResultPromise).then(searchResultCaptor.capture());
    searchResultCaptor.getValue().apply(new Resource[0]);
    verify(searchContainer).search(anyString(), eq(search));
    verify(view).isWholeWordsOnly();
    verify(view, never()).showErrorMessage(anyString());
    verify(view).close();
    verify(findResultPresenter).handleResponse(eq(new Resource[0]), eq(search));
}
Also used : Path(org.eclipse.che.ide.resource.Path) Resource(org.eclipse.che.ide.api.resources.Resource) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 10 with Resource

use of org.eclipse.che.ide.api.resources.Resource in project che by eclipse.

the class GdbDebugger method fqnToPath.

@Override
protected String fqnToPath(@NotNull Location location) {
    final Resource resource = appContext.getResource();
    if (resource == null) {
        return location.getTarget();
    }
    final Optional<Project> project = resource.getRelatedProject();
    if (project.isPresent()) {
        return project.get().getLocation().append(location.getTarget()).toString();
    }
    return location.getTarget();
}
Also used : Project(org.eclipse.che.ide.api.resources.Project) Resource(org.eclipse.che.ide.api.resources.Resource)

Aggregations

Resource (org.eclipse.che.ide.api.resources.Resource)146 Project (org.eclipse.che.ide.api.resources.Project)73 OperationException (org.eclipse.che.api.promises.client.OperationException)48 Operation (org.eclipse.che.api.promises.client.Operation)46 PromiseError (org.eclipse.che.api.promises.client.PromiseError)40 Container (org.eclipse.che.ide.api.resources.Container)32 Path (org.eclipse.che.ide.resource.Path)30 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)22 Optional (com.google.common.base.Optional)15 File (org.eclipse.che.ide.api.resources.File)14 CLIOutputResponse (org.eclipse.che.plugin.svn.shared.CLIOutputResponse)14 List (java.util.List)13 Promise (org.eclipse.che.api.promises.client.Promise)13 FunctionException (org.eclipse.che.api.promises.client.FunctionException)12 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)12 ArrayList (java.util.ArrayList)11 Function (org.eclipse.che.api.promises.client.Function)9 ResourceChangedEvent (org.eclipse.che.ide.api.resources.ResourceChangedEvent)9 JavaUtil.isJavaProject (org.eclipse.che.ide.ext.java.client.util.JavaUtil.isJavaProject)9 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)8