Search in sources :

Example 31 with EditorPartPresenter

use of org.eclipse.che.ide.api.editor.EditorPartPresenter in project che by eclipse.

the class EditorContentSynchronizerImplTest method shouldRemoveEditorFromGroup.

@Test
public void shouldRemoveEditorFromGroup() {
    EditorPartPresenter openedEditor1 = mock(EditorPartPresenter.class);
    EditorPartPresenter openedEditor2 = mock(EditorPartPresenter.class);
    when(openedEditor1.getEditorInput()).thenReturn(editorInput);
    when(openedEditor2.getEditorInput()).thenReturn(editorInput);
    editorContentSynchronizer.trackEditor(openedEditor1);
    editorContentSynchronizer.trackEditor(openedEditor2);
    editorContentSynchronizer.trackEditor(activeEditor);
    editorContentSynchronizer.unTrackEditor(activeEditor);
    verify(editorGroupSynchronization).removeEditor(activeEditor);
}
Also used : EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) Test(org.junit.Test)

Example 32 with EditorPartPresenter

use of org.eclipse.che.ide.api.editor.EditorPartPresenter in project che by eclipse.

the class EditorPartStackPresenterTest method shouldReturnFirstPart.

@Test
public void shouldReturnFirstPart() {
    presenter.addPart(partPresenter1);
    presenter.addPart(partPresenter2);
    presenter.addPart(partPresenter3);
    EditorPartPresenter result = presenter.getNextFor(partPresenter3);
    assertNotNull(result);
    assertEquals(partPresenter1, result);
}
Also used : EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) Test(org.junit.Test)

Example 33 with EditorPartPresenter

use of org.eclipse.che.ide.api.editor.EditorPartPresenter in project che by eclipse.

the class GoToSymbolAction method updateInPerspective.

@Override
public void updateInPerspective(@NotNull ActionEvent event) {
    EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
    if (activeEditor instanceof TextEditor) {
        TextEditorConfiguration configuration = ((TextEditor) activeEditor).getConfiguration();
        if (configuration instanceof LanguageServerEditorConfiguration) {
            ServerCapabilities capabilities = ((LanguageServerEditorConfiguration) configuration).getServerCapabilities();
            event.getPresentation().setEnabledAndVisible(capabilities.isDocumentSymbolProvider() != null && capabilities.isDocumentSymbolProvider());
            return;
        }
    }
    event.getPresentation().setEnabledAndVisible(false);
}
Also used : TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) LanguageServerEditorConfiguration(org.eclipse.che.plugin.languageserver.ide.editor.LanguageServerEditorConfiguration) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) TextEditorConfiguration(org.eclipse.che.ide.api.editor.editorconfig.TextEditorConfiguration) ServerCapabilities(io.typefox.lsapi.ServerCapabilities)

Example 34 with EditorPartPresenter

use of org.eclipse.che.ide.api.editor.EditorPartPresenter in project che by eclipse.

the class OpenFileInEditorHelper method openFile.

public void openFile(final String filePath, final TextRange selectionRange) {
    if (Strings.isNullOrEmpty(filePath)) {
        return;
    }
    EditorPartPresenter editorPartPresenter = editorAgent.getOpenedEditor(Path.valueOf(filePath));
    if (editorPartPresenter != null) {
        editorAgent.activateEditor(editorPartPresenter);
        fileOpened(editorPartPresenter, selectionRange);
        return;
    }
    appContext.getWorkspaceRoot().getFile(filePath).then(openNode(selectionRange));
}
Also used : EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter)

Example 35 with EditorPartPresenter

use of org.eclipse.che.ide.api.editor.EditorPartPresenter in project che by eclipse.

the class OccurrencesProvider method computeOccurrences.

