use of org.eclipse.che.api.promises.client.OperationException in project che by eclipse.
the class RenamePresenter method validateName.
/** {@inheritDoc} */
@Override
public void validateName() {
ValidateNewName validateNewName = dtoFactory.createDto(ValidateNewName.class);
validateNewName.setSessionId(renameRefactoringSession.getSessionId());
validateNewName.setNewName(view.getNewName());
refactorService.validateNewName(validateNewName).then(new Operation<RefactoringStatus>() {
@Override
public void apply(RefactoringStatus arg) throws OperationException {
switch(arg.getSeverity()) {
case OK:
view.setEnableAcceptButton(true);
view.setEnablePreviewButton(true);
view.clearErrorLabel();
break;
case INFO:
view.setEnableAcceptButton(true);
view.setEnablePreviewButton(true);
view.showStatusMessage(arg);
break;
default:
view.setEnableAcceptButton(false);
view.setEnablePreviewButton(false);
view.showErrorMessage(arg);
break;
}
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
notificationManager.notify(locale.failedToRename(), arg.getMessage(), FAIL, FLOAT_MODE);
}
});
}
use of org.eclipse.che.api.promises.client.OperationException in project che by eclipse.
the class RenamePresenter method show.
/**
* Show Rename window with the special information.
*
* @param refactorInfo
* information about the rename operation
*/
public void show(RefactorInfo refactorInfo) {
this.refactorInfo = refactorInfo;
final CreateRenameRefactoring createRenameRefactoring = createRenameRefactoringDto(refactorInfo);
Promise<RenameRefactoringSession> createRenamePromise = refactorService.createRenameRefactoring(createRenameRefactoring);
createRenamePromise.then(new Operation<RenameRefactoringSession>() {
@Override
public void apply(RenameRefactoringSession session) throws OperationException {
show(session);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
notificationManager.notify(locale.failedToRename(), arg.getMessage(), FAIL, FLOAT_MODE);
}
});
}
use of org.eclipse.che.api.promises.client.OperationException in project che by eclipse.
the class MatchNode method actionPerformed.
@Override
public void actionPerformed() {
if (compilationUnit != null) {
final EditorPartPresenter editorPartPresenter = editorAgent.getOpenedEditor(Path.valueOf(compilationUnit.getPath()));
if (editorPartPresenter != null) {
selectRange(editorPartPresenter);
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
editorAgent.activateEditor(editorPartPresenter);
}
});
return;
}
appContext.getWorkspaceRoot().getFile(compilationUnit.getPath()).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) {
selectRange(editor);
}
});
}
}
});
} else if (classFile != null) {
final String className = classFile.getElementName();
final Resource resource = appContext.getResource();
if (resource == null) {
return;
}
final Project project = resource.getRelatedProject().get();
service.getContent(project.getLocation(), className).then(new Operation<ClassContent>() {
@Override
public void apply(ClassContent content) throws OperationException {
final VirtualFile file = new SyntheticFile(Path.valueOf(className.replace('.', '/')).lastSegment(), content.getContent());
editorAgent.openEditor(file, new OpenEditorCallbackImpl() {
@Override
public void onEditorOpened(EditorPartPresenter editor) {
selectRange(editor);
}
});
}
});
}
}
use of org.eclipse.che.api.promises.client.OperationException in project che by eclipse.
the class OrganizeImportsPresenter method onFinishButtonClicked.
/** {@inheritDoc} */
@Override
public void onFinishButtonClicked() {
selected.put(page, view.getSelectedImport());
ConflictImportDTO result = dtoFactory.createDto(ConflictImportDTO.class).withTypeMatches(new ArrayList<>(selected.values()));
if (file instanceof Resource) {
final Optional<Project> project = ((Resource) file).getRelatedProject();
javaCodeAssistClient.applyChosenImports(project.get().getLocation().toString(), JavaUtil.resolveFQN(file), result).then(new Operation<List<Change>>() {
@Override
public void apply(List<Change> result) throws OperationException {
applyChanges(((TextEditor) editor).getDocument(), result);
view.hide();
((TextEditor) editor).setFocus();
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
String title = locale.failedToProcessOrganizeImports();
String message = arg.getMessage();
notificationManager.notify(title, message, FAIL, FLOAT_MODE);
}
});
}
}
use of org.eclipse.che.api.promises.client.OperationException in project che by eclipse.
the class ClasspathResolver method updateClasspath.
/** Concatenates classpath entries and update classpath file. */
public Promise<Void> updateClasspath() {
final Resource resource = appContext.getResource();
checkState(resource != null);
final Optional<Project> optProject = resource.getRelatedProject();
checkState(optProject.isPresent());
final List<ClasspathEntryDto> entries = new ArrayList<>();
for (String path : libs) {
entries.add(dtoFactory.createDto(ClasspathEntryDto.class).withPath(path).withEntryKind(LIBRARY));
}
for (ClasspathEntryDto container : containers) {
entries.add(container);
}
for (String path : sources) {
entries.add(dtoFactory.createDto(ClasspathEntryDto.class).withPath(path).withEntryKind(SOURCE));
}
for (String path : projects) {
entries.add(dtoFactory.createDto(ClasspathEntryDto.class).withPath(path).withEntryKind(PROJECT));
}
final Project project = optProject.get();
Promise<Void> promise = classpathUpdater.setRawClasspath(project.getLocation().toString(), entries);
promise.then(new Operation<Void>() {
@Override
public void apply(Void arg) throws OperationException {
project.synchronize().then(new Operation<Resource[]>() {
@Override
public void apply(Resource[] arg) throws OperationException {
eventBus.fireEvent(new ClasspathChangedEvent(project.getLocation().toString(), entries));
}
});
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
notificationManager.notify("Problems with updating classpath", arg.getMessage(), FAIL, EMERGE_MODE);
}
});
return promise;
}
Aggregations