Search in sources :

Example 61 with Path

use of org.eclipse.che.ide.resource.Path in project che by eclipse.

the class EditorContentSynchronizerImpl method onFolderChanged.

private void onFolderChanged(Path fromPath, Path toPath) {
    final Map<Path, EditorGroupSynchronization> newGroups = new HashMap<>(editorGroups.size());
    final Iterator<Map.Entry<Path, EditorGroupSynchronization>> iterator = editorGroups.entrySet().iterator();
    while (iterator.hasNext()) {
        final Map.Entry<Path, EditorGroupSynchronization> entry = iterator.next();
        final Path groupPath = entry.getKey();
        final EditorGroupSynchronization group = entry.getValue();
        if (fromPath.isPrefixOf(groupPath)) {
            final Path relPath = groupPath.removeFirstSegments(fromPath.segmentCount());
            final Path newPath = toPath.append(relPath);
            newGroups.put(newPath, group);
            iterator.remove();
        }
    }
    editorGroups.putAll(newGroups);
}
Also used : Path(org.eclipse.che.ide.resource.Path) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 62 with Path

use of org.eclipse.che.ide.resource.Path in project che by eclipse.

the class EditorContentSynchronizerImpl method trackEditor.

/**
     * Begins to track given editor to sync its content with opened files with the same {@link Path}.
     *
     * @param editor
     *         editor to sync content
     */
@Override
public void trackEditor(EditorPartPresenter editor) {
    Path path = editor.getEditorInput().getFile().getLocation();
    if (editorGroups.containsKey(path)) {
        editorGroups.get(path).addEditor(editor);
    } else {
        EditorGroupSynchronization group = editorGroupSyncProvider.get();
        editorGroups.put(path, group);
        group.addEditor(editor);
    }
}
Also used : Path(org.eclipse.che.ide.resource.Path)

Example 63 with Path

use of org.eclipse.che.ide.resource.Path in project che by eclipse.

the class EditorAgentImpl method onSelectionChanged.

@Override
public void onSelectionChanged(SelectionChangedEvent event) {
    final String isLinkedWithEditor = preferencesManager.getValue(LinkWithEditorAction.LINK_WITH_EDITOR);
    if (!parseBoolean(isLinkedWithEditor)) {
        return;
    }
    final Selection<?> selection = event.getSelection();
    if (selection instanceof Selection.NoSelectionProvided) {
        return;
    }
    Resource currentResource = null;
    if (selection == null || selection.getHeadElement() == null || selection.getAllElements().size() > 1) {
        return;
    }
    final Object headObject = selection.getHeadElement();
    if (headObject instanceof HasDataObject) {
        Object data = ((HasDataObject) headObject).getData();
        if (data instanceof Resource) {
            currentResource = (Resource) data;
        }
    } else if (headObject instanceof Resource) {
        currentResource = (Resource) headObject;
    }
    EditorPartStack activePartStack = editorMultiPartStack.getActivePartStack();
    if (currentResource == null || activePartStack == null || activeEditor == null) {
        return;
    }
    final Path locationOfActiveOpenedFile = activeEditor.getEditorInput().getFile().getLocation();
    final Path selectedResourceLocation = currentResource.getLocation();
    if (!(activePart instanceof ProjectExplorerPresenter) && selectedResourceLocation.equals(locationOfActiveOpenedFile)) {
        return;
    }
    PartPresenter partPresenter = activePartStack.getPartByPath(selectedResourceLocation);
    if (partPresenter != null) {
        workspaceAgent.setActivePart(partPresenter, EDITING);
    }
}
Also used : Path(org.eclipse.che.ide.resource.Path) HasDataObject(org.eclipse.che.ide.api.data.HasDataObject) Resource(org.eclipse.che.ide.api.resources.Resource) HasDataObject(org.eclipse.che.ide.api.data.HasDataObject) JsonObject(elemental.json.JsonObject) PartPresenter(org.eclipse.che.ide.api.parts.PartPresenter) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) EditorPartStack(org.eclipse.che.ide.api.parts.EditorPartStack) ProjectExplorerPresenter(org.eclipse.che.ide.part.explorer.project.ProjectExplorerPresenter)

Example 64 with Path

use of org.eclipse.che.ide.resource.Path in project che by eclipse.

the class EditorCurrentFilePathMacro method expand.

/** {@inheritDoc} */
@Override
public Promise<String> expand() {
    final EditorPartPresenter editor = getActiveEditor();
    if (editor == null) {
        return promises.resolve("");
    }
    final Path absolutePath = appContext.getProjectsRoot().append(editor.getEditorInput().getFile().getLocation());
    return promises.resolve(absolutePath.toString());
}
Also used : Path(org.eclipse.che.ide.resource.Path) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter)

Example 65 with Path

use of org.eclipse.che.ide.resource.Path 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

Path (org.eclipse.che.ide.resource.Path)72 Resource (org.eclipse.che.ide.api.resources.Resource)27 Operation (org.eclipse.che.api.promises.client.Operation)15 OperationException (org.eclipse.che.api.promises.client.OperationException)15 PromiseError (org.eclipse.che.api.promises.client.PromiseError)13 ArrayList (java.util.ArrayList)11 Project (org.eclipse.che.ide.api.resources.Project)11 Promise (org.eclipse.che.api.promises.client.Promise)10 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)10 List (java.util.List)8 Test (org.junit.Test)7 ResourceDelta (org.eclipse.che.ide.api.resources.ResourceDelta)6 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)6 Optional (com.google.common.base.Optional)5 Function (org.eclipse.che.api.promises.client.Function)5 FunctionException (org.eclipse.che.api.promises.client.FunctionException)5 Container (org.eclipse.che.ide.api.resources.Container)5 ResourceChangedEvent (org.eclipse.che.ide.api.resources.ResourceChangedEvent)5 HashMap (java.util.HashMap)4 ProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto)4