use of org.eclipse.che.api.promises.client.OperationException in project che by eclipse.
the class DebugConfigurationsManagerImpl method apply.
@Override
public void apply(final DebugConfiguration debugConfiguration) {
if (debugConfiguration == null) {
return;
}
if (debuggerManager.getActiveDebugger() != null) {
dialogFactory.createMessageDialog(localizationConstants.connectToRemote(), localizationConstants.debuggerAlreadyConnected(), null).show();
return;
}
final Debugger debugger = debuggerManager.getDebugger(debugConfiguration.getType().getId());
if (debugger != null) {
debuggerManager.setActiveDebugger(debugger);
currentProjectPathMacro.expand().then(new Operation<String>() {
@Override
public void apply(String arg) throws OperationException {
Map<String, String> connectionProperties = prepareConnectionProperties(debugConfiguration, arg);
debugger.connect(connectionProperties).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
debuggerManager.setActiveDebugger(null);
}
});
}
});
}
}
use of org.eclipse.che.api.promises.client.OperationException in project che by eclipse.
the class JavaDebuggerFileHandler method openExternalResource.
private void openExternalResource(final Location location, final AsyncCallback<VirtualFile> callback) {
final String className = extractOuterClassFqn(location.getTarget());
final int libId = location.getExternalResourceId();
final Path projectPath = new Path(location.getResourceProjectPath());
service.getEntry(projectPath, libId, className).then(new Operation<JarEntry>() {
@Override
public void apply(final JarEntry jarEntry) throws OperationException {
final JarFileNode file = nodeFactory.newJarFileNode(jarEntry, libId, projectPath, null);
AsyncCallback<VirtualFile> downloadSourceCallback = new AsyncCallback<VirtualFile>() {
@Override
public void onSuccess(final VirtualFile result) {
if (file.isContentGenerated()) {
handleContentGeneratedResource(file, location, callback);
} else {
handleActivatedFile(file, callback, location.getLineNumber());
}
}
@Override
public void onFailure(Throwable caught) {
callback.onFailure(caught);
}
};
handleActivatedFile(file, downloadSourceCallback, location.getLineNumber());
eventBus.fireEvent(FileEvent.createOpenFileEvent(file));
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
callback.onFailure(arg.getCause());
}
});
}
use of org.eclipse.che.api.promises.client.OperationException in project che by eclipse.
the class ProcessesPanelPresenter method onPreviewSsh.
@Override
public void onPreviewSsh(String machineId) {
ProcessTreeNode machineTreeNode = findProcessTreeNodeById(machineId);
if (machineTreeNode == null) {
return;
}
Machine machine = (Machine) machineTreeNode.getData();
final OutputConsole defaultConsole = commandConsoleFactory.create("SSH");
addCommandOutput(machineId, defaultConsole);
final String machineName = machine.getConfig().getName();
String sshServiceAddress = getSshServerAddress(machine);
final String machineHost;
final String sshPort;
if (sshServiceAddress != null) {
String[] parts = sshServiceAddress.split(":");
machineHost = parts[0];
sshPort = (parts.length == 2) ? parts[1] : SSH_PORT;
} else {
sshPort = SSH_PORT;
machineHost = "";
}
// user
final String userName;
String user = machine.getRuntime().getProperties().get("config.user");
if (isNullOrEmpty(user)) {
userName = "root";
} else {
userName = user;
}
// ssh key
final String workspaceName = appContext.getWorkspace().getConfig().getName();
Promise<SshPairDto> sshPairDtoPromise = sshServiceClient.getPair("workspace", machine.getWorkspaceId());
sshPairDtoPromise.then(new Operation<SshPairDto>() {
@Override
public void apply(SshPairDto sshPairDto) throws OperationException {
if (defaultConsole instanceof DefaultOutputConsole) {
((DefaultOutputConsole) defaultConsole).enableAutoScroll(false);
((DefaultOutputConsole) defaultConsole).printText(localizationConstant.sshConnectInfo(machineName, machineHost, sshPort, workspaceName, userName, localizationConstant.sshConnectInfoPrivateKey(sshPairDto.getPrivateKey())));
}
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
if (defaultConsole instanceof DefaultOutputConsole) {
((DefaultOutputConsole) defaultConsole).enableAutoScroll(false);
((DefaultOutputConsole) defaultConsole).printText(localizationConstant.sshConnectInfo(machineName, machineHost, sshPort, workspaceName, userName, localizationConstant.sshConnectInfoNoPrivateKey()));
}
}
});
}
use of org.eclipse.che.api.promises.client.OperationException in project che by eclipse.
the class SshCategoryPresenter method updateTargetRecipe.
/**
* Updates as existent target recipe and save it.
*/
private void updateTargetRecipe() {
RecipeUpdate recipeUpdate = dtoFactory.createDto(RecipeUpdate.class).withId(selectedTarget.getRecipe().getId()).withName(sshView.getTargetName()).withType(selectedTarget.getRecipe().getType()).withTags(selectedTarget.getRecipe().getTags()).withDescription(selectedTarget.getRecipe().getDescription()).withScript("{" + "\"host\": \"" + selectedTarget.getHost() + "\", " + "\"port\": \"" + selectedTarget.getPort() + "\", " + "\"username\": \"" + selectedTarget.getUserName() + "\", " + "\"password\": \"" + selectedTarget.getPassword() + "\"" + "}");
Promise<RecipeDescriptor> updateRecipe = recipeServiceClient.updateRecipe(recipeUpdate);
updateRecipe.then(new Operation<RecipeDescriptor>() {
@Override
public void apply(RecipeDescriptor recipe) throws OperationException {
onTargetSaved(recipe);
}
});
updateRecipe.catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
dialogFactory.createMessageDialog("Error", machineLocale.targetsViewSaveError(), null).show();
}
});
}
use of org.eclipse.che.api.promises.client.OperationException in project che by eclipse.
the class SshCategoryPresenter method createTargetRecipe.
/**
* Create a new target recipe and save it.
*/
private void createTargetRecipe() {
List<String> tags = new ArrayList<>();
tags.add(this.getCategory());
NewRecipe newRecipe = dtoFactory.createDto(NewRecipe.class).withName(selectedTarget.getName()).withType(getCategory()).withScript("{" + "\"host\": \"" + selectedTarget.getHost() + "\", " + "\"port\": \"" + selectedTarget.getPort() + "\", " + "\"username\": \"" + selectedTarget.getUserName() + "\", " + "\"password\": \"" + selectedTarget.getPassword() + "\"" + "}").withTags(tags);
Promise<RecipeDescriptor> createRecipe = recipeServiceClient.createRecipe(newRecipe);
createRecipe.then(new Operation<RecipeDescriptor>() {
@Override
public void apply(RecipeDescriptor recipe) throws OperationException {
onTargetSaved(recipe);
}
});
createRecipe.catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
dialogFactory.createMessageDialog("Error", machineLocale.targetsViewSaveError(), null).show();
}
});
}
Aggregations