Search in sources :

Example 11 with FunctionException

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

the class ProjectResolver method resolve.

public Promise<Project> resolve(final Project project) {
    return project.resolve().thenPromise(new Function<List<SourceEstimation>, Promise<Project>>() {

        @Override
        public Promise<Project> apply(List<SourceEstimation> estimations) throws FunctionException {
            if (estimations == null || estimations.isEmpty()) {
                return promiseProvider.resolve(project);
            }
            final List<String> primeTypes = newArrayList();
            for (SourceEstimation estimation : estimations) {
                if (projectTypeRegistry.getProjectType(estimation.getType()).isPrimaryable()) {
                    primeTypes.add(estimation.getType());
                }
            }
            final MutableProjectConfig config = new MutableProjectConfig(project);
            final SourceStorage source = project.getSource();
            if (source != null && source.getParameters() != null && source.getParameters().containsKey("keepDir")) {
                config.setType(Constants.BLANK_ID);
            } else if (primeTypes.isEmpty()) {
                return promiseProvider.resolve(project);
            } else if (primeTypes.size() == 1) {
                config.setType(primeTypes.get(0));
            } else {
                config.setType(Constants.BLANK_ID);
                projectWizard.show(config);
                return promiseProvider.resolve(project);
            }
            return project.update().withBody(config).send();
        }
    }).catchErrorPromise(new Function<PromiseError, Promise<Project>>() {

        @Override
        public Promise<Project> apply(PromiseError error) throws FunctionException {
            Log.warn(ProjectResolver.class, error.getMessage());
            return promiseProvider.resolve(project);
        }
    });
}
Also used : MutableProjectConfig(org.eclipse.che.ide.api.project.MutableProjectConfig) FunctionException(org.eclipse.che.api.promises.client.FunctionException) Function(org.eclipse.che.api.promises.client.Function) Project(org.eclipse.che.ide.api.resources.Project) Promise(org.eclipse.che.api.promises.client.Promise) SourceStorage(org.eclipse.che.api.core.model.project.SourceStorage) PromiseError(org.eclipse.che.api.promises.client.PromiseError) SourceEstimation(org.eclipse.che.api.project.shared.dto.SourceEstimation) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList)

Example 12 with FunctionException

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

the class CopyPasteManager method moveResource.

private Promise<Void> moveResource(final Resource resource, final Path destination) {
    //simple move without overwriting
    return resource.move(destination).thenPromise(new Function<Resource, Promise<Void>>() {

        @Override
        public Promise<Void> apply(Resource resource) throws FunctionException {
            eventBus.fireEvent(new RevealResourceEvent(resource));
            return promises.resolve(null);
        }
    }).catchErrorPromise(new Function<PromiseError, Promise<Void>>() {

        @Override
        public Promise<Void> apply(final PromiseError error) throws FunctionException {
            //resource may already exists
            if (error.getMessage().contains("exists")) {
                //create dialog with overwriting option
                return createFromAsyncRequest(new RequestCall<Void>() {

                    @Override
                    public void makeCall(final AsyncCallback<Void> callback) {
                        //handle overwrite operation
                        final ConfirmCallback overwrite = new ConfirmCallback() {

                            @Override
                            public void accepted() {
                                //copy with overwriting
                                resource.move(destination, true).then(new Operation<Resource>() {

                                    @Override
                                    public void apply(Resource ignored) throws OperationException {
                                        callback.onSuccess(null);
                                    }
                                }).catchError(new Operation<PromiseError>() {

                                    @Override
                                    public void apply(PromiseError error) throws OperationException {
                                        callback.onFailure(error.getCause());
                                    }
                                });
                            }
                        };
                        //skip this resource
                        final ConfirmCallback skip = new ConfirmCallback() {

                            @Override
                            public void accepted() {
                                callback.onSuccess(null);
                            }
                        };
                        //change destination name
                        final ConfirmCallback rename = new ConfirmCallback() {

                            @Override
                            public void accepted() {
                                dialogFactory.createInputDialog("Enter new name", "Enter new name", new InputCallback() {

                                    @Override
                                    public void accepted(String value) {
                                        final Path newPath = destination.parent().append(value);
                                        moveResource(resource, newPath).then(new Operation<Void>() {

                                            @Override
                                            public void apply(Void result) throws OperationException {
                                                callback.onSuccess(result);
                                            }
                                        }).catchError(new Operation<PromiseError>() {

                                            @Override
                                            public void apply(PromiseError error) throws OperationException {
                                                callback.onFailure(error.getCause());
                                            }
                                        });
                                    }
                                }, new CancelCallback() {

                                    @Override
                                    public void cancelled() {
                                    }
                                }).show();
                            }
                        };
                        dialogFactory.createChoiceDialog("Error", error.getMessage(), "Overwrite", "Skip", "Change Name", overwrite, skip, rename).show();
                    }
                });
            } else {
                //notify user about failed copying
                notificationManager.notify("Error moving resource", error.getMessage(), FAIL, FLOAT_MODE);
                return promises.resolve(null);
            }
        }
    });
}
Also used : Path(org.eclipse.che.ide.resource.Path) ConfirmCallback(org.eclipse.che.ide.api.dialogs.ConfirmCallback) RequestCall(org.eclipse.che.api.promises.client.callback.AsyncPromiseHelper.RequestCall) InputCallback(org.eclipse.che.ide.api.dialogs.InputCallback) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) Resource(org.eclipse.che.ide.api.resources.Resource) FunctionException(org.eclipse.che.api.promises.client.FunctionException) Operation(org.eclipse.che.api.promises.client.Operation) Function(org.eclipse.che.api.promises.client.Function) Promise(org.eclipse.che.api.promises.client.Promise) PromiseError(org.eclipse.che.api.promises.client.PromiseError) CancelCallback(org.eclipse.che.ide.api.dialogs.CancelCallback) RevealResourceEvent(org.eclipse.che.ide.resources.reveal.RevealResourceEvent) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 13 with FunctionException

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

