Search in sources :

Example 26 with TextEditor

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

the class QuickDocPresenter method showDocumentation.

@Override
public void showDocumentation() {
    EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
    if (activeEditor == null) {
        return;
    }
    if (!(activeEditor instanceof TextEditor)) {
        Log.error(getClass(), "Quick Document support only TextEditor as editor");
        return;
    }
    TextEditor editor = ((TextEditor) activeEditor);
    int offset = editor.getCursorOffset();
    final PositionConverter.PixelCoordinates coordinates = editor.getPositionConverter().offsetToPixel(offset);
    final Resource resource = appContext.getResource();
    if (resource != null) {
        final Optional<Project> project = resource.getRelatedProject();
        final Optional<Resource> srcFolder = resource.getParentWithMarker(SourceFolderMarker.ID);
        if (!srcFolder.isPresent()) {
            return;
        }
        final String fqn = JavaUtil.resolveFQN((Container) srcFolder.get(), resource);
        final String docUrl = appContext.getDevMachine().getWsAgentBaseUrl() + "/java/javadoc/find?fqn=" + fqn + "&projectpath=" + project.get().getLocation() + "&offset=" + offset;
        view.show(agentURLDecorator.modify(docUrl), coordinates.getX(), coordinates.getY());
    }
}
Also used : Project(org.eclipse.che.ide.api.resources.Project) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) Resource(org.eclipse.che.ide.api.resources.Resource) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) PositionConverter(org.eclipse.che.ide.api.editor.position.PositionConverter)

Example 27 with TextEditor

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

the class FileWatcher method handleFileOperations.

@Inject
private void handleFileOperations(EventBus eventBus) {
    eventBus.addHandler(ResourceChangedEvent.getType(), new ResourceChangedEvent.ResourceChangedHandler() {

        @Override
        public void onResourceChanged(ResourceChangedEvent event) {
            if (event.getDelta().getKind() != REMOVED) {
                return;
            }
            if ((event.getDelta().getFlags() & DERIVED) == 0) {
                return;
            }
            final Resource resource = event.getDelta().getResource();
            final Optional<Resource> srcFolder = resource.getParentWithMarker(SourceFolderMarker.ID);
            if (srcFolder.isPresent()) {
                reparseAllOpenedFiles();
            }
        }
    });
    eventBus.addHandler(ActivePartChangedEvent.TYPE, new ActivePartChangedHandler() {

        @Override
        public void onActivePartChanged(ActivePartChangedEvent event) {
            if (event.getActivePart() instanceof TextEditor) {
                if (editor2reconcile.contains(event.getActivePart())) {
                    reParseEditor((TextEditor) event.getActivePart());
                }
            }
        }
    });
}
Also used : ActivePartChangedHandler(org.eclipse.che.ide.api.event.ActivePartChangedHandler) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) Optional(com.google.common.base.Optional) ActivePartChangedEvent(org.eclipse.che.ide.api.event.ActivePartChangedEvent) Resource(org.eclipse.che.ide.api.resources.Resource) ResourceChangedEvent(org.eclipse.che.ide.api.resources.ResourceChangedEvent) Inject(com.google.inject.Inject)

Example 28 with TextEditor

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

the class OpenImplementationPresenter method show.

/**
     * Shows the implementations of the selected element.
     *
     * @param editorPartPresenter
     *         the active editor
     */
public void show(final EditorPartPresenter editorPartPresenter) {
    if (!(editorPartPresenter instanceof TextEditor)) {
        Log.error(getClass(), "Open Declaration support only TextEditor as editor");
        return;
    }
    activeEditor = ((TextEditor) editorPartPresenter);
    final 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);
        service.getImplementations(project.get().getLocation(), fqn, activeEditor.getCursorOffset()).then(new Operation<ImplementationsDescriptorDTO>() {

            @Override
            public void apply(ImplementationsDescriptorDTO impls) throws OperationException {
                int overridingSize = impls.getImplementations().size();
                String title = locale.openImplementationWindowTitle(impls.getMemberName(), overridingSize);
                NoImplementationWidget noImplementationWidget = new NoImplementationWidget(popupResources, javaResources, locale, OpenImplementationPresenter.this, title);
                if (overridingSize == 1) {
                    actionPerformed(impls.getImplementations().get(0));
                } else if (overridingSize > 1) {
                    openOneImplementation(impls, noImplementationWidget, (TextEditor) editorPartPresenter);
                } else if (!isNullOrEmpty(impls.getMemberName()) && overridingSize == 0) {
                    showNoImplementations(noImplementationWidget, (TextEditor) editorPartPresenter);
                }
            }
        });
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) Project(org.eclipse.che.ide.api.resources.Project) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) Resource(org.eclipse.che.ide.api.resources.Resource) ImplementationsDescriptorDTO(org.eclipse.che.ide.ext.java.shared.dto.ImplementationsDescriptorDTO) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 29 with TextEditor

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

