Search in sources :

Example 26 with VirtualFile

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);
            }
        }
    });
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) PromiseError(org.eclipse.che.api.promises.client.PromiseError) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 27 with VirtualFile

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);
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) FileType(org.eclipse.che.ide.api.filetypes.FileType) EditorInput(org.eclipse.che.ide.api.editor.EditorInput) Test(org.junit.Test)

Example 28 with VirtualFile

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);
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter)

Example 29 with VirtualFile

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));
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) Test(org.junit.Test)

Example 30 with VirtualFile

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();
            }
        });
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) CompilationUnit(org.eclipse.che.ide.ext.java.shared.dto.model.CompilationUnit) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) Project(org.eclipse.che.ide.api.resources.Project) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) PromiseError(org.eclipse.che.api.promises.client.PromiseError) OperationException(org.eclipse.che.api.promises.client.OperationException)

Aggregations

VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)48 Project (org.eclipse.che.ide.api.resources.Project)21 Resource (org.eclipse.che.ide.api.resources.Resource)19 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)18 OperationException (org.eclipse.che.api.promises.client.OperationException)15 Operation (org.eclipse.che.api.promises.client.Operation)14 PromiseError (org.eclipse.che.api.promises.client.PromiseError)9 File (org.eclipse.che.ide.api.resources.File)8 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)6 Test (org.junit.Test)6 Optional (com.google.common.base.Optional)5 Scheduler (com.google.gwt.core.client.Scheduler)4 HashMap (java.util.HashMap)4 EditorInput (org.eclipse.che.ide.api.editor.EditorInput)4 OpenEditorCallbackImpl (org.eclipse.che.ide.api.editor.OpenEditorCallbackImpl)4 JarEntry (org.eclipse.che.ide.ext.java.shared.JarEntry)4 ClassContent (org.eclipse.che.ide.ext.java.shared.dto.ClassContent)4 Path (org.eclipse.che.ide.resource.Path)4 Breakpoint (org.eclipse.che.ide.api.debug.Breakpoint)3 JarFileNode (org.eclipse.che.ide.ext.java.client.tree.library.JarFileNode)3