Search in sources :

Example 66 with Operation

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

the class EditCommandsPresenter method onRemoveClicked.

@Override
public void onRemoveClicked() {
    final CommandImpl selectedCommand = view.getSelectedCommand();
    if (selectedCommand == null) {
        return;
    }
    final ConfirmCallback confirmCallback = new ConfirmCallback() {

        @Override
        public void accepted() {
            commandManager.remove(selectedCommand.getName()).then(new Operation<Void>() {

                @Override
                public void apply(Void arg) throws OperationException {
                    view.selectNeighborCommand(selectedCommand);
                    commandProcessingCallback = getCommandProcessingCallback();
                    refreshView();
                }
            }).catchError(new Operation<PromiseError>() {

                @Override
                public void apply(PromiseError arg) throws OperationException {
                    dialogFactory.createMessageDialog("Error", arg.getMessage(), null).show();
                }
            });
        }
    };
    ConfirmDialog confirmDialog = dialogFactory.createConfirmDialog(machineLocale.editCommandsViewRemoveTitle(), machineLocale.editCommandsRemoveConfirmation(selectedCommand.getName()), confirmCallback, null);
    confirmDialog.show();
}
Also used : CommandImpl(org.eclipse.che.ide.api.command.CommandImpl) ConfirmCallback(org.eclipse.che.ide.api.dialogs.ConfirmCallback) PromiseError(org.eclipse.che.api.promises.client.PromiseError) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException) ConfirmDialog(org.eclipse.che.ide.api.dialogs.ConfirmDialog)

Example 67 with Operation

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

the class CommandOutputConsolePresenter method getProcessDiedOperation.

@Override
public Operation<ProcessDiedEventDto> getProcessDiedOperation() {
    return new Operation<ProcessDiedEventDto>() {

        @Override
        public void apply(ProcessDiedEventDto event) throws OperationException {
            finished = true;
            view.enableStopButton(false);
            view.toggleScrollToEndButton(false);
            eventBus.fireEvent(new ProcessFinishedEvent(pid));
        }
    };
}
Also used : ProcessFinishedEvent(org.eclipse.che.ide.extension.machine.client.processes.ProcessFinishedEvent) Operation(org.eclipse.che.api.promises.client.Operation) ProcessDiedEventDto(org.eclipse.che.api.machine.shared.dto.execagent.event.ProcessDiedEventDto)

Example 68 with Operation

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

the class TerminalPresenter method connectToTerminalWebSocket.

private void connectToTerminalWebSocket(@NotNull String wsUrl) {
    countRetry--;
    socket = WebSocket.create(wsUrl);
    socket.setOnMessageHandler(new MessageReceivedHandler() {

        @Override
        public void onMessageReceived(MessageReceivedEvent event) {
            terminal.write(event.getMessage());
        }
    });
    socket.setOnCloseHandler(new ConnectionClosedHandler() {

        @Override
        public void onClose(WebSocketClosedEvent event) {
            if (CLOSE_NORMAL == event.getCode()) {
                connected = false;
                terminalStateListener.onExit();
            }
        }
    });
    socket.setOnOpenHandler(new ConnectionOpenedHandler() {

        @Override
        public void onOpen() {
            JavaScriptObject terminalJso = moduleHolder.getModule("Xterm");
            // if terminal was created programmatically then we don't set focus on it
            TerminalOptionsJso terminalOptionsJso = TerminalOptionsJso.createDefault();
            if (source instanceof AddTerminalClickHandler || source instanceof Action) {
                terminalOptionsJso.withFocusOnOpen(true);
            }
            terminal = TerminalJso.create(terminalJso, terminalOptionsJso);
            connected = true;
            view.openTerminal(terminal);
            terminal.on(DATA_EVENT_NAME, new Operation<String>() {

                @Override
                public void apply(String arg) throws OperationException {
                    Jso jso = Jso.create();
                    jso.addField("type", "data");
                    jso.addField("data", arg);
                    socket.send(jso.serialize());
                }
            });
        }
    });
    socket.setOnErrorHandler(new ConnectionErrorHandler() {

        @Override
        public void onError() {
            connected = false;
            if (countRetry == 0) {
                view.showErrorMessage(locale.terminalErrorStart());
                notificationManager.notify(locale.connectionFailedWithTerminal(), locale.terminalErrorConnection(), FAIL, FLOAT_MODE);
            } else {
                reconnect();
            }
        }
    });
}
Also used : ConnectionOpenedHandler(org.eclipse.che.ide.websocket.events.ConnectionOpenedHandler) Action(org.eclipse.che.ide.api.action.Action) ConnectionErrorHandler(org.eclipse.che.ide.websocket.events.ConnectionErrorHandler) MessageReceivedHandler(org.eclipse.che.ide.websocket.events.MessageReceivedHandler) Jso(org.eclipse.che.ide.collections.Jso) Operation(org.eclipse.che.api.promises.client.Operation) MessageReceivedEvent(org.eclipse.che.ide.websocket.events.MessageReceivedEvent) WebSocketClosedEvent(org.eclipse.che.ide.websocket.events.WebSocketClosedEvent) AddTerminalClickHandler(org.eclipse.che.ide.extension.machine.client.processes.AddTerminalClickHandler) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) ConnectionClosedHandler(org.eclipse.che.ide.websocket.events.ConnectionClosedHandler)

