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();
}
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));
}
};
}
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();
}
}
});
}
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();
}
});
}
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);
}
});
}
Aggregations