Search in sources :

Example 6 with Operation

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

the class ParametersHintsPresenter method show.

/**
     * The method gets method parameters via {@link JavaNavigationService} and then call special method on view to display them.
     *
     * @param activeEditor
     *         active editor which contains method or constructor for which parameters will be displayed
     */
public void show(final TextEditor activeEditor) {
    final int offset = activeEditor.getCursorOffset();
    if (!isCursorInRightPlace(activeEditor, offset)) {
        return;
    }
    VirtualFile file = activeEditor.getEditorInput().getFile();
    if (file instanceof Resource) {
        final Optional<Project> project = ((Resource) file).getRelatedProject();
        final int lineStartOffset = getLineStartOffset(activeEditor, offset);
        navigationService.getMethodParametersHints(project.get().getLocation(), JavaUtil.resolveFQN(file), offset, lineStartOffset).then(new Operation<List<MethodParameters>>() {

            @Override
            public void apply(List<MethodParameters> parameters) throws OperationException {
                if (parameters.isEmpty()) {
                    return;
                }
                PositionConverter.PixelCoordinates coordinates = activeEditor.getPositionConverter().offsetToPixel(offset);
                view.show(parameters, coordinates.getX(), coordinates.getY());
            }
        }).catchError(new Operation<PromiseError>() {

            @Override
            public void apply(PromiseError error) throws OperationException {
                Log.error(getClass(), error.getMessage());
            }
        });
    }
}
Also used : VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) Project(org.eclipse.che.ide.api.resources.Project) PromiseError(org.eclipse.che.api.promises.client.PromiseError) List(java.util.List) MethodParameters(org.eclipse.che.ide.ext.java.shared.dto.model.MethodParameters) PositionConverter(org.eclipse.che.ide.api.editor.position.PositionConverter) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 7 with Operation

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

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

the class MavenMessagesHandler method handleOperations.

private void handleOperations(final DtoFactory factory, final WsAgentStateController wsAgentStateController) {
    eventBus.addHandler(WsAgentStateEvent.TYPE, new WsAgentStateHandler() {

        @Override
        public void onWsAgentStarted(WsAgentStateEvent event) {
            wsAgentStateController.getMessageBus().then(new Operation<MessageBus>() {

                @Override
                public void apply(MessageBus messageBus) throws OperationException {
                    try {
                        handleMavenServerEvents(messageBus);
                        handleMavenArchetype(messageBus);
                    } catch (WebSocketException e) {
                        dependencyResolver.hide();
                        Log.error(getClass(), e);
                    }
                }
            });
        }

        @Override
        public void onWsAgentStopped(WsAgentStateEvent event) {
            dependencyResolver.hide();
        }
    });
    eventBus.addHandler(WorkspaceStoppedEvent.TYPE, new WorkspaceStoppedEvent.Handler() {

        @Override
        public void onWorkspaceStopped(WorkspaceStoppedEvent event) {
            dependencyResolver.hide();
        }
    });
}
Also used : MessageBus(org.eclipse.che.ide.websocket.MessageBus) WebSocketException(org.eclipse.che.ide.websocket.WebSocketException) WsAgentStateHandler(org.eclipse.che.ide.api.machine.events.WsAgentStateHandler) Operation(org.eclipse.che.api.promises.client.Operation) WsAgentStateEvent(org.eclipse.che.ide.api.machine.events.WsAgentStateEvent) WorkspaceStoppedEvent(org.eclipse.che.ide.api.workspace.event.WorkspaceStoppedEvent)

Example 9 with Operation

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

the class ProcessesPanelPresenterTest method setUp.

@Before
public void setUp() {
    DevMachine devMachine = mock(DevMachine.class);
    when(devMachine.getId()).thenReturn(WORKSPACE_ID);
    when(appContext.getDevMachine()).thenReturn(devMachine);
    when(appContext.getWorkspace()).thenReturn(workspace);
    when(workspace.getRuntime()).thenReturn(workspaceRuntime);
    when(processesPromise.then(Matchers.<Operation<List<MachineProcessDto>>>anyObject())).thenReturn(processesPromise);
    when(commandConsoleFactory.create(anyString())).thenReturn(mock(OutputConsole.class));
    when(appContext.getWorkspaceId()).thenReturn(WORKSPACE_ID);
    when(workspaceAgent.getPartStack(eq(PartStackType.INFORMATION))).thenReturn(partStack);
    when(execAgentCommandManager.getProcesses(anyString(), anyBoolean())).thenReturn(promise);
    when(promise.then(any(Operation.class))).thenReturn(promise);
    presenter = new ProcessesPanelPresenter(view, localizationConstant, resources, eventBus, workspaceAgent, appContext, notificationManager, entityFactory, terminalFactory, commandConsoleFactory, dialogFactory, consoleTreeContextMenuFactory, commandTypeRegistry, sshService, execAgentCommandManager, macroProcessor, dtoFactory);
}
Also used : DevMachine(org.eclipse.che.ide.api.machine.DevMachine) CommandOutputConsole(org.eclipse.che.ide.extension.machine.client.outputspanel.console.CommandOutputConsole) OutputConsole(org.eclipse.che.ide.api.outputconsole.OutputConsole) List(java.util.List) ArrayList(java.util.ArrayList) Operation(org.eclipse.che.api.promises.client.Operation) Before(org.junit.Before)

Example 10 with Operation

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

the class AbstractDebugger method deleteBreakpoint.

@Override
public void deleteBreakpoint(final VirtualFile file, final int lineNumber) {
    if (!isConnected()) {
        return;
    }
    LocationDto locationDto = dtoFactory.createDto(LocationDto.class);
    locationDto.setLineNumber(lineNumber + 1);
    String fqn = pathToFqn(file);
    if (fqn == null) {
        return;
    }
    locationDto.setTarget(fqn);
    Promise<Void> promise = service.deleteBreakpoint(debugSessionDto.getId(), locationDto);
    promise.then(new Operation<Void>() {

        @Override
        public void apply(Void arg) throws OperationException {
            for (DebuggerObserver observer : observers) {
                Breakpoint breakpoint = new Breakpoint(Breakpoint.Type.BREAKPOINT, lineNumber, file.getLocation().toString(), file, false);
                observer.onBreakpointDeleted(breakpoint);
            }
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError arg) throws OperationException {
            Log.error(AbstractDebugger.class, arg.getMessage());
        }
    });
}
Also used : Breakpoint(org.eclipse.che.ide.api.debug.Breakpoint) JsPromiseError(org.eclipse.che.api.promises.client.js.JsPromiseError) PromiseError(org.eclipse.che.api.promises.client.PromiseError) Operation(org.eclipse.che.api.promises.client.Operation) DebuggerObserver(org.eclipse.che.ide.debug.DebuggerObserver) LocationDto(org.eclipse.che.api.debug.shared.dto.LocationDto) 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