use of org.eclipse.che.ide.api.resources.ResourceChangedEvent 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.ResourceChangedEvent in project che by eclipse.
the class ResourceManager method getRemoteResources.
Promise<Resource[]> getRemoteResources(final Container container, final int depth, boolean includeFiles) {
checkArgument(depth > -2, "Invalid depth");
if (depth == DEPTH_ZERO) {
return promises.resolve(NO_RESOURCES);
}
int depthToReload = depth;
final Optional<Resource[]> descendants = store.getAll(container.getLocation());
if (depthToReload != -1 && descendants.isPresent()) {
for (Resource resource : descendants.get()) {
if (resource.getLocation().segmentCount() - container.getLocation().segmentCount() > depth) {
depthToReload = resource.getLocation().segmentCount() - container.getLocation().segmentCount();
}
}
}
return ps.getTree(container.getLocation(), depthToReload, includeFiles).then(new Function<TreeElement, Resource[]>() {
@Override
public Resource[] apply(TreeElement tree) throws FunctionException {
class Visitor implements ResourceVisitor {
Resource[] resources;
//size of total items
private int size = 0;
//step to increase resource array
private int incStep = 50;
private Visitor() {
this.resources = NO_RESOURCES;
}
@Override
public void visit(Resource resource) {
if (resource.getResourceType() == PROJECT) {
final Optional<ProjectConfigDto> optionalConfig = findProjectConfigDto(resource.getLocation());
if (optionalConfig.isPresent()) {
final Optional<ProblemProjectMarker> optionalMarker = getProblemMarker(optionalConfig.get());
if (optionalMarker.isPresent()) {
resource.addMarker(optionalMarker.get());
}
}
}
if (size > resources.length - 1) {
//check load factor and increase resource array
resources = copyOf(resources, resources.length + incStep);
}
resources[size++] = resource;
}
}
final Visitor visitor = new Visitor();
traverse(tree, visitor);
return copyOf(visitor.resources, visitor.size);
}
}).then(new Function<Resource[], Resource[]>() {
@Override
public Resource[] apply(Resource[] reloaded) throws FunctionException {
Resource[] result = new Resource[0];
if (descendants.isPresent()) {
Resource[] outdated = descendants.get();
final Resource[] removed = removeAll(outdated, reloaded, false);
for (Resource resource : removed) {
store.dispose(resource.getLocation(), false);
eventBus.fireEvent(new ResourceChangedEvent(new ResourceDeltaImpl(resource, REMOVED)));
}
final Resource[] updated = removeAll(outdated, reloaded, true);
for (Resource resource : updated) {
store.register(resource);
eventBus.fireEvent(new ResourceChangedEvent(new ResourceDeltaImpl(resource, UPDATED)));
final Optional<Resource> registered = store.getResource(resource.getLocation());
if (registered.isPresent()) {
result = Arrays.add(result, registered.get());
}
}
final Resource[] added = removeAll(reloaded, outdated, false);
for (Resource resource : added) {
store.register(resource);
eventBus.fireEvent(new ResourceChangedEvent(new ResourceDeltaImpl(resource, ADDED)));
final Optional<Resource> registered = store.getResource(resource.getLocation());
if (registered.isPresent()) {
result = Arrays.add(result, registered.get());
}
}
} else {
for (Resource resource : reloaded) {
store.register(resource);
eventBus.fireEvent(new ResourceChangedEvent(new ResourceDeltaImpl(resource, ADDED)));
final Optional<Resource> registered = store.getResource(resource.getLocation());
if (registered.isPresent()) {
result = Arrays.add(result, registered.get());
}
}
}
return result;
}
});
}
use of org.eclipse.che.ide.api.resources.ResourceChangedEvent in project che by eclipse.
the class FileWatcher method handleFileOperations.
@Inject
private void handleFileOperations(EventBus eventBus) {
eventBus.addHandler(ResourceChangedEvent.getType(), new ResourceChangedEvent.ResourceChangedHandler() {
@Override
public void onResourceChanged(ResourceChangedEvent event) {
if (event.getDelta().getKind() != REMOVED) {
return;
}
if ((event.getDelta().getFlags() & DERIVED) == 0) {
return;
}
final Resource resource = event.getDelta().getResource();
final Optional<Resource> srcFolder = resource.getParentWithMarker(SourceFolderMarker.ID);
if (srcFolder.isPresent()) {
reparseAllOpenedFiles();
}
}
});
eventBus.addHandler(ActivePartChangedEvent.TYPE, new ActivePartChangedHandler() {
@Override
public void onActivePartChanged(ActivePartChangedEvent event) {
if (event.getActivePart() instanceof TextEditor) {
if (editor2reconcile.contains(event.getActivePart())) {
reParseEditor((TextEditor) event.getActivePart());
}
}
}
});
}
use of org.eclipse.che.ide.api.resources.ResourceChangedEvent in project che by eclipse.
the class AppContextImpl method initResourceManager.
@Override
public void initResourceManager(final Callback<ResourceManager, Exception> callback) {
if (runtime.getDevMachine() == null) {
//should never happened, but anyway
callback.onFailure(new NullPointerException("Dev machine is not initialized"));
}
if (projects != null) {
for (Project project : projects) {
eventBus.fireEvent(new ResourceChangedEvent(new ResourceDeltaImpl(project, REMOVED)));
}
projects = null;
}
resourceManager = resourceManagerFactory.newResourceManager(runtime.getDevMachine());
resourceManager.getWorkspaceProjects().then(projects -> {
AppContextImpl.this.projects = projects;
java.util.Arrays.sort(AppContextImpl.this.projects, ResourcePathComparator.getInstance());
callback.onSuccess(resourceManager);
eventBus.fireEvent(new WorkspaceReadyEvent(projects));
}).catchError(error -> {
callback.onFailure((Exception) error.getCause());
});
}
use of org.eclipse.che.ide.api.resources.ResourceChangedEvent in project che by eclipse.
the class BreakpointManagerImpl method registerEventHandlers.
/**
* Registers events handlers.
*/
private void registerEventHandlers(EventBus eventBus) {
eventBus.addHandler(WorkspaceReadyEvent.getType(), new WorkspaceReadyEvent.WorkspaceReadyHandler() {
@Override
public void onWorkspaceReady(WorkspaceReadyEvent event) {
restoreBreakpoints();
}
});
eventBus.addHandler(EditorOpenedEvent.TYPE, new EditorOpenedEventHandler() {
@Override
public void onEditorOpened(EditorOpenedEvent event) {
onOpenEditor(event.getFile().getLocation().toString(), event.getEditor());
}
});
eventBus.addHandler(DeleteProjectEvent.TYPE, new DeleteProjectHandler() {
@Override
public void onProjectDeleted(DeleteProjectEvent event) {
if (breakpoints.isEmpty()) {
return;
}
ProjectConfigDto config = event.getProjectConfig();
String path = config.getPath() + "/";
deleteBreakpoints(getBreakpointPaths(path));
}
});
eventBus.addHandler(ResourceChangedEvent.getType(), new ResourceChangedEvent.ResourceChangedHandler() {
@Override
public void onResourceChanged(ResourceChangedEvent event) {
if (event.getDelta().getKind() == ResourceDelta.REMOVED) {
if (breakpoints.isEmpty()) {
return;
}
final Resource resource = event.getDelta().getResource();
Path path = resource.getLocation();
if (resource.isFolder()) {
path.addTrailingSeparator();
deleteBreakpoints(getBreakpointPaths(path.toString()));
} else if (resource.isFile()) {
deleteBreakpoints(Collections.singleton(path.toString()));
}
}
}
});
}
Aggregations