Search in sources :

Example 66 with OperationException

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

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

the class DebuggerTest method testAttachDebugger.

@Test
public void testAttachDebugger() throws Exception {
    debugger.setDebugSession(null);
    final String debugSessionJson = "debugSession";
    doReturn(debugSessionJson).when(dtoFactory).toJson(debugSessionDto);
    doReturn(mock(StartActionDto.class)).when(dtoFactory).createDto(StartActionDto.class);
    Map<String, String> connectionProperties = mock(Map.class);
    Promise<DebugSessionDto> promiseDebuggerInfo = mock(Promise.class);
    doReturn(promiseDebuggerInfo).when(service).connect("id", connectionProperties);
    doReturn(promiseVoid).when(promiseDebuggerInfo).then((Function<DebugSessionDto, Void>) any());
    doReturn(promiseVoid).when(promiseVoid).catchError((Operation<PromiseError>) any());
    Promise<Void> result = debugger.connect(connectionProperties);
    assertEquals(promiseVoid, result);
    verify(promiseDebuggerInfo).then(argumentCaptorFunctionJavaDebugSessionVoid.capture());
    argumentCaptorFunctionJavaDebugSessionVoid.getValue().apply(debugSessionDto);
    verify(promiseVoid).catchError(operationPromiseErrorCaptor.capture());
    try {
        operationPromiseErrorCaptor.getValue().apply(promiseError);
        fail("Operation Exception expected");
    } catch (OperationException e) {
        verify(promiseError).getMessage();
        verify(promiseError).getCause();
    }
    verify(observer).onDebuggerAttached(debuggerDescriptor, promiseVoid);
    assertTrue(debugger.isConnected());
    verify(localStorage).setItem(eq(AbstractDebugger.LOCAL_STORAGE_DEBUGGER_SESSION_KEY), eq(debugSessionJson));
    verify(messageBus).subscribe(eq("id:events:"), any(SubscriptionHandler.class));
}
Also used : SubscriptionHandler(org.eclipse.che.ide.websocket.rest.SubscriptionHandler) PromiseError(org.eclipse.che.api.promises.client.PromiseError) DebugSessionDto(org.eclipse.che.api.debug.shared.dto.DebugSessionDto) Matchers.anyString(org.mockito.Matchers.anyString) StartActionDto(org.eclipse.che.api.debug.shared.dto.action.StartActionDto) OperationException(org.eclipse.che.api.promises.client.OperationException) BaseTest(org.eclipse.che.plugin.debugger.ide.BaseTest) Test(org.junit.Test)

Example 68 with OperationException

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

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

the class LibEntryPresenter method go.

@Override
public void go(final AcceptsOneWidget container) {
    final Resource resource = appContext.getResource();
    Preconditions.checkState(resource != null);
    final Optional<Project> project = resource.getRelatedProject();
    isPlainJava = JAVAC.equals(project.get().getType());
    setReadOnlyMod();
    container.setWidget(view);
    if (!categories.isEmpty()) {
        view.renderLibraries();
        return;
    }
    classpathContainer.getClasspathEntries(project.get().getPath()).then(new Operation<List<ClasspathEntryDto>>() {

        @Override
        public void apply(List<ClasspathEntryDto> arg) throws OperationException {
            categories.clear();
            for (ClasspathEntryDto entry : arg) {
                if (CONTAINER == entry.getEntryKind() || LIBRARY == entry.getEntryKind()) {
                    categories.put(entry.getPath(), entry);
                }
            }
            view.setData(categories);
            view.renderLibraries();
        }
    });
}
Also used : Project(org.eclipse.che.ide.api.resources.Project) Resource(org.eclipse.che.ide.api.resources.Resource) ClasspathEntryDto(org.eclipse.che.ide.ext.java.shared.dto.classpath.ClasspathEntryDto) List(java.util.List) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 70 with OperationException

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

the class RefactoringUpdater method updateAfterRefactoring.

