Search in sources :

Example 31 with Operation

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

the class PropertyEditorPresenter method editProperty.

private void editProperty(Project project) {
    final String propertyName = view.getSelectedProperty();
    final Depth depth = view.getDepth();
    final String propertyValue = view.getPropertyValue();
    final boolean force = view.isForceSelected();
    final Resource[] resources = appContext.getResources();
    checkState(!Arrays.isNullOrEmpty(resources));
    checkState(resources.length == 1);
    final StatusNotification notification = new StatusNotification(constants.propertyModifyStart(), PROGRESS, FLOAT_MODE);
    notificationManager.notify(notification);
    service.propertySet(project.getLocation(), propertyName, propertyValue, depth, force, toRelative(project, resources[0])).then(new Operation<CLIOutputResponse>() {

        @Override
        public void apply(CLIOutputResponse response) throws OperationException {
            printResponse(response.getCommand(), response.getOutput(), response.getErrOutput(), constants.commandProperty());
            notification.setTitle(constants.propertyModifyFinished());
            notification.setStatus(SUCCESS);
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            notification.setTitle(constants.propertyModifyFailed());
            notification.setStatus(FAIL);
        }
    });
}
Also used : PromiseError(org.eclipse.che.api.promises.client.PromiseError) Resource(org.eclipse.che.ide.api.resources.Resource) StatusNotification(org.eclipse.che.ide.api.notification.StatusNotification) Operation(org.eclipse.che.api.promises.client.Operation) CLIOutputResponse(org.eclipse.che.plugin.svn.shared.CLIOutputResponse) Depth(org.eclipse.che.plugin.svn.shared.Depth) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 32 with Operation

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

the class DeleteResourceManager method onConfirm.

private ConfirmCallback onConfirm(final Resource[] resources, final AsyncCallback<Void> callback) {
    return new ConfirmCallback() {

        @Override
        public void accepted() {
            if (resources == null) {
                //sometimes we may occur NPE here while reading length
                callback.onFailure(new IllegalStateException());
                return;
            }
            Promise<?>[] deleteAll = new Promise<?>[resources.length];
            for (int i = 0; i < resources.length; i++) {
                final Resource resource = resources[i];
                deleteAll[i] = resource.delete().catchError(new Operation<PromiseError>() {

                    @Override
                    public void apply(PromiseError error) throws OperationException {
                        notificationManager.notify("Failed to delete '" + resource.getName() + "'", error.getMessage(), FAIL, StatusNotification.DisplayMode.FLOAT_MODE);
                    }
                });
            }
            promiseProvider.all(deleteAll).then(new Operation<JsArrayMixed>() {

                @Override
                public void apply(JsArrayMixed arg) throws OperationException {
                    callback.onSuccess(null);
                }
            });
        }
    };
}
Also used : Promise(org.eclipse.che.api.promises.client.Promise) ConfirmCallback(org.eclipse.che.ide.api.dialogs.ConfirmCallback) JsPromiseError(org.eclipse.che.api.promises.client.js.JsPromiseError) PromiseError(org.eclipse.che.api.promises.client.PromiseError) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) JsArrayMixed(com.google.gwt.core.client.JsArrayMixed) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 33 with Operation

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

the class EvaluateExpressionPresenter method onEvaluateClicked.

/** {@inheritDoc} */
@Override
public void onEvaluateClicked() {
    Debugger debugger = debuggerManager.getActiveDebugger();
    if (debugger != null) {
        view.setEnableEvaluateButton(false);
        debugger.evaluate(view.getExpression()).then(new Operation<String>() {

            @Override
            public void apply(String result) throws OperationException {
                view.setResult(result);
                view.setEnableEvaluateButton(true);
            }
        }).catchError(new Operation<PromiseError>() {

            @Override
            public void apply(PromiseError error) throws OperationException {
                view.setResult(constant.evaluateExpressionFailed(error.getMessage()));
                view.setEnableEvaluateButton(true);
            }
        });
    }
}
Also used : Debugger(org.eclipse.che.ide.debug.Debugger) PromiseError(org.eclipse.che.api.promises.client.PromiseError) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 34 with Operation

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

the class MovePresenter method show.

/**
     * Show Move panel with the special information.
     *
     * @param refactorInfo
     *         information about the move operation
     */
public void show(final RefactorInfo refactorInfo) {
    this.refactorInfo = refactorInfo;
    view.setEnablePreviewButton(false);
    view.setEnableAcceptButton(false);
    view.clearErrorLabel();
    CreateMoveRefactoring moveRefactoring = createMoveDto();
    Promise<String> sessionIdPromise = refactorService.createMoveRefactoring(moveRefactoring);
    sessionIdPromise.then(new Operation<String>() {

        @Override
        public void apply(String sessionId) throws OperationException {
            MovePresenter.this.refactoringSessionId = sessionId;
            showProjectsAndPackages();
        }
    }).catchError(new Operation<PromiseError>() {

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

Example 35 with Operation

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

the class MovePresenter method onPreviewButtonClicked.

/** {@inheritDoc} */
@Override
public void onPreviewButtonClicked() {
    RefactoringSession session = dtoFactory.createDto(RefactoringSession.class);
    session.setSessionId(refactoringSessionId);
    prepareMovingChanges(session).then(new Operation<ChangeCreationResult>() {

        @Override
        public void apply(ChangeCreationResult arg) throws OperationException {
            if (arg.isCanShowPreviewPage()) {
                previewPresenter.show(refactoringSessionId, refactorInfo);
                view.hide();
            } else {
                view.showStatusMessage(arg.getStatus());
            }
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            notificationManager.notify(locale.showPreviewError(), error.getMessage(), Status.FAIL, FLOAT_MODE);
        }
    });
}
Also used : PromiseError(org.eclipse.che.api.promises.client.PromiseError) RefactoringSession(org.eclipse.che.ide.ext.java.shared.dto.refactoring.RefactoringSession) ChangeCreationResult(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeCreationResult) 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