the class JavaQuickAssistProcessor method computeQuickAssistProposals.

@Override
public void computeQuickAssistProposals(final QuickAssistInvocationContext quickAssistContext, final CodeAssistCallback callback) {
    final TextEditor textEditor = quickAssistContext.getTextEditor();
    final Document document = textEditor.getDocument();
    LinearRange tempRange;
    tempRange = textEditor.getSelectedLinearRange();
    final LinearRange range = tempRange;
    final boolean goToClosest = (range.getLength() == 0);
    final QueryAnnotationsEvent.AnnotationFilter filter = new QueryAnnotationsEvent.AnnotationFilter() {

        @Override
        public boolean accept(final Annotation annotation) {
            if (!(annotation instanceof JavaAnnotation)) {
                return false;
            } else {
                JavaAnnotation javaAnnotation = (JavaAnnotation) annotation;
                return (!javaAnnotation.isMarkedDeleted());
            }
        }
    };
    final QueryAnnotationsEvent.QueryCallback queryCallback = new QueryAnnotationsEvent.QueryCallback() {

        @Override
        public void respond(final Map<Annotation, Position> annotations) {
            List<Problem> problems = new ArrayList<>();
            /*final Map<Annotation, Position> problems =*/
            int offset = collectQuickFixableAnnotations(range, document, annotations, goToClosest, problems);
            if (offset != range.getStartOffset()) {
                TextEditor presenter = ((TextEditor) textEditor);
                presenter.getCursorModel().setCursorPosition(offset);
            }
            setupProposals(callback, textEditor, offset, problems);
        }
    };
    final QueryAnnotationsEvent event = new QueryAnnotationsEvent.Builder().withFilter(filter).withCallback(queryCallback).build();
    document.getDocumentHandle().getDocEventBus().fireEvent(event);
}
Also used : LinearRange(org.eclipse.che.ide.api.editor.text.LinearRange) ArrayList(java.util.ArrayList) Document(org.eclipse.che.ide.api.editor.document.Document) QueryAnnotationsEvent(org.eclipse.che.ide.api.editor.annotation.QueryAnnotationsEvent) Annotation(org.eclipse.che.ide.api.editor.text.annotation.Annotation) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) Problem(org.eclipse.che.ide.ext.java.shared.dto.Problem) Map(java.util.Map)

Example 30 with TextEditor

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

the class ParametersHintsAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent event) {
    EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
    if (!(activeEditor instanceof TextEditor)) {
        return;
    }
    parametersHintsPresenter.show((TextEditor) activeEditor);
}
Also used : TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter)

Aggregations

TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)33 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)21 Project (org.eclipse.che.ide.api.resources.Project)8 Resource (org.eclipse.che.ide.api.resources.Resource)8 OperationException (org.eclipse.che.api.promises.client.OperationException)7 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)7 Operation (org.eclipse.che.api.promises.client.Operation)6 Document (org.eclipse.che.ide.api.editor.document.Document)5 TextEditorConfiguration (org.eclipse.che.ide.api.editor.editorconfig.TextEditorConfiguration)5 LanguageServerEditorConfiguration (org.eclipse.che.plugin.languageserver.ide.editor.LanguageServerEditorConfiguration)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 PromiseError (org.eclipse.che.api.promises.client.PromiseError)4 File (org.eclipse.che.ide.api.resources.File)4 Optional (com.google.common.base.Optional)3 ServerCapabilities (io.typefox.lsapi.ServerCapabilities)3 TextDocumentPositionParamsDTO (org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO)3 Collections.singletonList (java.util.Collections.singletonList)2 FunctionException (org.eclipse.che.api.promises.client.FunctionException)2 JsPromise (org.eclipse.che.api.promises.client.js.JsPromise)2