Search in sources :

Example 6 with ResourceChangedEvent

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

Example 7 with ResourceChangedEvent

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;
        }
    });
}
Also used : Optional(com.google.common.base.Optional) NewProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) Resource(org.eclipse.che.ide.api.resources.Resource) ProblemProjectMarker(org.eclipse.che.ide.api.resources.Project.ProblemProjectMarker) FunctionException(org.eclipse.che.api.promises.client.FunctionException) TreeElement(org.eclipse.che.api.project.shared.dto.TreeElement) Function(org.eclipse.che.api.promises.client.Function) ResourceChangedEvent(org.eclipse.che.ide.api.resources.ResourceChangedEvent)

Example 8 with ResourceChangedEvent

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());
                }
            }
        }
    });
}
Also used : ActivePartChangedHandler(org.eclipse.che.ide.api.event.ActivePartChangedHandler) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) Optional(com.google.common.base.Optional) ActivePartChangedEvent(org.eclipse.che.ide.api.event.ActivePartChangedEvent) Resource(org.eclipse.che.ide.api.resources.Resource) ResourceChangedEvent(org.eclipse.che.ide.api.resources.ResourceChangedEvent) Inject(com.google.inject.Inject)

Example 9 with ResourceChangedEvent

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());
    });
}
Also used : ResourceDeltaImpl(org.eclipse.che.ide.resources.impl.ResourceDeltaImpl) WindowActionEvent(org.eclipse.che.ide.api.event.WindowActionEvent) Inject(com.google.inject.Inject) Arrays(org.eclipse.che.ide.util.Arrays) SelectionChangedEvent(org.eclipse.che.ide.api.event.SelectionChangedEvent) Arrays.sort(java.util.Arrays.sort) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) ResourceDeltaImpl(org.eclipse.che.ide.resources.impl.ResourceDeltaImpl) StartUpAction(org.eclipse.che.ide.api.app.StartUpAction) UPDATED(org.eclipse.che.ide.api.resources.ResourceDelta.UPDATED) ResourceManagerInitializer(org.eclipse.che.ide.resources.ResourceManagerInitializer) Arrays.copyOf(java.util.Arrays.copyOf) WorkspaceReadyEvent(org.eclipse.che.ide.api.workspace.WorkspaceReadyEvent) WorkspaceStartedEvent(org.eclipse.che.ide.api.workspace.event.WorkspaceStartedEvent) ResourceChangedHandler(org.eclipse.che.ide.api.resources.ResourceChangedEvent.ResourceChangedHandler) Set(java.util.Set) HasDataObject(org.eclipse.che.ide.api.data.HasDataObject) DevMachine(org.eclipse.che.ide.api.machine.DevMachine) Sets(com.google.common.collect.Sets) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Callback(com.google.gwt.core.client.Callback) List(java.util.List) PROJECT(org.eclipse.che.ide.api.resources.Resource.PROJECT) MOVED_FROM(org.eclipse.che.ide.api.resources.ResourceDelta.MOVED_FROM) ADDED(org.eclipse.che.ide.api.resources.ResourceDelta.ADDED) Singleton(com.google.inject.Singleton) Workspace(org.eclipse.che.api.core.model.workspace.Workspace) Project(org.eclipse.che.ide.api.resources.Project) WindowActionHandler(org.eclipse.che.ide.api.event.WindowActionHandler) ResourcePathComparator(org.eclipse.che.ide.api.resources.ResourcePathComparator) ArrayList(java.util.ArrayList) ResourceChangedEvent(org.eclipse.che.ide.api.resources.ResourceChangedEvent) AppContext(org.eclipse.che.ide.api.app.AppContext) SYNCHRONIZED(org.eclipse.che.ide.api.resources.ResourceDelta.SYNCHRONIZED) EditorAgent(org.eclipse.che.ide.api.editor.EditorAgent) WorkspaceStoppedEvent(org.eclipse.che.ide.api.workspace.event.WorkspaceStoppedEvent) Arrays.binarySearch(java.util.Arrays.binarySearch) ActiveRuntime(org.eclipse.che.ide.api.machine.ActiveRuntime) Selection(org.eclipse.che.ide.api.selection.Selection) EventBus(com.google.web.bindery.event.shared.EventBus) SelectionChangedHandler(org.eclipse.che.ide.api.event.SelectionChangedHandler) SyntheticNode(org.eclipse.che.ide.project.node.SyntheticNode) ResourceManager(org.eclipse.che.ide.resources.impl.ResourceManager) Resource(org.eclipse.che.ide.api.resources.Resource) REMOVED(org.eclipse.che.ide.api.resources.ResourceDelta.REMOVED) ResourceDelta(org.eclipse.che.ide.api.resources.ResourceDelta) Provider(com.google.inject.Provider) Container(org.eclipse.che.ide.api.resources.Container) VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) CurrentUser(org.eclipse.che.ide.api.app.CurrentUser) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) AppStateManager(org.eclipse.che.ide.statepersistance.AppStateManager) Path(org.eclipse.che.ide.resource.Path) Project(org.eclipse.che.ide.api.resources.Project) WorkspaceReadyEvent(org.eclipse.che.ide.api.workspace.WorkspaceReadyEvent) ResourceChangedEvent(org.eclipse.che.ide.api.resources.ResourceChangedEvent)

Example 10 with ResourceChangedEvent

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()));
                }
            }
        }
    });
}
Also used : Path(org.eclipse.che.ide.resource.Path) DeleteProjectEvent(org.eclipse.che.ide.api.event.project.DeleteProjectEvent) EditorOpenedEvent(org.eclipse.che.ide.api.editor.EditorOpenedEvent) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) Resource(org.eclipse.che.ide.api.resources.Resource) DeleteProjectHandler(org.eclipse.che.ide.api.event.project.DeleteProjectHandler) EditorOpenedEventHandler(org.eclipse.che.ide.api.editor.EditorOpenedEventHandler) WorkspaceReadyEvent(org.eclipse.che.ide.api.workspace.WorkspaceReadyEvent) ResourceChangedEvent(org.eclipse.che.ide.api.resources.ResourceChangedEvent)

Aggregations

ResourceChangedEvent (org.eclipse.che.ide.api.resources.ResourceChangedEvent)12 Resource (org.eclipse.che.ide.api.resources.Resource)10 Optional (com.google.common.base.Optional)6 Path (org.eclipse.che.ide.resource.Path)6 Function (org.eclipse.che.api.promises.client.Function)5 FunctionException (org.eclipse.che.api.promises.client.FunctionException)5 ProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto)5 Project (org.eclipse.che.ide.api.resources.Project)5 Promise (org.eclipse.che.api.promises.client.Promise)4 NewProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto)4 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)4 ResourceDelta (org.eclipse.che.ide.api.resources.ResourceDelta)3 Inject (com.google.inject.Inject)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 SourceStorage (org.eclipse.che.api.core.model.project.SourceStorage)2 SourceStorageDto (org.eclipse.che.api.workspace.shared.dto.SourceStorageDto)2 EditorAgent (org.eclipse.che.ide.api.editor.EditorAgent)2 MutableProjectConfig (org.eclipse.che.ide.api.project.MutableProjectConfig)2 WorkspaceReadyEvent (org.eclipse.che.ide.api.workspace.WorkspaceReadyEvent)2