the class CopyPasteManager method copyResource.

private Promise<Void> copyResource(final Resource resource, final Path destination) {
    //simple copy without overwriting
    return resource.copy(destination).thenPromise(new Function<Resource, Promise<Void>>() {

        @Override
        public Promise<Void> apply(Resource resource) throws FunctionException {
            eventBus.fireEvent(new RevealResourceEvent(resource));
            return promises.resolve(null);
        }
    }).catchErrorPromise(new Function<PromiseError, Promise<Void>>() {

        @Override
        public Promise<Void> apply(final PromiseError error) throws FunctionException {
            //resource may already exists
            if (error.getMessage().contains("exists")) {
                //create dialog with overwriting option
                return createFromAsyncRequest(new RequestCall<Void>() {

                    @Override
                    public void makeCall(final AsyncCallback<Void> callback) {
                        //handle overwrite operation
                        final ConfirmCallback overwrite = new ConfirmCallback() {

                            @Override
                            public void accepted() {
                                //copy with overwriting
                                resource.copy(destination, true).then(new Operation<Resource>() {

                                    @Override
                                    public void apply(Resource ignored) throws OperationException {
                                        callback.onSuccess(null);
                                    }
                                }).catchError(new Operation<PromiseError>() {

                                    @Override
                                    public void apply(PromiseError error) throws OperationException {
                                        callback.onFailure(error.getCause());
                                    }
                                });
                            }
                        };
                        //skip this resource
                        final ConfirmCallback skip = new ConfirmCallback() {

                            @Override
                            public void accepted() {
                                callback.onSuccess(null);
                            }
                        };
                        //change destination name
                        final ConfirmCallback rename = new ConfirmCallback() {

                            @Override
                            public void accepted() {
                                dialogFactory.createInputDialog("Enter new name", "Enter new name", new InputCallback() {

                                    @Override
                                    public void accepted(String value) {
                                        final Path newPath = destination.parent().append(value);
                                        copyResource(resource, newPath).then(new Operation<Void>() {

                                            @Override
                                            public void apply(Void result) throws OperationException {
                                                callback.onSuccess(result);
                                            }
                                        }).catchError(new Operation<PromiseError>() {

                                            @Override
                                            public void apply(PromiseError error) throws OperationException {
                                                callback.onFailure(error.getCause());
                                            }
                                        });
                                    }
                                }, new CancelCallback() {

                                    @Override
                                    public void cancelled() {
                                    }
                                }).show();
                            }
                        };
                        dialogFactory.createChoiceDialog("Error", error.getMessage(), "Overwrite", "Skip", "Change Name", overwrite, skip, rename).show();
                    }
                });
            } else {
                //notify user about failed copying
                notificationManager.notify("Error copying resource", error.getMessage(), FAIL, FLOAT_MODE);
                return promises.resolve(null);
            }
        }
    });
}
Also used : Path(org.eclipse.che.ide.resource.Path) ConfirmCallback(org.eclipse.che.ide.api.dialogs.ConfirmCallback) RequestCall(org.eclipse.che.api.promises.client.callback.AsyncPromiseHelper.RequestCall) InputCallback(org.eclipse.che.ide.api.dialogs.InputCallback) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) Resource(org.eclipse.che.ide.api.resources.Resource) FunctionException(org.eclipse.che.api.promises.client.FunctionException) Operation(org.eclipse.che.api.promises.client.Operation) Function(org.eclipse.che.api.promises.client.Function) Promise(org.eclipse.che.api.promises.client.Promise) PromiseError(org.eclipse.che.api.promises.client.PromiseError) CancelCallback(org.eclipse.che.ide.api.dialogs.CancelCallback) RevealResourceEvent(org.eclipse.che.ide.resources.reveal.RevealResourceEvent) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 14 with FunctionException

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