/**
     * Iterates over each refactoring change and according to change type performs specific update operation.
     * i.e. for {@code ChangeName#UPDATE} updates only opened editors, for {@code ChangeName#MOVE or ChangeName#RENAME_COMPILATION_UNIT}
     * updates only new paths and opened editors, for {@code ChangeName#RENAME_PACKAGE} reloads package structure and restore expansion.
     *
     * @param changes
     *         applied changes
     */
public void updateAfterRefactoring(List<ChangeInfo> changes) {
    if (changes == null || changes.isEmpty()) {
        return;
    }
    ExternalResourceDelta[] deltas = new ExternalResourceDelta[0];
    final List<String> pathChanged = new ArrayList<>();
    for (ChangeInfo change : changes) {
        final ExternalResourceDelta delta;
        final Path newPath = Path.valueOf(change.getPath());
        final Path oldPath = !isNullOrEmpty(change.getOldPath()) ? Path.valueOf(change.getOldPath()) : Path.EMPTY;
        switch(change.getName()) {
            case MOVE:
            case RENAME_COMPILATION_UNIT:
                delta = new ExternalResourceDelta(newPath, oldPath, ADDED | MOVED_FROM | MOVED_TO);
                registerRemovedFile(change);
                break;
            case RENAME_PACKAGE:
                delta = new ExternalResourceDelta(newPath, oldPath, ADDED | MOVED_FROM | MOVED_TO);
                break;
            case UPDATE:
                if (!isFileRemoved(change.getPath(), changes)) {
                    pathChanged.add(change.getPath());
                    registerRemovedFile(change);
                }
            default:
                continue;
        }
        final int index = deltas.length;
        deltas = Arrays.copyOf(deltas, index + 1);
        deltas[index] = delta;
    }
    //here we need to remove file for file that moved or renamed JDT lib sent it to
    for (int i = 0; i < deltas.length; i++) {
        if (pathChanged.contains(deltas[i].getToPath().toString())) {
            pathChanged.remove(deltas[i].getToPath().toString());
        }
        if (pathChanged.contains(deltas[i].getFromPath().toString())) {
            pathChanged.remove(deltas[i].getFromPath().toString());
        }
    }
    if (deltas.length > 0) {
        appContext.getWorkspaceRoot().synchronize(deltas).then(new Operation<ResourceDelta[]>() {

            @Override
            public void apply(final ResourceDelta[] appliedDeltas) throws OperationException {
                for (ResourceDelta delta : appliedDeltas) {
                    eventBus.fireEvent(new RevealResourceEvent(delta.getToPath()));
                }
                for (EditorPartPresenter editorPartPresenter : editorAgent.getOpenedEditors()) {
                    final String path = editorPartPresenter.getEditorInput().getFile().getLocation().toString();
                    if (pathChanged.contains(path)) {
                        eventBus.fireEvent(new FileContentUpdateEvent(editorPartPresenter.getEditorInput().getFile().getLocation().toString()));
                    }
                }
                setActiveEditor();
            }
        });
    } else {
        Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {

            @Override
            public void execute() {
                for (EditorPartPresenter editorPartPresenter : editorAgent.getOpenedEditors()) {
                    eventBus.fireEvent(new FileContentUpdateEvent(editorPartPresenter.getEditorInput().getFile().getLocation().toString()));
                }
                setActiveEditor();
            }
        });
    }
}
Also used : ExternalResourceDelta(org.eclipse.che.ide.api.resources.ExternalResourceDelta) Path(org.eclipse.che.ide.resource.Path) FileContentUpdateEvent(org.eclipse.che.ide.api.event.FileContentUpdateEvent) ChangeInfo(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo) Scheduler(com.google.gwt.core.client.Scheduler) ArrayList(java.util.ArrayList) ExternalResourceDelta(org.eclipse.che.ide.api.resources.ExternalResourceDelta) ResourceDelta(org.eclipse.che.ide.api.resources.ResourceDelta) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) RevealResourceEvent(org.eclipse.che.ide.resources.reveal.RevealResourceEvent) 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