Search in sources :

Example 36 with Operation

use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.

the class MovePresenter method showProjectsAndPackages.

private void showProjectsAndPackages() {
    Promise<List<JavaProject>> projectsPromise = navigationService.getProjectsAndPackages(true);
    projectsPromise.then(new Operation<List<JavaProject>>() {

        @Override
        public void apply(List<JavaProject> projects) throws OperationException {
            List<JavaProject> currentProject = new ArrayList<>();
            for (JavaProject project : projects) {
                currentProject.add(project);
            }
            view.setTreeOfDestinations(currentProject);
            view.show(refactorInfo);
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            notificationManager.notify(locale.showPackagesError(), error.getMessage(), Status.FAIL, FLOAT_MODE);
        }
    });
}
Also used : JavaProject(org.eclipse.che.ide.ext.java.shared.dto.model.JavaProject) PromiseError(org.eclipse.che.api.promises.client.PromiseError) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 37 with Operation

use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.

the class OpenDeclarationFinder method openDeclaration.

public void openDeclaration() {
    EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
    if (activeEditor == null) {
        return;
    }
    if (!(activeEditor instanceof TextEditor)) {
        Log.error(getClass(), "Open Declaration support only TextEditor as editor");
        return;
    }
    TextEditor editor = ((TextEditor) activeEditor);
    int offset = editor.getCursorOffset();
    final VirtualFile file = editor.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);
        navigationService.findDeclaration(project.get().getLocation(), fqn, offset).then(new Operation<OpenDeclarationDescriptor>() {

            @Override
            public void apply(OpenDeclarationDescriptor result) throws OperationException {
                if (result != null) {
                    handleDescriptor(project.get().getLocation(), result);
                }
            }
        });
    } else if (file instanceof JarFileNode) {
        navigationService.findDeclaration(((JarFileNode) file).getProjectLocation(), file.getLocation().toString().replace('/', '.'), offset).then(new Operation<OpenDeclarationDescriptor>() {

            @Override
            public void apply(OpenDeclarationDescriptor result) throws OperationException {
                if (result != null) {
                    handleDescriptor(((JarFileNode) file).getProject(), result);
                }
            }
        });
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) OpenDeclarationDescriptor(org.eclipse.che.ide.ext.java.shared.OpenDeclarationDescriptor) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) JarFileNode(org.eclipse.che.ide.ext.java.client.tree.library.JarFileNode) Project(org.eclipse.che.ide.api.resources.Project) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 38 with Operation

use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.

the class OpenDeclarationFinder method handleDescriptor.

