use of org.eclipse.che.ide.api.resources.VirtualFile in project che by eclipse.
the class DocumentStorageImpl method saveDocument.
@Override
public void saveDocument(final EditorInput editorInput, @NotNull final Document document, final boolean overwrite, @NotNull final AsyncCallback<EditorInput> callback) {
final VirtualFile file = editorInput.getFile();
file.updateContent(document.getContents()).then(new Operation<Void>() {
@Override
public void apply(Void arg) throws OperationException {
Log.debug(DocumentStorageImpl.class, "Document saved (" + file.getLocation() + ").");
DocumentStorageImpl.this.eventBus.fireEvent(FileEvent.createSaveFileEvent(file));
try {
callback.onSuccess(editorInput);
} catch (final Exception e) {
Log.warn(DocumentStorageImpl.class, "Exception during save success callback: ", e);
}
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
Log.error(DocumentStorageImpl.class, "Document save failed (" + file.getLocation() + ").", arg.getCause());
try {
callback.onFailure(arg.getCause());
} catch (final Exception e) {
Log.warn(DocumentStorageImpl.class, "Exception during save failure callback: ", e);
}
}
});
}
use of org.eclipse.che.ide.api.resources.VirtualFile in project che by eclipse.
the class EditorTabWidgetTest method virtualFileShouldBeUpdated.
@Test
public void virtualFileShouldBeUpdated() throws Exception {
EditorInput editorInput = mock(EditorInput.class);
FileType fileType = mock(FileType.class);
VirtualFile newFile = mock(VirtualFile.class);
when(editorPartPresenter.getEditorInput()).thenReturn(editorInput);
when(fileTypeRegistry.getFileTypeByFile(newFile)).thenReturn(fileType);
when(fileType.getImage()).thenReturn(icon);
when(editorInput.getFile()).thenReturn(newFile);
assertNotEquals(tab.getFile(), newFile);
tab.update(editorPartPresenter);
assertEquals(tab.getFile(), newFile);
}
use of org.eclipse.che.ide.api.resources.VirtualFile in project che by eclipse.
the class JavaDebuggerFileHandler method openFile.
@Override
public void openFile(Location location, AsyncCallback<VirtualFile> callback) {
VirtualFile activeFile = null;
String activePath = null;
final EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
if (activeEditor != null) {
activeFile = editorAgent.getActiveEditor().getEditorInput().getFile();
activePath = activeFile.getLocation().toString();
}
if (activePath != null && !activePath.equals(location.getTarget()) && !activePath.equals(location.getResourcePath())) {
if (location.isExternalResource()) {
openExternalResource(location, callback);
} else {
doOpenFile(location, callback);
}
} else {
scrollEditorToExecutionPoint((TextEditor) activeEditor, location.getLineNumber());
callback.onSuccess(activeFile);
}
}
use of org.eclipse.che.ide.api.resources.VirtualFile in project che by eclipse.
the class RecipeEditorInputTest method fileShouldBeChanged.
@Test
public void fileShouldBeChanged() {
VirtualFile file1 = mock(VirtualFile.class);
assertThat(recipeEditorInput.getFile(), is(file));
recipeEditorInput.setFile(file1);
assertThat(recipeEditorInput.getFile(), is(file1));
}
use of org.eclipse.che.ide.api.resources.VirtualFile in project che by eclipse.
the class FileStructurePresenter method show.
/**
* Shows the structure of the opened class.
*
* @param editorPartPresenter
* the active editor
*/
public void show(EditorPartPresenter editorPartPresenter) {
loader.show();
view.setTitle(editorPartPresenter.getEditorInput().getFile().getName());
if (!(editorPartPresenter instanceof TextEditor)) {
Log.error(getClass(), "Open Declaration support only TextEditor as editor");
return;
}
activeEditor = ((TextEditor) editorPartPresenter);
cursorOffset = activeEditor.getCursorOffset();
VirtualFile file = activeEditor.getEditorInput().getFile();
if (file instanceof Resource) {
final Optional<Project> project = ((Resource) file).getRelatedProject();
final Optional<Resource> srcFolder = ((Resource) file).getParentWithMarker(SourceFolderMarker.ID);
if (!srcFolder.isPresent()) {
return;
}
final String fqn = JavaUtil.resolveFQN((Container) srcFolder.get(), (Resource) file);
javaNavigationService.getCompilationUnit(project.get().getLocation(), fqn, showInheritedMembers).then(new Operation<CompilationUnit>() {
@Override
public void apply(CompilationUnit unit) throws OperationException {
view.setStructure(unit, showInheritedMembers);
showInheritedMembers = !showInheritedMembers;
loader.hide();
view.show();
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
Log.error(FileStructurePresenter.class, arg.getMessage());
loader.hide();
}
});
}
}
Aggregations