use of org.eclipse.che.api.promises.client.PromiseError 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.PromiseError 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();
}
});
}
use of org.eclipse.che.api.promises.client.PromiseError in project che by eclipse.
the class SshCategoryPresenter method connect.
/**
* Opens a connection to the selected target.
* Starts a machine based on the selected recipe.
*/
private void connect() {
sshView.setConnectButtonText(null);
connectTargetName = selectedTarget.getName();
connectNotification = notificationManager.notify(machineLocale.targetsViewConnectProgress(selectedTarget.getName()), PROGRESS, FLOAT_MODE);
String recipeURL = selectedTarget.getRecipe().getLink("get recipe script").getHref();
MachineLimitsDto limitsDto = dtoFactory.createDto(MachineLimitsDto.class).withRam(1024);
MachineSourceDto sourceDto = dtoFactory.createDto(MachineSourceDto.class).withType("ssh-config").withLocation(recipeURL);
MachineConfigDto configDto = dtoFactory.createDto(MachineConfigDto.class).withDev(false).withName(selectedTarget.getName()).withSource(sourceDto).withLimits(limitsDto).withType(getCategory());
Promise<Void> machinePromise = workspaceServiceClient.createMachine(appContext.getWorkspaceId(), configDto);
machinePromise.then(new Operation<Void>() {
@Override
public void apply(Void arg) throws OperationException {
}
});
machinePromise.catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError promiseError) throws OperationException {
onConnectingFailed(null);
}
});
}
use of org.eclipse.che.api.promises.client.PromiseError in project che by eclipse.
the class RecipePartPresenter method onSaveButtonClicked.
/** {@inheritDoc} */
@Override
public void onSaveButtonClicked() {
RecipeEditorPanel editorPanel = recipesContainerPresenter.getEditorPanel(selectedRecipe);
RecipeDescriptor recipeDescriptor = selectedRecipe.getDescriptor();
final RecipeUpdate recipeUpdate = dtoFactory.createDto(RecipeUpdate.class).withId(recipeDescriptor.getId()).withType(recipeDescriptor.getType()).withScript(editorPanel.getScript()).withName(editorPanel.getName()).withTags(editorPanel.getTags());
Promise<RecipeDescriptor> updateRecipe = service.updateRecipe(recipeUpdate);
updateRecipe.then(new Operation<RecipeDescriptor>() {
@Override
public void apply(RecipeDescriptor recipeDescriptor) throws OperationException {
RecipeDescriptor selectedRecipeDescriptor = recipes.get(selectedRecipe);
selectedRecipeDescriptor.setScript(recipeDescriptor.getScript());
selectedRecipeDescriptor.setTags(recipeDescriptor.getTags());
selectedRecipeDescriptor.setName(recipeDescriptor.getName());
selectedRecipe.setName(recipeDescriptor.getName());
notificationManager.notify("Recipe \"" + recipeDescriptor.getName() + "\" was saved.");
}
});
updateRecipe.catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
if (arg.getMessage() != null) {
notificationManager.notify(locale.failedToSaveRecipe(), arg.getMessage(), FAIL, FLOAT_MODE);
}
}
});
}
use of org.eclipse.che.api.promises.client.PromiseError in project che by eclipse.
the class TestResultViewImpl method gotoClass.
@Override
public void gotoClass(String packagePath, int line) {
lastWentLine = line;
final Project project = appContext.getRootProject();
String testSrcPath = project.getPath() + "/" + DEFAULT_TEST_SOURCE_FOLDER;
appContext.getWorkspaceRoot().getFile(testSrcPath + packagePath).then(new Operation<Optional<File>>() {
@Override
public void apply(Optional<File> file) throws OperationException {
if (file.isPresent()) {
eventBus.fireEvent(FileEvent.createOpenFileEvent(file.get()));
Timer t = new Timer() {
@Override
public void run() {
EditorPartPresenter editorPart = editorAgent.getActiveEditor();
Document doc = ((TextEditor) editorPart).getDocument();
doc.setCursorPosition(new TextPosition(lastWentLine - 1, 0));
}
};
t.schedule(500);
}
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
Log.info(TestResultViewImpl.class, error);
}
});
}
Aggregations