the class LanguageServerSignatureHelp method signatureHelp.

@Override
public Promise<Optional<SignatureHelp>> signatureHelp(Document document, int offset) {
    TextDocumentPositionParamsDTO paramsDTO = helper.createTDPP(document, offset);
    Promise<SignatureHelpDTO> promise = client.signatureHelp(paramsDTO);
    return promise.then(new Function<SignatureHelpDTO, Optional<SignatureHelp>>() {

        @Override
        public Optional<SignatureHelp> apply(SignatureHelpDTO arg) throws FunctionException {
            if (arg == null) {
                return Optional.absent();
            }
            return Optional.<SignatureHelp>of(new SignatureHelpImpl(arg));
        }
    }).catchError(new Function<PromiseError, Optional<SignatureHelp>>() {

        @Override
        public Optional<SignatureHelp> apply(PromiseError arg) throws FunctionException {
            notificationManager.notify(arg.getMessage(), StatusNotification.Status.FAIL, StatusNotification.DisplayMode.EMERGE_MODE);
            return Optional.absent();
        }
    });
}
Also used : TextDocumentPositionParamsDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO) Function(org.eclipse.che.api.promises.client.Function) PromiseError(org.eclipse.che.api.promises.client.PromiseError) Optional(com.google.common.base.Optional) SignatureHelpDTO(org.eclipse.che.api.languageserver.shared.lsapi.SignatureHelpDTO) FunctionException(org.eclipse.che.api.promises.client.FunctionException) SignatureHelp(org.eclipse.che.ide.api.editor.signature.SignatureHelp)

Example 15 with FunctionException

use of org.eclipse.che.api.promises.client.FunctionException 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

FunctionException (org.eclipse.che.api.promises.client.FunctionException)24 Promise (org.eclipse.che.api.promises.client.Promise)15 Resource (org.eclipse.che.ide.api.resources.Resource)12 Function (org.eclipse.che.api.promises.client.Function)11 Optional (com.google.common.base.Optional)9 Project (org.eclipse.che.ide.api.resources.Project)8 List (java.util.List)7 PromiseError (org.eclipse.che.api.promises.client.PromiseError)7 Path (org.eclipse.che.ide.resource.Path)6 Operation (org.eclipse.che.api.promises.client.Operation)5 ResourceChangedEvent (org.eclipse.che.ide.api.resources.ResourceChangedEvent)5 ArrayList (java.util.ArrayList)4 NewProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto)4 ProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto)4 MutableProjectConfig (org.eclipse.che.ide.api.project.MutableProjectConfig)4 SourceStorage (org.eclipse.che.api.core.model.project.SourceStorage)3 TextDocumentPositionParamsDTO (org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO)3 OperationException (org.eclipse.che.api.promises.client.OperationException)3 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)2 Set (java.util.Set)2