use of com.google.gwt.core.client.JsArray in project gerrit by GerritCodeReview.
the class PatchSetSelectBox method setUpBlame.
void setUpBlame(final CodeMirror cm, final boolean isBase, final PatchSet.Id rev, final String path) {
if (!Patch.isMagic(path) && Gerrit.isSignedIn() && Gerrit.info().change().allowBlame()) {
Anchor blameIcon = createBlameIcon();
blameIcon.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
if (cm.extras().getBlameInfo() != null) {
cm.extras().toggleAnnotation();
} else {
ChangeApi.blame(rev, path, isBase).get(new GerritCallback<JsArray<BlameInfo>>() {
@Override
public void onSuccess(JsArray<BlameInfo> lines) {
cm.extras().toggleAnnotation(lines);
}
});
}
}
});
linkPanel.add(blameIcon);
}
}
use of com.google.gwt.core.client.JsArray in project gerrit by GerritCodeReview.
the class ChangeList method queryMultiple.
/** Run multiple queries in a single remote invocation. */
public static void queryMultiple(final AsyncCallback<JsArray<ChangeList>> callback, Set<ListChangesOption> options, String... queries) {
if (queries.length == 0) {
return;
}
RestApi call = new RestApi(URI);
for (String q : queries) {
call.addParameterRaw("q", KeyUtil.encode(q));
}
addOptions(call, options);
if (queries.length == 1) {
// Server unwraps a single query, so wrap it back in an array for the
// callback.
call.get(new AsyncCallback<ChangeList>() {
@Override
public void onSuccess(ChangeList result) {
JsArray<ChangeList> wrapped = JsArray.createArray(1).cast();
wrapped.set(0, result);
callback.onSuccess(wrapped);
}
@Override
public void onFailure(Throwable caught) {
callback.onFailure(caught);
}
});
} else {
call.get(callback);
}
}
use of com.google.gwt.core.client.JsArray in project rstudio by rstudio.
the class ModifyKeyboardShortcutsWidget method collectShortcuts.
private void collectShortcuts() {
final List<KeyboardShortcutEntry> bindings = new ArrayList<KeyboardShortcutEntry>();
SerializedCommandQueue queue = new SerializedCommandQueue();
// Load addins discovered as part of package exports. This registers
// the addin, with the actual keybinding to be registered later,
// if discovered.
queue.addCommand(new SerializedCommand() {
@Override
public void onExecute(final Command continuation) {
RAddins rAddins = addins_.getRAddins();
for (String key : JsUtil.asIterable(rAddins.keys())) {
RAddin addin = rAddins.get(key);
bindings.add(new KeyboardShortcutEntry(addin.getPackage() + "::" + addin.getBinding(), addin.getName(), new KeySequence(), KeyboardShortcutEntry.TYPE_ADDIN, false, AppCommand.Context.Addin));
}
continuation.execute();
}
});
// Load saved addin bindings
queue.addCommand(new SerializedCommand() {
@Override
public void onExecute(final Command continuation) {
addins_.loadBindings(new CommandWithArg<EditorKeyBindings>() {
@Override
public void execute(EditorKeyBindings addinBindings) {
for (String commandId : addinBindings.iterableKeys()) {
EditorKeyBinding addinBinding = addinBindings.get(commandId);
for (KeyboardShortcutEntry binding : bindings) {
if (binding.getId() == commandId) {
List<KeySequence> keys = addinBinding.getKeyBindings();
if (keys.size() >= 1)
binding.setDefaultKeySequence(keys.get(0));
if (keys.size() >= 2) {
for (int i = 1; i < keys.size(); i++) {
bindings.add(new KeyboardShortcutEntry(binding.getId(), binding.getName(), keys.get(i), KeyboardShortcutEntry.TYPE_ADDIN, false, AppCommand.Context.Addin));
}
}
}
}
}
continuation.execute();
}
});
}
});
// Ace loading command
queue.addCommand(new SerializedCommand() {
@Override
public void onExecute(final Command continuation) {
// Ace Commands
JsArray<AceCommand> aceCommands = editorCommands_.getCommands();
for (int i = 0; i < aceCommands.length(); i++) {
AceCommand command = aceCommands.get(i);
JsArrayString shortcuts = command.getBindingsForCurrentPlatform();
if (shortcuts != null) {
String id = command.getInternalName();
String name = command.getDisplayName();
boolean custom = command.isCustomBinding();
for (int j = 0; j < shortcuts.length(); j++) {
String shortcut = shortcuts.get(j);
KeySequence keys = KeySequence.fromShortcutString(shortcut);
int type = KeyboardShortcutEntry.TYPE_EDITOR_COMMAND;
bindings.add(new KeyboardShortcutEntry(id, name, keys, type, custom, AppCommand.Context.Editor));
}
}
}
continuation.execute();
}
});
// RStudio commands
queue.addCommand(new SerializedCommand() {
@Override
public void onExecute(final Command continuation) {
// RStudio Commands
appCommands_.loadBindings(new CommandWithArg<EditorKeyBindings>() {
@Override
public void execute(final EditorKeyBindings customBindings) {
Map<String, AppCommand> commands = commands_.getCommands();
for (Map.Entry<String, AppCommand> entry : commands.entrySet()) {
AppCommand command = entry.getValue();
if (isExcludedCommand(command))
continue;
String id = command.getId();
String name = getAppCommandName(command);
int type = KeyboardShortcutEntry.TYPE_RSTUDIO_COMMAND;
boolean isCustom = customBindings.hasKey(id);
List<KeySequence> keySequences = new ArrayList<KeySequence>();
if (isCustom)
keySequences = customBindings.get(id).getKeyBindings();
else
keySequences.add(command.getKeySequence());
for (KeySequence keys : keySequences) {
KeyboardShortcutEntry binding = new KeyboardShortcutEntry(id, name, keys, type, isCustom, command.getContext());
bindings.add(binding);
}
}
continuation.execute();
}
});
}
});
// Sort and finish up
queue.addCommand(new SerializedCommand() {
@Override
public void onExecute(final Command continuation) {
Collections.sort(bindings, new Comparator<KeyboardShortcutEntry>() {
@Override
public int compare(KeyboardShortcutEntry o1, KeyboardShortcutEntry o2) {
if (o1.getContext() != o2.getContext())
return o1.getContext().compareTo(o2.getContext());
return o1.getName().compareTo(o2.getName());
}
});
originalBindings_ = bindings;
updateData(bindings);
continuation.execute();
}
});
queue.addCommand(new SerializedCommand() {
@Override
public void onExecute(Command continuation) {
if (initialFilterText_ != null) {
filterWidget_.setText(initialFilterText_);
filter();
}
continuation.execute();
}
});
// Exhaust the queue
queue.run();
}
use of com.google.gwt.core.client.JsArray in project rstudio by rstudio.
the class ProjectPopupMenu method getDynamicPopupMenu.
@Override
public void getDynamicPopupMenu(final DynamicPopupMenuCallback callback) {
ProjectMRUList.setOpenInNewWindow(false);
if (allowSharedProjects_) {
final GlobalProgressDelayer progress = new GlobalProgressDelayer(RStudioGinjector.INSTANCE.getGlobalDisplay(), 250, "Looking for projects...");
// if shared projects are on, check for them every time the user drops
// the menu; we request one more than the maximum we can display so
// we can let the user know whether there are more projects than those
// that can be displayed in the menu
server_.getSharedProjects(MAX_SHARED_PROJECTS + 1, new ServerRequestCallback<JsArray<SharedProjectDetails>>() {
@Override
public void onResponseReceived(JsArray<SharedProjectDetails> result) {
rebuildMenu(result, callback);
progress.dismiss();
}
@Override
public void onError(ServerError error) {
// if we can't get the shared projects, we can at least show
// the menu without them
rebuildMenu(null, callback);
progress.dismiss();
}
});
} else {
rebuildMenu(null, callback);
}
}
use of com.google.gwt.core.client.JsArray in project rstudio by rstudio.
the class DependencyManager method processDependencyRequest.
private void processDependencyRequest(final DependencyRequest req) {
// convert dependencies to JsArray, excluding satisfied dependencies
final JsArray<Dependency> deps = JsArray.createArray().cast();
for (int i = 0; i < req.dependencies.length; i++) {
boolean satisfied = false;
for (Dependency d : satisfied_) {
if (req.dependencies[i].isEqualTo(d)) {
satisfied = true;
break;
}
}
if (!satisfied)
deps.push(req.dependencies[i]);
}
// if no unsatisfied dependencies were found, we're done already
if (deps.length() == 0) {
req.onComplete.execute(true);
return;
}
// create progress indicator
final ProgressIndicator progress = new GlobalProgressDelayer(globalDisplay_, 250, req.progressCaption + "...").getIndicator();
// query for unsatisfied dependencies
server_.unsatisfiedDependencies(deps, req.silentEmbeddedUpdate, new ServerRequestCallback<JsArray<Dependency>>() {
@Override
public void onResponseReceived(final JsArray<Dependency> unsatisfiedDeps) {
progress.onCompleted();
updateSatisfied(deps, unsatisfiedDeps);
// if we've satisfied all dependencies then execute the command
if (unsatisfiedDeps.length() == 0) {
req.onComplete.execute(true);
return;
}
// check to see if we can satisfy the version requirement for all
// dependencies
String unsatisfiedVersions = "";
for (int i = 0; i < unsatisfiedDeps.length(); i++) {
if (!unsatisfiedDeps.get(i).getVersionSatisfied()) {
unsatisfiedVersions += unsatisfiedDeps.get(i).getName() + " " + unsatisfiedDeps.get(i).getVersion();
String version = unsatisfiedDeps.get(i).getAvailableVersion();
if (version.isEmpty())
unsatisfiedVersions += " is not available\n";
else
unsatisfiedVersions += " is required but " + version + " is available\n";
}
}
if (!unsatisfiedVersions.isEmpty()) {
// error if we can't satisfy requirements
globalDisplay_.showErrorMessage(StringUtil.isNullOrEmpty(req.userAction) ? "Packages Not Found" : req.userAction, "Required package versions could not be found:\n\n" + unsatisfiedVersions + "\n" + "Check that getOption(\"repos\") refers to a CRAN " + "repository that contains the needed package versions.");
req.onComplete.execute(false);
} else {
// otherwise ask the user if they want to install the
// unsatisifed dependencies
final CommandWithArg<Boolean> installCommand = new CommandWithArg<Boolean>() {
@Override
public void execute(Boolean confirmed) {
// bail if user didn't confirm
if (!confirmed) {
req.onComplete.execute(false);
return;
}
// the incoming JsArray from the server may not serialize
// as expected when this code is executed from a satellite
// (see RemoteServer.sendRequestViaMainWorkbench), so we
// clone it before passing to the dependency installer
JsArray<Dependency> newArray = JsArray.createArray().cast();
newArray.setLength(unsatisfiedDeps.length());
for (int i = 0; i < unsatisfiedDeps.length(); i++) {
newArray.set(i, unsatisfiedDeps.get(i));
}
installDependencies(newArray, req.silentEmbeddedUpdate, req.onComplete);
}
};
if (req.userPrompt != null) {
req.userPrompt.execute(describeDepPkgs(unsatisfiedDeps), new Command() {
@Override
public void execute() {
installCommand.execute(true);
}
});
} else {
confirmPackageInstallation(req.userAction, unsatisfiedDeps, installCommand);
}
}
}
@Override
public void onError(ServerError error) {
progress.onError(error.getUserMessage());
req.onComplete.execute(false);
}
});
}
Aggregations