Search in sources :

Example 1 with SyntheticNode

use of org.eclipse.che.ide.project.node.SyntheticNode 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)

Aggregations

EditorAgent (org.eclipse.che.ide.api.editor.EditorAgent)1 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)1 Project (org.eclipse.che.ide.api.resources.Project)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