private void handleDescriptor(final Path projectPath, final OpenDeclarationDescriptor descriptor) {
    final EditorPartPresenter openedEditor = editorAgent.getOpenedEditor(Path.valueOf(descriptor.getPath()));
    if (openedEditor != null) {
        editorAgent.openEditor(openedEditor.getEditorInput().getFile(), new OpenEditorCallbackImpl() {

            @Override
            public void onEditorOpened(EditorPartPresenter editor) {
                setCursorAndActivateEditor(editor, descriptor.getOffset());
            }

            @Override
            public void onEditorActivated(EditorPartPresenter editor) {
                setCursorAndActivateEditor(editor, descriptor.getOffset());
            }
        });
        return;
    }
    if (descriptor.isBinary()) {
        navigationService.getEntry(projectPath, descriptor.getLibId(), descriptor.getPath()).then(new Operation<JarEntry>() {

            @Override
            public void apply(final JarEntry entry) throws OperationException {
                navigationService.getContent(projectPath, descriptor.getLibId(), Path.valueOf(entry.getPath())).then(new Operation<ClassContent>() {

                    @Override
                    public void apply(ClassContent content) throws OperationException {
                        final VirtualFile file = javaNodeFactory.newJarFileNode(entry, descriptor.getLibId(), projectPath, null);
                        editorAgent.openEditor(file, new OpenEditorCallbackImpl() {

                            @Override
                            public void onEditorOpened(final EditorPartPresenter editor) {
                                Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {

                                    @Override
                                    public void execute() {
                                        if (editor instanceof TextEditor) {
                                            ((TextEditor) editor).getDocument().setSelectedRange(LinearRange.createWithStart(descriptor.getOffset()).andLength(0), true);
                                            editor.activate();
                                        }
                                    }
                                });
                            }
                        });
                    }
                });
            }
        });
    } else {
        appContext.getWorkspaceRoot().getFile(descriptor.getPath()).then(new Operation<Optional<File>>() {

            @Override
            public void apply(Optional<File> file) throws OperationException {
                if (file.isPresent()) {
                    editorAgent.openEditor(file.get(), new OpenEditorCallbackImpl() {

                        @Override
                        public void onEditorOpened(final EditorPartPresenter editor) {
                            Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {

                                @Override
                                public void execute() {
                                    if (editor instanceof TextEditor) {
                                        ((TextEditor) editor).getDocument().setSelectedRange(LinearRange.createWithStart(descriptor.getOffset()).andLength(0), true);
                                        editor.activate();
                                    }
                                }
                            });
                        }
                    });
                }
            }
        });
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) ClassContent(org.eclipse.che.ide.ext.java.shared.dto.ClassContent) Optional(com.google.common.base.Optional) Scheduler(com.google.gwt.core.client.Scheduler) OpenEditorCallbackImpl(org.eclipse.che.ide.api.editor.OpenEditorCallbackImpl) Operation(org.eclipse.che.api.promises.client.Operation) JarEntry(org.eclipse.che.ide.ext.java.shared.JarEntry) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) File(org.eclipse.che.ide.api.resources.File) VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 39 with Operation

use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.

the class LanguageServerFileTypeRegister method start.

@Override
public void start(final Callback<WsAgentComponent, Exception> callback) {
    Promise<List<LanguageDescriptionDTO>> registeredLanguages = serverLanguageRegistry.getSupportedLanguages();
    registeredLanguages.then(new Operation<List<LanguageDescriptionDTO>>() {

        @Override
        public void apply(List<LanguageDescriptionDTO> langs) throws OperationException {
            if (!langs.isEmpty()) {
                JsArrayString contentTypes = JsArrayString.createArray().cast();
                for (LanguageDescriptionDTO lang : langs) {
                    String primaryExtension = lang.getFileExtensions().get(0);
                    for (String ext : lang.getFileExtensions()) {
                        final FileType fileType = new FileType(resources.file(), ext);
                        fileTypeRegistry.registerFileType(fileType);
                        editorRegistry.registerDefaultEditor(fileType, editorProvider);
                        ext2langId.put(ext, lang.getLanguageId());
                    }
                    List<String> mimeTypes = lang.getMimeTypes();
                    if (mimeTypes.isEmpty()) {
                        mimeTypes = newArrayList("text/x-" + lang.getLanguageId());
                    }
                    for (String contentTypeId : mimeTypes) {
                        contentTypes.push(contentTypeId);
                        OrionContentTypeOverlay contentType = OrionContentTypeOverlay.create();
                        contentType.setId(contentTypeId);
                        contentType.setName(lang.getLanguageId());
                        contentType.setExtension(primaryExtension);
                        contentType.setExtends("text/plain");
                        // highlighting
                        OrionHighlightingConfigurationOverlay config = OrionHighlightingConfigurationOverlay.create();
                        config.setId(lang.getLanguageId() + ".highlighting");
                        config.setContentTypes(contentTypeId);
                        config.setPatterns(lang.getHighlightingConfiguration());
                        Logger logger = Logger.getLogger(LanguageServerFileTypeRegister.class.getName());
                        contentTypeRegistrant.registerFileType(contentType, config);
                    }
                }
                orionHoverRegistrant.registerHover(contentTypes, hoverProvider);
                orionOccurrencesRegistrant.registerOccurrencesHandler(contentTypes, occurrencesProvider);
            }
            callback.onSuccess(LanguageServerFileTypeRegister.this);
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError arg) throws OperationException {
            callback.onFailure(new Exception(arg.getMessage(), arg.getCause()));
        }
    });
}
Also used : OrionHighlightingConfigurationOverlay(org.eclipse.che.ide.editor.orion.client.jso.OrionHighlightingConfigurationOverlay) LanguageDescriptionDTO(org.eclipse.che.api.languageserver.shared.lsapi.LanguageDescriptionDTO) OrionContentTypeOverlay(org.eclipse.che.ide.editor.orion.client.jso.OrionContentTypeOverlay) Operation(org.eclipse.che.api.promises.client.Operation) JsArrayString(com.google.gwt.core.client.JsArrayString) JsArrayString(com.google.gwt.core.client.JsArrayString) Logger(java.util.logging.Logger) OperationException(org.eclipse.che.api.promises.client.OperationException) PromiseError(org.eclipse.che.api.promises.client.PromiseError) FileType(org.eclipse.che.ide.api.filetypes.FileType) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 40 with Operation