Example 69 with Operation

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

the class NewFolderAction method createFolder.

final void createFolder(String name) {
    Resource resource = appContext.getResource();
    if (!(resource instanceof Container)) {
        final Container parent = resource.getParent();
        checkState(parent != null, "Parent should be a container");
        resource = parent;
    }
    ((Container) resource).newFolder(name).then(new Operation<Folder>() {

        @Override
        public void apply(Folder folder) throws OperationException {
            eventBus.fireEvent(new RevealResourceEvent(folder));
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            dialogFactory.createMessageDialog("Error", error.getMessage(), null).show();
        }
    });
}
Also used : Container(org.eclipse.che.ide.api.resources.Container) PromiseError(org.eclipse.che.api.promises.client.PromiseError) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) Folder(org.eclipse.che.ide.api.resources.Folder) RevealResourceEvent(org.eclipse.che.ide.resources.reveal.RevealResourceEvent) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 70 with Operation

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

the class CopyPresenter method onCopyClicked.

/** {@inheritDoc} */
@Override
public void onCopyClicked() {
    final Project project = appContext.getRootProject();
    Preconditions.checkState(project != null);
    final Path src = view.isSourceCheckBoxSelected() ? Path.valueOf(view.getSourcePath()) : toRelative(project, sourceNode);
    final Path target = view.isTargetCheckBoxSelected() ? Path.valueOf(view.getTargetUrl()) : toRelative(project, this.target);
    final String comment = view.isTargetCheckBoxSelected() ? view.getComment() : null;
    final StatusNotification notification = new StatusNotification(constants.copyNotificationStarted(src.toString()), PROGRESS, FLOAT_MODE);
    notificationManager.notify(notification);
    view.hide();
    performOperationWithCredentialsRequestIfNeeded(new RemoteSubversionOperation<CLIOutputResponse>() {

        @Override
        public Promise<CLIOutputResponse> perform(Credentials credentials) {
            notification.setStatus(PROGRESS);
            notification.setTitle(constants.copyNotificationStarted(src.toString()));
            return service.copy(project.getLocation(), src, target, comment, credentials);
        }
    }, notification).then(new Operation<CLIOutputResponse>() {

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

        @Override
        public void apply(PromiseError error) throws OperationException {
            notification.setTitle(constants.copyNotificationFailed());
            notification.setStatus(FAIL);
        }
    });
}
Also used : Path(org.eclipse.che.ide.resource.Path) StatusNotification(org.eclipse.che.ide.api.notification.StatusNotification) Operation(org.eclipse.che.api.promises.client.Operation) Project(org.eclipse.che.ide.api.resources.Project) Promise(org.eclipse.che.api.promises.client.Promise) PromiseError(org.eclipse.che.api.promises.client.PromiseError) CLIOutputResponse(org.eclipse.che.plugin.svn.shared.CLIOutputResponse) Credentials(org.eclipse.che.ide.api.subversion.Credentials) 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