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;
}
}
}
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);
}
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;
}
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;
}
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);
}
Aggregations