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