Search in sources :

Example 11 with ResourceChangedEvent

use of org.eclipse.che.ide.api.resources.ResourceChangedEvent in project che by eclipse.

the class AppContextImpl method onWorkspaceStopped.

@Override
public void onWorkspaceStopped(WorkspaceStoppedEvent event) {
    appStateManager.get().persistWorkspaceState(getWorkspaceId()).then(ignored -> {
        for (Project project : projects) {
            eventBus.fireEvent(new ResourceChangedEvent(new ResourceDeltaImpl(project, REMOVED)));
        }
        projects = NO_PROJECTS;
        resourceManager = null;
    });
    //goto close all editors
    final EditorAgent editorAgent = editorAgentProvider.get();
    final List<EditorPartPresenter> openedEditors = editorAgent.getOpenedEditors();
    for (EditorPartPresenter editor : openedEditors) {
        editorAgent.closeEditor(editor);
    }
    runtime = null;
}
Also used : ResourceDeltaImpl(org.eclipse.che.ide.resources.impl.ResourceDeltaImpl) Project(org.eclipse.che.ide.api.resources.Project) EditorAgent(org.eclipse.che.ide.api.editor.EditorAgent) ResourceChangedEvent(org.eclipse.che.ide.api.resources.ResourceChangedEvent) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter)

Example 12 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)

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