Search in sources :

Example 81 with OperationException

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

the class OpenImplementationPresenter method actionPerformed.

public void actionPerformed(final Member member) {
    if (member.isBinary()) {
        final Resource resource = context.getResource();
        if (resource == null) {
            return;
        }
        final Optional<Project> project = resource.getRelatedProject();
        service.getEntry(project.get().getLocation(), member.getLibId(), member.getRootPath()).then(new Operation<JarEntry>() {

            @Override
            public void apply(final JarEntry entry) throws OperationException {
                service.getContent(project.get().getLocation(), member.getLibId(), Path.valueOf(entry.getPath())).then(new Operation<ClassContent>() {

                    @Override
                    public void apply(ClassContent content) throws OperationException {
                        final String clazz = entry.getName().substring(0, entry.getName().indexOf('.'));
                        final VirtualFile file = new SyntheticFile(entry.getName(), clazz, content.getContent());
                        editorAgent.openEditor(file, new OpenEditorCallbackImpl() {

                            @Override
                            public void onEditorOpened(EditorPartPresenter editor) {
                                setCursor(member.getFileRegion());
                            }
                        });
                    }
                });
            }
        });
    } else {
        context.getWorkspaceRoot().getFile(member.getRootPath()).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(EditorPartPresenter editor) {
                            setCursor(member.getFileRegion());
                        }
                    });
                }
            }
        });
    }
    Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {

        @Override
        public void execute() {
            activeEditor.setFocus();
        }
    });
}
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) Resource(org.eclipse.che.ide.api.resources.Resource) 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) Project(org.eclipse.che.ide.api.resources.Project) SyntheticFile(org.eclipse.che.ide.api.resources.SyntheticFile) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) File(org.eclipse.che.ide.api.resources.File) VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) SyntheticFile(org.eclipse.che.ide.api.resources.SyntheticFile) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 82 with OperationException

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

the class ProjectImporter method authUserAndRecallImport.

private Promise<Project> authUserAndRecallImport(final String providerName, final String authenticateUrl, final Path path, final SourceStorage sourceStorage, final ProjectNotificationSubscriber subscriber) {
    return createFromAsyncRequest(new RequestCall<Project>() {

        @Override
        public void makeCall(final AsyncCallback<Project> callback) {
            OAuth2Authenticator authenticator = oAuth2AuthenticatorRegistry.getAuthenticator(providerName);
            if (authenticator == null) {
                authenticator = oAuth2AuthenticatorRegistry.getAuthenticator("default");
            }
            authenticator.authenticate(OAuth2AuthenticatorUrlProvider.get(appContext.getMasterEndpoint(), authenticateUrl), new AsyncCallback<OAuthStatus>() {

                @Override
                public void onFailure(Throwable caught) {
                    callback.onFailure(new Exception(caught.getMessage()));
                }

                @Override
                public void onSuccess(OAuthStatus result) {
                    if (!result.equals(OAuthStatus.NOT_PERFORMED)) {
                        doImport(path, sourceStorage).then(new Operation<Project>() {

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

                            @Override
                            public void apply(PromiseError error) throws OperationException {
                                callback.onFailure(error.getCause());
                            }
                        });
                    } else {
                        subscriber.onFailure("Authentication cancelled");
                        callback.onFailure(new IllegalStateException("Authentication cancelled"));
                    }
                }
            });
        }
    });
}
Also used : OAuth2Authenticator(org.eclipse.che.ide.api.oauth.OAuth2Authenticator) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) OAuthStatus(org.eclipse.che.security.oauth.OAuthStatus) Operation(org.eclipse.che.api.promises.client.Operation) FunctionException(org.eclipse.che.api.promises.client.FunctionException) OperationException(org.eclipse.che.api.promises.client.OperationException) Project(org.eclipse.che.ide.api.resources.Project) PromiseError(org.eclipse.che.api.promises.client.PromiseError) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 83 with OperationException

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

the class FullTextSearchPresenter method search.

@Override
public void search(final String text) {
    final Path startPoint = isNullOrEmpty(view.getPathToSearch()) ? defaultStartPoint : Path.valueOf(view.getPathToSearch());
    appContext.getWorkspaceRoot().getContainer(startPoint).then(new Operation<Optional<Container>>() {

        @Override
        public void apply(Optional<Container> optionalContainer) throws OperationException {
            if (!optionalContainer.isPresent()) {
                view.showErrorMessage("Path '" + startPoint + "' doesn't exists");
                return;
            }
            final Container container = optionalContainer.get();
            container.search(view.getFileMask(), prepareQuery(text)).then(new Operation<Resource[]>() {

                @Override
                public void apply(Resource[] result) throws OperationException {
                    view.close();
                    findResultPresenter.handleResponse(result, text);
                }
            });
        }
    });
}
Also used : Path(org.eclipse.che.ide.resource.Path) Container(org.eclipse.che.ide.api.resources.Container) Optional(com.google.common.base.Optional) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 84 with OperationException

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