@Override
public JsPromise<OrionOccurrenceOverlay[]> computeOccurrences(OrionOccurrenceContextOverlay context) {
    final EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
    if (activeEditor == null || !(activeEditor instanceof TextEditor)) {
        return null;
    }
    final TextEditor editor = ((TextEditor) activeEditor);
    if (!(editor.getConfiguration() instanceof LanguageServerEditorConfiguration)) {
        return null;
    }
    final LanguageServerEditorConfiguration configuration = (LanguageServerEditorConfiguration) editor.getConfiguration();
    if (configuration.getServerCapabilities().isDocumentHighlightProvider() == null || !configuration.getServerCapabilities().isDocumentHighlightProvider()) {
        return null;
    }
    final Document document = editor.getDocument();
    final TextDocumentPositionParamsDTO paramsDTO = helper.createTDPP(document, context.getStart());
    // FIXME: the result should be a Promise<List<DocumentHighlightDTO>> but the typefox API returns a single DocumentHighlightDTO
    Promise<DocumentHighlightDTO> promise = client.documentHighlight(paramsDTO);
    Promise<OrionOccurrenceOverlay[]> then = promise.then(new Function<DocumentHighlightDTO, OrionOccurrenceOverlay[]>() {

        @Override
        public OrionOccurrenceOverlay[] apply(DocumentHighlightDTO highlight) throws FunctionException {
            if (highlight == null) {
                return new OrionOccurrenceOverlay[0];
            }
            final OrionOccurrenceOverlay[] occurrences = new OrionOccurrenceOverlay[1];
            final OrionOccurrenceOverlay occurrence = OrionOccurrenceOverlay.create();
            // FIXME: this assumes that the language server will
            // compute a range based on 'line 1', ie, the whole
            // file content is on line 1 and the location to
            // highlight is given by the 'character' position
            // only.
            occurrence.setStart(highlight.getRange().getStart().getCharacter());
            occurrence.setEnd(highlight.getRange().getEnd().getCharacter() + 1);
            occurrences[0] = occurrence;
            return occurrences;
        }
    });
    return (JsPromise<OrionOccurrenceOverlay[]>) then;
}
Also used : TextDocumentPositionParamsDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO) FunctionException(org.eclipse.che.api.promises.client.FunctionException) JsPromise(org.eclipse.che.api.promises.client.js.JsPromise) Document(org.eclipse.che.ide.api.editor.document.Document) OrionOccurrenceOverlay(org.eclipse.che.ide.editor.orion.client.jso.OrionOccurrenceOverlay) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) LanguageServerEditorConfiguration(org.eclipse.che.plugin.languageserver.ide.editor.LanguageServerEditorConfiguration) DocumentHighlightDTO(org.eclipse.che.api.languageserver.shared.lsapi.DocumentHighlightDTO) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter)

Aggregations

EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)79 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)21 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)19 OperationException (org.eclipse.che.api.promises.client.OperationException)13 Project (org.eclipse.che.ide.api.resources.Project)13 Resource (org.eclipse.che.ide.api.resources.Resource)11 Test (org.junit.Test)10 Operation (org.eclipse.che.api.promises.client.Operation)9 Path (org.eclipse.che.ide.resource.Path)8 File (org.eclipse.che.ide.api.resources.File)7 Scheduler (com.google.gwt.core.client.Scheduler)6 EditorPartStack (org.eclipse.che.ide.api.parts.EditorPartStack)6 PartPresenter (org.eclipse.che.ide.api.parts.PartPresenter)6 Optional (com.google.common.base.Optional)5 OpenEditorCallbackImpl (org.eclipse.che.ide.api.editor.OpenEditorCallbackImpl)5 LanguageServerEditorConfiguration (org.eclipse.che.plugin.languageserver.ide.editor.LanguageServerEditorConfiguration)5 HandlesTextOperations (org.eclipse.che.ide.api.editor.texteditor.HandlesTextOperations)4 ResourceDelta (org.eclipse.che.ide.api.resources.ResourceDelta)4 ClassContent (org.eclipse.che.ide.ext.java.shared.dto.ClassContent)4 JsonObject (elemental.json.JsonObject)3