use of org.eclipse.che.api.promises.client.Operation in project che by eclipse.

the class GoToSymbolAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    DocumentSymbolParamsDTO paramsDTO = dtoFactory.createDto(DocumentSymbolParamsDTO.class);
    TextDocumentIdentifierDTO identifierDTO = dtoFactory.createDto(TextDocumentIdentifierDTO.class);
    identifierDTO.setUri(editorAgent.getActiveEditor().getEditorInput().getFile().getLocation().toString());
    paramsDTO.setTextDocument(identifierDTO);
    activeEditor = (TextEditor) editorAgent.getActiveEditor();
    cursorPosition = activeEditor.getDocument().getCursorPosition();
    client.documentSymbol(paramsDTO).then(new Operation<List<SymbolInformationDTO>>() {

        @Override
        public void apply(List<SymbolInformationDTO> arg) throws OperationException {
            cachedItems = arg;
            presenter.run(GoToSymbolAction.this);
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError arg) throws OperationException {
            notificationManager.notify("Can't fetch document symbols.", arg.getMessage(), StatusNotification.Status.FAIL, StatusNotification.DisplayMode.FLOAT_MODE);
        }
    });
}
Also used : SymbolInformationDTO(org.eclipse.che.api.languageserver.shared.lsapi.SymbolInformationDTO) DocumentSymbolParamsDTO(org.eclipse.che.api.languageserver.shared.lsapi.DocumentSymbolParamsDTO) PromiseError(org.eclipse.che.api.promises.client.PromiseError) TextDocumentIdentifierDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentIdentifierDTO) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException)

Aggregations

Operation (org.eclipse.che.api.promises.client.Operation)126 OperationException (org.eclipse.che.api.promises.client.OperationException)116 PromiseError (org.eclipse.che.api.promises.client.PromiseError)110 Project (org.eclipse.che.ide.api.resources.Project)51 Resource (org.eclipse.che.ide.api.resources.Resource)45 Promise (org.eclipse.che.api.promises.client.Promise)21 StatusNotification (org.eclipse.che.ide.api.notification.StatusNotification)21 CLIOutputResponse (org.eclipse.che.plugin.svn.shared.CLIOutputResponse)21 List (java.util.List)17 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)16 Path (org.eclipse.che.ide.resource.Path)14 GitOutputConsole (org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputConsole)13 Optional (com.google.common.base.Optional)11 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)10 File (org.eclipse.che.ide.api.resources.File)10 Credentials (org.eclipse.che.ide.api.subversion.Credentials)10 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)9 JsPromiseError (org.eclipse.che.api.promises.client.js.JsPromiseError)8 TestResult (org.eclipse.che.api.testing.shared.TestResult)7