the class PreferencesPresenter method onRefreshClicked.

@Override
public void onRefreshClicked() {
    Promise<Map<String, String>> promise = Promises.resolve(null);
    for (final PreferencesManager preferencesManager : managers) {
        promise = promise.thenPromise(new Function<Map<String, String>, Promise<Map<String, String>>>() {

            @Override
            public Promise<Map<String, String>> apply(Map<String, String> arg) throws FunctionException {
                return preferencesManager.loadPreferences().catchError(new Operation<PromiseError>() {

                    @Override
                    public void apply(PromiseError error) throws OperationException {
                        notificationManagerProvider.get().notify(locale.unableToLoadPreference(), error.getMessage(), FAIL, FLOAT_MODE);
                    }
                });
            }
        });
    }
    /**
         * Revert changes on every preference page
         */
    promise.then(new Operation<Map<String, String>>() {

        @Override
        public void apply(Map<String, String> arg) throws OperationException {
            for (PreferencePagePresenter p : PreferencesPresenter.this.preferences) {
                p.revertChanges();
            }
        }
    });
}
Also used : Function(org.eclipse.che.api.promises.client.Function) PromiseError(org.eclipse.che.api.promises.client.PromiseError) PreferencePagePresenter(org.eclipse.che.ide.api.preferences.PreferencePagePresenter) HashMap(java.util.HashMap) Map(java.util.Map) PreferencesManager(org.eclipse.che.ide.api.preferences.PreferencesManager) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 85 with OperationException

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

the class PreferencesPresenter method onSaveClicked.

@Override
public void onSaveClicked() {
    for (PreferencePagePresenter preference : preferences) {
        if (preference.isDirty()) {
            preference.storeChanges();
        }
    }
    Promise<Void> promise = Promises.resolve(null);
    final List<PromiseError> promiseErrorList = new ArrayList<>();
    for (final PreferencesManager preferencesManager : managers) {
        promise = promise.thenPromise(new Function<Void, Promise<Void>>() {

            @Override
            public Promise<Void> apply(Void arg) throws FunctionException {
                return preferencesManager.flushPreferences().catchError(new Operation<PromiseError>() {

                    @Override
                    public void apply(PromiseError error) throws OperationException {
                        notificationManagerProvider.get().notify(locale.unableToSavePreference(), error.getMessage(), FAIL, FLOAT_MODE);
                        promiseErrorList.add(error);
                    }
                });
            }
        });
    }
    promise.then(new Operation<Void>() {

        @Override
        public void apply(Void aVoid) throws OperationException {
            if (promiseErrorList.isEmpty()) {
                view.enableSaveButton(false);
            }
        }
    });
}
Also used : Function(org.eclipse.che.api.promises.client.Function) PreferencePagePresenter(org.eclipse.che.ide.api.preferences.PreferencePagePresenter) PromiseError(org.eclipse.che.api.promises.client.PromiseError) ArrayList(java.util.ArrayList) PreferencesManager(org.eclipse.che.ide.api.preferences.PreferencesManager) OperationException(org.eclipse.che.api.promises.client.OperationException)

Aggregations

OperationException (org.eclipse.che.api.promises.client.OperationException)158 PromiseError (org.eclipse.che.api.promises.client.PromiseError)123 Operation (org.eclipse.che.api.promises.client.Operation)115 Project (org.eclipse.che.ide.api.resources.Project)53 Resource (org.eclipse.che.ide.api.resources.Resource)48 StatusNotification (org.eclipse.che.ide.api.notification.StatusNotification)21 CLIOutputResponse (org.eclipse.che.plugin.svn.shared.CLIOutputResponse)21 List (java.util.List)19 Promise (org.eclipse.che.api.promises.client.Promise)17 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)15 Path (org.eclipse.che.ide.resource.Path)15 JsPromiseError (org.eclipse.che.api.promises.client.js.JsPromiseError)14 ArrayList (java.util.ArrayList)13 GitOutputConsole (org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputConsole)13 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)12 DebuggerObserver (org.eclipse.che.ide.debug.DebuggerObserver)11 Optional (com.google.common.base.Optional)10 HashMap (java.util.HashMap)10 File (org.eclipse.che.ide.api.resources.File)10 Credentials (org.eclipse.che.ide.api.subversion.Credentials)10