use of com.google.gwt.user.client.rpc.AsyncCallback 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 com.google.gwt.user.client.rpc.AsyncCallback in project che by eclipse.
the class CopyPasteManager method moveResource.
private Promise<Void> moveResource(final Resource resource, final Path destination) {
//simple move without overwriting
return resource.move(destination).thenPromise(new Function<Resource, Promise<Void>>() {
@Override
public Promise<Void> apply(Resource resource) throws FunctionException {
eventBus.fireEvent(new RevealResourceEvent(resource));
return promises.resolve(null);
}
}).catchErrorPromise(new Function<PromiseError, Promise<Void>>() {
@Override
public Promise<Void> apply(final PromiseError error) throws FunctionException {
//resource may already exists
if (error.getMessage().contains("exists")) {
//create dialog with overwriting option
return createFromAsyncRequest(new RequestCall<Void>() {
@Override
public void makeCall(final AsyncCallback<Void> callback) {
//handle overwrite operation
final ConfirmCallback overwrite = new ConfirmCallback() {
@Override
public void accepted() {
//copy with overwriting
resource.move(destination, true).then(new Operation<Resource>() {
@Override
public void apply(Resource ignored) throws OperationException {
callback.onSuccess(null);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
callback.onFailure(error.getCause());
}
});
}
};
//skip this resource
final ConfirmCallback skip = new ConfirmCallback() {
@Override
public void accepted() {
callback.onSuccess(null);
}
};
//change destination name
final ConfirmCallback rename = new ConfirmCallback() {
@Override
public void accepted() {
dialogFactory.createInputDialog("Enter new name", "Enter new name", new InputCallback() {
@Override
public void accepted(String value) {
final Path newPath = destination.parent().append(value);
moveResource(resource, newPath).then(new Operation<Void>() {
@Override
public void apply(Void result) throws OperationException {
callback.onSuccess(result);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
callback.onFailure(error.getCause());
}
});
}
}, new CancelCallback() {
@Override
public void cancelled() {
}
}).show();
}
};
dialogFactory.createChoiceDialog("Error", error.getMessage(), "Overwrite", "Skip", "Change Name", overwrite, skip, rename).show();
}
});
} else {
//notify user about failed copying
notificationManager.notify("Error moving resource", error.getMessage(), FAIL, FLOAT_MODE);
return promises.resolve(null);
}
}
});
}
use of com.google.gwt.user.client.rpc.AsyncCallback in project che by eclipse.
the class CopyPasteManager method copyResource.
private Promise<Void> copyResource(final Resource resource, final Path destination) {
//simple copy without overwriting
return resource.copy(destination).thenPromise(new Function<Resource, Promise<Void>>() {
@Override
public Promise<Void> apply(Resource resource) throws FunctionException {
eventBus.fireEvent(new RevealResourceEvent(resource));
return promises.resolve(null);
}
}).catchErrorPromise(new Function<PromiseError, Promise<Void>>() {
@Override
public Promise<Void> apply(final PromiseError error) throws FunctionException {
//resource may already exists
if (error.getMessage().contains("exists")) {
//create dialog with overwriting option
return createFromAsyncRequest(new RequestCall<Void>() {
@Override
public void makeCall(final AsyncCallback<Void> callback) {
//handle overwrite operation
final ConfirmCallback overwrite = new ConfirmCallback() {
@Override
public void accepted() {
//copy with overwriting
resource.copy(destination, true).then(new Operation<Resource>() {
@Override
public void apply(Resource ignored) throws OperationException {
callback.onSuccess(null);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
callback.onFailure(error.getCause());
}
});
}
};
//skip this resource
final ConfirmCallback skip = new ConfirmCallback() {
@Override
public void accepted() {
callback.onSuccess(null);
}
};
//change destination name
final ConfirmCallback rename = new ConfirmCallback() {
@Override
public void accepted() {
dialogFactory.createInputDialog("Enter new name", "Enter new name", new InputCallback() {
@Override
public void accepted(String value) {
final Path newPath = destination.parent().append(value);
copyResource(resource, newPath).then(new Operation<Void>() {
@Override
public void apply(Void result) throws OperationException {
callback.onSuccess(result);
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
callback.onFailure(error.getCause());
}
});
}
}, new CancelCallback() {
@Override
public void cancelled() {
}
}).show();
}
};
dialogFactory.createChoiceDialog("Error", error.getMessage(), "Overwrite", "Skip", "Change Name", overwrite, skip, rename).show();
}
});
} else {
//notify user about failed copying
notificationManager.notify("Error copying resource", error.getMessage(), FAIL, FLOAT_MODE);
return promises.resolve(null);
}
}
});
}
use of com.google.gwt.user.client.rpc.AsyncCallback in project gerrit by GerritCodeReview.
the class ProjectAccessScreen method onLoad.
@Override
protected void onLoad() {
super.onLoad();
CallbackGroup cbs = new CallbackGroup();
ConfigServerApi.capabilities(cbs.add(new AsyncCallback<NativeMap<CapabilityInfo>>() {
@Override
public void onSuccess(NativeMap<CapabilityInfo> result) {
capabilityMap = result;
}
@Override
public void onFailure(Throwable caught) {
// Handled by ScreenLoadCallback.onFailure().
}
}));
Util.PROJECT_SVC.projectAccess(getProjectKey(), cbs.addFinal(new ScreenLoadCallback<ProjectAccess>(this) {
@Override
public void preDisplay(ProjectAccess access) {
displayReadOnly(access);
}
}));
savedPanel = ACCESS;
}
use of com.google.gwt.user.client.rpc.AsyncCallback in project gerrit by GerritCodeReview.
the class EditScreen method onLoad.
@Override
protected void onLoad() {
super.onLoad();
prefs = EditPreferences.create(Gerrit.getEditPreferences());
CallbackGroup group1 = new CallbackGroup();
final CallbackGroup group2 = new CallbackGroup();
final CallbackGroup group3 = new CallbackGroup();
CodeMirror.initLibrary(group1.add(new AsyncCallback<Void>() {
final AsyncCallback<Void> themeCallback = group3.addEmpty();
@Override
public void onSuccess(Void result) {
// Load theme after CM library to ensure theme can override CSS.
ThemeLoader.loadTheme(prefs.theme(), themeCallback);
group2.done();
new AddonInjector().add(Addons.I.merge_bundled().getName()).inject(new AsyncCallback<Void>() {
@Override
public void onFailure(Throwable caught) {
}
@Override
public void onSuccess(Void result) {
if (!prefs.showBase() || revision.get() > 0) {
group3.done();
}
}
});
}
@Override
public void onFailure(Throwable caught) {
}
}));
ChangeApi.detail(revision.getParentKey().get(), group1.add(new AsyncCallback<ChangeInfo>() {
@Override
public void onSuccess(ChangeInfo c) {
project.setInnerText(c.project());
SafeHtml.setInnerHTML(filePath, Header.formatPath(path));
}
@Override
public void onFailure(Throwable caught) {
}
}));
if (revision.get() == 0) {
ChangeEditApi.getMeta(revision, path, group1.add(new AsyncCallback<EditFileInfo>() {
@Override
public void onSuccess(EditFileInfo editInfo) {
editFileInfo = editInfo;
}
@Override
public void onFailure(Throwable e) {
}
}));
if (prefs.showBase()) {
ChangeEditApi.get(revision, path, true, /* base */
group1.addFinal(new HttpCallback<NativeString>() {
@Override
public void onSuccess(HttpResponse<NativeString> fc) {
baseContent = fc;
group3.done();
}
@Override
public void onFailure(Throwable e) {
}
}));
} else {
group1.done();
}
} else {
// TODO(davido): We probably want to create dedicated GET EditScreenMeta
// REST endpoint. Abuse GET diff for now, as it retrieves links we need.
DiffApi.diff(revision, path).webLinksOnly().get(group1.addFinal(new AsyncCallback<DiffInfo>() {
@Override
public void onSuccess(DiffInfo diffInfo) {
diffLinks = diffInfo.webLinks();
}
@Override
public void onFailure(Throwable e) {
}
}));
}
ChangeEditApi.get(revision, path, group2.add(new HttpCallback<NativeString>() {
final AsyncCallback<Void> modeCallback = group3.addEmpty();
@Override
public void onSuccess(HttpResponse<NativeString> fc) {
content = fc;
if (revision.get() > 0) {
baseContent = fc;
}
if (prefs.syntaxHighlighting()) {
injectMode(fc.getContentType(), modeCallback);
} else {
modeCallback.onSuccess(null);
}
}
@Override
public void onFailure(Throwable e) {
// "Not Found" means it's a new file.
if (RestApi.isNotFound(e)) {
content = null;
modeCallback.onSuccess(null);
} else {
GerritCallback.showFailure(e);
}
}
}));
group3.addListener(new ScreenLoadCallback<Void>(this) {
@Override
protected void preDisplay(Void result) {
initEditor();
renderLinks(editFileInfo, diffLinks);
editFileInfo = null;
diffLinks = null;
showBase.setValue(prefs.showBase(), true);
cmBase.refresh();
}
});
}
Aggregations