use of org.eclipse.che.ide.api.resources.ResourceDelta in project che by eclipse.
the class RefactoringUpdater method updateAfterRefactoring.
/**
* Iterates over each refactoring change and according to change type performs specific update operation.
* i.e. for {@code ChangeName#UPDATE} updates only opened editors, for {@code ChangeName#MOVE or ChangeName#RENAME_COMPILATION_UNIT}
* updates only new paths and opened editors, for {@code ChangeName#RENAME_PACKAGE} reloads package structure and restore expansion.
*
* @param changes
* applied changes
*/
public void updateAfterRefactoring(List<ChangeInfo> changes) {
if (changes == null || changes.isEmpty()) {
return;
}
ExternalResourceDelta[] deltas = new ExternalResourceDelta[0];
final List<String> pathChanged = new ArrayList<>();
for (ChangeInfo change : changes) {
final ExternalResourceDelta delta;
final Path newPath = Path.valueOf(change.getPath());
final Path oldPath = !isNullOrEmpty(change.getOldPath()) ? Path.valueOf(change.getOldPath()) : Path.EMPTY;
switch(change.getName()) {
case MOVE:
case RENAME_COMPILATION_UNIT:
delta = new ExternalResourceDelta(newPath, oldPath, ADDED | MOVED_FROM | MOVED_TO);
registerRemovedFile(change);
break;
case RENAME_PACKAGE:
delta = new ExternalResourceDelta(newPath, oldPath, ADDED | MOVED_FROM | MOVED_TO);
break;
case UPDATE:
if (!isFileRemoved(change.getPath(), changes)) {
pathChanged.add(change.getPath());
registerRemovedFile(change);
}
default:
continue;
}
final int index = deltas.length;
deltas = Arrays.copyOf(deltas, index + 1);
deltas[index] = delta;
}
//here we need to remove file for file that moved or renamed JDT lib sent it to
for (int i = 0; i < deltas.length; i++) {
if (pathChanged.contains(deltas[i].getToPath().toString())) {
pathChanged.remove(deltas[i].getToPath().toString());
}
if (pathChanged.contains(deltas[i].getFromPath().toString())) {
pathChanged.remove(deltas[i].getFromPath().toString());
}
}
if (deltas.length > 0) {
appContext.getWorkspaceRoot().synchronize(deltas).then(new Operation<ResourceDelta[]>() {
@Override
public void apply(final ResourceDelta[] appliedDeltas) throws OperationException {
for (ResourceDelta delta : appliedDeltas) {
eventBus.fireEvent(new RevealResourceEvent(delta.getToPath()));
}
for (EditorPartPresenter editorPartPresenter : editorAgent.getOpenedEditors()) {
final String path = editorPartPresenter.getEditorInput().getFile().getLocation().toString();
if (pathChanged.contains(path)) {
eventBus.fireEvent(new FileContentUpdateEvent(editorPartPresenter.getEditorInput().getFile().getLocation().toString()));
}
}
setActiveEditor();
}
});
} else {
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
for (EditorPartPresenter editorPartPresenter : editorAgent.getOpenedEditors()) {
eventBus.fireEvent(new FileContentUpdateEvent(editorPartPresenter.getEditorInput().getFile().getLocation().toString()));
}
setActiveEditor();
}
});
}
}
use of org.eclipse.che.ide.api.resources.ResourceDelta in project che by eclipse.
the class EditorTabWidget method onResourceChanged.
@Override
public void onResourceChanged(ResourceChangedEvent event) {
final ResourceDelta delta = event.getDelta();
if (delta.getKind() == ADDED) {
if (!delta.getResource().isFile() || (delta.getFlags() & (MOVED_FROM | MOVED_TO)) == 0) {
return;
}
final Resource resource = delta.getResource();
final Path movedFrom = delta.getFromPath();
if (file.getLocation().equals(movedFrom)) {
file = (VirtualFile) resource;
title.setText(file.getDisplayName());
}
} else if (delta.getKind() == UPDATED) {
if (!delta.getResource().isFile()) {
return;
}
final Resource resource = delta.getResource();
if (file.getLocation().equals(resource.getLocation())) {
file = (VirtualFile) resource;
title.setText(file.getDisplayName());
}
}
}
use of org.eclipse.che.ide.api.resources.ResourceDelta in project che by eclipse.
the class CopyPasteManager method onResourceChanged.
@Override
public void onResourceChanged(ResourceChangedEvent event) {
final ResourceDelta delta = event.getDelta();
//delta should be removed and resources is not null
if (delta.getKind() != REMOVED || resources == null) {
return;
}
for (int i = 0; i < resources.length; i++) {
final Resource resource = resources[i];
if (delta.getResource().getLocation().isPrefixOf(resource.getLocation())) {
int size = resources.length;
int numMoved = resources.length - i - 1;
if (numMoved > 0) {
System.arraycopy(resources, i + 1, resources, i, numMoved);
}
resources = copyOf(resources, --size);
}
}
}
use of org.eclipse.che.ide.api.resources.ResourceDelta in project che by eclipse.
the class EditorContentSynchronizerImplTest method shouldUpdatePathForGroupWhenFileLocationIsChanged.
@Test
public void shouldUpdatePathForGroupWhenFileLocationIsChanged() {
Resource resource = mock(Resource.class);
ResourceDelta delta = mock(ResourceDelta.class);
ResourceChangedEvent resourceChangedEvent = new ResourceChangedEvent(delta);
Path fromPath = new Path(FILE_PATH);
Path toPath = new Path("testProject/src/main/java/org/eclipse/che/examples/changedFile");
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(true);
editorContentSynchronizer.trackEditor(openedEditor1);
editorContentSynchronizer.onResourceChanged(resourceChangedEvent);
final EditorGroupSynchronization oldGroup = editorContentSynchronizer.editorGroups.get(fromPath);
final EditorGroupSynchronization newGroup = editorContentSynchronizer.editorGroups.get(toPath);
assertNull(oldGroup);
assertNotNull(newGroup);
}
use of org.eclipse.che.ide.api.resources.ResourceDelta in project che by eclipse.
the class EmptyEditorsPanel method onResourceChanged.
@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;
}
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
updateOnProjectsChange();
}
});
}
Aggregations