Search in sources :

Example 26 with Path

use of org.eclipse.che.ide.resource.Path in project che by eclipse.

the class InMemoryResourceStore method register.

/** {@inheritDoc} */
@Override
public boolean register(Resource resource) {
    checkArgument(resource != null, "Null resource occurred");
    final Path parent = resource.getLocation().segmentCount() == 1 ? Path.ROOT : resource.getLocation().parent();
    if (!memoryCache.containsKey(parent)) {
        memoryCache.put(parent, new Resource[] { resource });
        intercept(resource);
        return true;
    } else {
        Resource[] container = memoryCache.get(parent);
        final int index = binarySearch(container, resource, NAME_COMPARATOR);
        if (index >= 0) {
            //update existing resource with new one
            container[index] = resource;
            intercept(resource);
            return false;
        } else {
            //such resource doesn't exists, then simply add it
            //negate inverted index into positive one
            final int posIndex = -index - 1;
            final int size = container.length;
            final Resource[] tmpContainer = copyOf(container, size + 1);
            //prepare cell to insert
            arraycopy(tmpContainer, posIndex, tmpContainer, posIndex + 1, size - posIndex);
            tmpContainer[posIndex] = resource;
            container = tmpContainer;
            memoryCache.put(parent, container);
            intercept(resource);
            return true;
        }
    }
}
Also used : Path(org.eclipse.che.ide.resource.Path) Resource(org.eclipse.che.ide.api.resources.Resource)

Example 27 with Path

use of org.eclipse.che.ide.resource.Path in project che by eclipse.

the class InMemoryResourceStore method getAll.

/** {@inheritDoc} */
@Override
public Optional<Resource[]> getAll(Path parent) {
    checkArgument(parent != null, "Null path occurred");
    if (!memoryCache.containsKey(parent)) {
        return absent();
    }
    Resource[] all = new Resource[0];
    for (Map.Entry<Path, Resource[]> setEntry : memoryCache.entrySet()) {
        /* There is no need to check compared path if its segment count is less then given one. */
        final Path comparedPath = setEntry.getKey();
        if (!parent.isPrefixOf(comparedPath)) {
            continue;
        }
        final Resource[] resources = setEntry.getValue();
        if (resources == null || resources.length == 0) {
            continue;
        }
        final Resource[] tmpResourcesArr = copyOf(all, all.length + resources.length);
        arraycopy(resources, 0, tmpResourcesArr, all.length, resources.length);
        all = tmpResourcesArr;
    }
    if (all.length == 0) {
        return of(EMPTY_RESOURCES);
    }
    return of(all);
}
Also used : Path(org.eclipse.che.ide.resource.Path) Resource(org.eclipse.che.ide.api.resources.Resource) Map(java.util.Map)

Example 28 with Path

use of org.eclipse.che.ide.resource.Path in project che by eclipse.

the class EditorPartStackPresenter method getPartByPath.

@Nullable
public PartPresenter getPartByPath(Path path) {
    for (TabItem tab : parts.keySet()) {
        EditorTab editorTab = (EditorTab) tab;
        Path currentPath = editorTab.getFile().getLocation();
        if (currentPath.equals(path)) {
            return parts.get(tab);
        }
    }
    return null;
}
Also used : Path(org.eclipse.che.ide.resource.Path) TabItem(org.eclipse.che.ide.api.parts.PartStackView.TabItem) EditorTab(org.eclipse.che.ide.api.parts.EditorTab) Nullable(org.eclipse.che.commons.annotation.Nullable)

Example 29 with Path

use of org.eclipse.che.ide.resource.Path in project che by eclipse.

the class EditorPartStackPresenter method getTabByPath.

@Nullable
@Override
public EditorTab getTabByPath(@NotNull Path path) {
    for (TabItem tab : parts.keySet()) {
        EditorTab editorTab = (EditorTab) tab;
        Path currentPath = editorTab.getFile().getLocation();
        if (currentPath.equals(path)) {
            return editorTab;
        }
    }
    return null;
}
Also used : Path(org.eclipse.che.ide.resource.Path) TabItem(org.eclipse.che.ide.api.parts.PartStackView.TabItem) EditorTab(org.eclipse.che.ide.api.parts.EditorTab) Nullable(org.eclipse.che.commons.annotation.Nullable)

Example 30 with Path

use of org.eclipse.che.ide.resource.Path in project che by eclipse.

the class EditorContentSynchronizerImplTest method shouldUpdatePathForGroupWhenFolderLocationIsChanged.

@Test
public void shouldUpdatePathForGroupWhenFolderLocationIsChanged() {
    Resource resource = mock(Resource.class);
    ResourceDelta delta = mock(ResourceDelta.class);
    ResourceChangedEvent resourceChangedEvent = new ResourceChangedEvent(delta);
    Path fromPath = new Path(FOLDER_PATH);
    Path toPath = new Path("testProject/src/main/java/org/eclipse/che/samples/");
    Path oldFilePath = new Path(FILE_PATH);
    Path newFilePath = new Path("testProject/src/main/java/org/eclipse/che/samples/" + FILE_NAME);
    EditorPartPresenter openedEditor1 = mock(EditorPartPresenter.class);
    when(openedEditor1.getEditorInput()).thenReturn(editorInput);
    when(delta.getKind()).thenReturn(ResourceDelta.ADDED);
    when(delta.getFlags()).thenReturn(5632);
    when(delta.getFromPath()).thenReturn(fromPath);
    when(delta.getToPath()).thenReturn(toPath);
    when(delta.getResource()).thenReturn(resource);
    when(resource.isFile()).thenReturn(false);
    editorContentSynchronizer.trackEditor(openedEditor1);
    editorContentSynchronizer.onResourceChanged(resourceChangedEvent);
    final EditorGroupSynchronization oldGroup = editorContentSynchronizer.editorGroups.get(oldFilePath);
    final EditorGroupSynchronization newGroup = editorContentSynchronizer.editorGroups.get(newFilePath);
    assertNull(oldGroup);
    assertNotNull(newGroup);
}
Also used : Path(org.eclipse.che.ide.resource.Path) ResourceDelta(org.eclipse.che.ide.api.resources.ResourceDelta) Resource(org.eclipse.che.ide.api.resources.Resource) ResourceChangedEvent(org.eclipse.che.ide.api.resources.ResourceChangedEvent) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) Test(org.junit.Test)

Aggregations

Path (org.eclipse.che.ide.resource.Path)72 Resource (org.eclipse.che.ide.api.resources.Resource)27 Operation (org.eclipse.che.api.promises.client.Operation)15 OperationException (org.eclipse.che.api.promises.client.OperationException)15 PromiseError (org.eclipse.che.api.promises.client.PromiseError)13 ArrayList (java.util.ArrayList)11 Project (org.eclipse.che.ide.api.resources.Project)11 Promise (org.eclipse.che.api.promises.client.Promise)10 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)10 List (java.util.List)8 Test (org.junit.Test)7 ResourceDelta (org.eclipse.che.ide.api.resources.ResourceDelta)6 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)6 Optional (com.google.common.base.Optional)5 Function (org.eclipse.che.api.promises.client.Function)5 FunctionException (org.eclipse.che.api.promises.client.FunctionException)5 Container (org.eclipse.che.ide.api.resources.Container)5 ResourceChangedEvent (org.eclipse.che.ide.api.resources.ResourceChangedEvent)5 HashMap (java.util.HashMap)4 ProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto)4