use of org.eclipse.che.ide.api.resources.ResourceDelta 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;
}
}
}
use of org.eclipse.che.ide.api.resources.ResourceDelta 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());
}
}
}
use of org.eclipse.che.ide.api.resources.ResourceDelta in project che by eclipse.
the class FindResultPresenter method onResourceChanged.
@Override
@SuppressWarnings("unchecked")
public void onResourceChanged(ResourceChangedEvent event) {
final ResourceDelta delta = event.getDelta();
final Tree tree = view.getTree();
if (delta.getKind() == REMOVED) {
for (Node node : tree.getNodeStorage().getAll()) {
if (node instanceof ResourceNode && ((ResourceNode) node).getData().getLocation().equals(delta.getResource().getLocation())) {
tree.getNodeStorage().remove(node);
return;
}
}
}
}
use of org.eclipse.che.ide.api.resources.ResourceDelta 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);
}
use of org.eclipse.che.ide.api.resources.ResourceDelta in project che by eclipse.
the class EditorContentSynchronizerImpl method onResourceChanged.
@Override
public void onResourceChanged(ResourceChangedEvent event) {
final ResourceDelta delta = event.getDelta();
if (delta.getKind() != ADDED || (delta.getFlags() & (MOVED_FROM | MOVED_TO)) == 0) {
return;
}
final Path fromPath = delta.getFromPath();
final Path toPath = delta.getToPath();
if (delta.getResource().isFile()) {
onFileChanged(fromPath, toPath);
} else {
onFolderChanged(fromPath, toPath);
}
}
Aggregations