use of org.eclipse.che.api.promises.client.OperationException in project che by eclipse.
the class OpenImplementationPresenter method actionPerformed.
public void actionPerformed(final Member member) {
if (member.isBinary()) {
final Resource resource = context.getResource();
if (resource == null) {
return;
}
final Optional<Project> project = resource.getRelatedProject();
service.getEntry(project.get().getLocation(), member.getLibId(), member.getRootPath()).then(new Operation<JarEntry>() {
@Override
public void apply(final JarEntry entry) throws OperationException {
service.getContent(project.get().getLocation(), member.getLibId(), Path.valueOf(entry.getPath())).then(new Operation<ClassContent>() {
@Override
public void apply(ClassContent content) throws OperationException {
final String clazz = entry.getName().substring(0, entry.getName().indexOf('.'));
final VirtualFile file = new SyntheticFile(entry.getName(), clazz, content.getContent());
editorAgent.openEditor(file, new OpenEditorCallbackImpl() {
@Override
public void onEditorOpened(EditorPartPresenter editor) {
setCursor(member.getFileRegion());
}
});
}
});
}
});
} else {
context.getWorkspaceRoot().getFile(member.getRootPath()).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) {
setCursor(member.getFileRegion());
}
});
}
}
});
}
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
activeEditor.setFocus();
}
});
}
use of org.eclipse.che.api.promises.client.OperationException in project che by eclipse.
the class ProjectImporter method authUserAndRecallImport.
private Promise<Project> authUserAndRecallImport(final String providerName, final String authenticateUrl, final Path path, final SourceStorage sourceStorage, final ProjectNotificationSubscriber subscriber) {
return createFromAsyncRequest(new RequestCall<Project>() {
@Override
public void makeCall(final AsyncCallback<Project> callback) {
OAuth2Authenticator authenticator = oAuth2AuthenticatorRegistry.getAuthenticator(providerName);
if (authenticator == null) {
authenticator = oAuth2AuthenticatorRegistry.getAuthenticator("default");
}
authenticator.authenticate(OAuth2AuthenticatorUrlProvider.get(appContext.getMasterEndpoint(), authenticateUrl), new AsyncCallback<OAuthStatus>() {
@Override
public void onFailure(Throwable caught) {
callback.onFailure(new Exception(caught.getMessage()));
}
@Override
public void onSuccess(OAuthStatus result) {
if (!result.equals(OAuthStatus.NOT_PERFORMED)) {
doImport(path, sourceStorage).then(new Operation<Project>() {
@Override
public void apply(Project project) throws OperationException {
callback.onSuccess(project);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
callback.onFailure(error.getCause());
}
});
} else {
subscriber.onFailure("Authentication cancelled");
callback.onFailure(new IllegalStateException("Authentication cancelled"));
}
}
});
}
});
}
use of org.eclipse.che.api.promises.client.OperationException in project che by eclipse.
the class FullTextSearchPresenter method search.
@Override
public void search(final String text) {
final Path startPoint = isNullOrEmpty(view.getPathToSearch()) ? defaultStartPoint : Path.valueOf(view.getPathToSearch());
appContext.getWorkspaceRoot().getContainer(startPoint).then(new Operation<Optional<Container>>() {
@Override
public void apply(Optional<Container> optionalContainer) throws OperationException {
if (!optionalContainer.isPresent()) {
view.showErrorMessage("Path '" + startPoint + "' doesn't exists");
return;
}
final Container container = optionalContainer.get();
container.search(view.getFileMask(), prepareQuery(text)).then(new Operation<Resource[]>() {
@Override
public void apply(Resource[] result) throws OperationException {
view.close();
findResultPresenter.handleResponse(result, text);
}
});
}
});
}
use of org.eclipse.che.api.promises.client.OperationException in project che by eclipse.
the class PreferencesPresenter method onRefreshClicked.
@Override
public void onRefreshClicked() {
Promise<Map<String, String>> promise = Promises.resolve(null);
for (final PreferencesManager preferencesManager : managers) {
promise = promise.thenPromise(new Function<Map<String, String>, Promise<Map<String, String>>>() {
@Override
public Promise<Map<String, String>> apply(Map<String, String> arg) throws FunctionException {
return preferencesManager.loadPreferences().catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
notificationManagerProvider.get().notify(locale.unableToLoadPreference(), error.getMessage(), FAIL, FLOAT_MODE);
}
});
}
});
}
/**
* Revert changes on every preference page
*/
promise.then(new Operation<Map<String, String>>() {
@Override
public void apply(Map<String, String> arg) throws OperationException {
for (PreferencePagePresenter p : PreferencesPresenter.this.preferences) {
p.revertChanges();
}
}
});
}
use of org.eclipse.che.api.promises.client.OperationException in project che by eclipse.
the class PreferencesPresenter method onSaveClicked.
@Override
public void onSaveClicked() {
for (PreferencePagePresenter preference : preferences) {
if (preference.isDirty()) {
preference.storeChanges();
}
}
Promise<Void> promise = Promises.resolve(null);
final List<PromiseError> promiseErrorList = new ArrayList<>();
for (final PreferencesManager preferencesManager : managers) {
promise = promise.thenPromise(new Function<Void, Promise<Void>>() {
@Override
public Promise<Void> apply(Void arg) throws FunctionException {
return preferencesManager.flushPreferences().catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
notificationManagerProvider.get().notify(locale.unableToSavePreference(), error.getMessage(), FAIL, FLOAT_MODE);
promiseErrorList.add(error);
}
});
}
});
}
promise.then(new Operation<Void>() {
@Override
public void apply(Void aVoid) throws OperationException {
if (promiseErrorList.isEmpty()) {
view.enableSaveButton(false);
}
}
});
}
Aggregations