Search in sources :

Example 1 with EditorAgent

use of org.eclipse.che.ide.api.editor.EditorAgent in project che by eclipse.

the class AppContextImpl method getRootProject.

@Override
public Project getRootProject() {
    if (projects == null) {
        return null;
    }
    if (currentResource == null || currentResources == null) {
        EditorAgent editorAgent = editorAgentProvider.get();
        if (editorAgent == null) {
            return null;
        }
        final EditorPartPresenter editor = editorAgent.getActiveEditor();
        if (editor == null) {
            return null;
        }
        final VirtualFile file = editor.getEditorInput().getFile();
        if (file instanceof SyntheticNode) {
            final Path projectPath = ((SyntheticNode) file).getProject();
            for (Project project : projects) {
                if (project.getLocation().equals(projectPath)) {
                    return project;
                }
            }
        }
    }
    if (currentResource == null) {
        return null;
    }
    Project root = null;
    for (Project project : projects) {
        if (project.getLocation().isPrefixOf(currentResource.getLocation())) {
            root = project;
        }
    }
    if (root == null) {
        return null;
    }
    for (int i = 1; i < currentResources.length; i++) {
        if (!root.getLocation().isPrefixOf(currentResources[i].getLocation())) {
            return null;
        }
    }
    return root;
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) Path(org.eclipse.che.ide.resource.Path) Project(org.eclipse.che.ide.api.resources.Project) EditorAgent(org.eclipse.che.ide.api.editor.EditorAgent) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) SyntheticNode(org.eclipse.che.ide.project.node.SyntheticNode)

Example 2 with EditorAgent

use of org.eclipse.che.ide.api.editor.EditorAgent 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)

Aggregations

EditorAgent (org.eclipse.che.ide.api.editor.EditorAgent)2 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)2 Project (org.eclipse.che.ide.api.resources.Project)2 ResourceChangedEvent (org.eclipse.che.ide.api.resources.ResourceChangedEvent)1 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)1 SyntheticNode (org.eclipse.che.ide.project.node.SyntheticNode)1 Path (org.eclipse.che.ide.resource.Path)1 ResourceDeltaImpl (org.eclipse.che.ide.resources.impl.ResourceDeltaImpl)1