use of elemental.json.JsonObject in project che by eclipse.
the class JsonRpcRequest method toJsonObject.
public JsonObject toJsonObject() {
JsonObject request = jsonFactory.createObject();
request.put("jsonrpc", "2.0");
request.put("method", method);
if (hasId()) {
request.put("id", id);
}
if (hasParams()) {
request.put("params", params.toJsonValue());
}
return request;
}
use of elemental.json.JsonObject in project che by eclipse.
the class EditorAgentImpl method loadState.
@Override
@SuppressWarnings("unchecked")
public void loadState(@NotNull final JsonObject state) {
if (state.hasKey("FILES")) {
JsonObject files = state.getObject("FILES");
EditorPartStack partStack = editorMultiPartStack.createRootPartStack();
final Map<EditorPartPresenter, EditorPartStack> activeEditors = new HashMap<>();
List<Promise<Void>> restore = restore(files, partStack, activeEditors);
Promise<ArrayOf<?>> promise = promiseProvider.all2(restore.toArray(new Promise[restore.size()]));
promise.then(new Operation() {
@Override
public void apply(Object arg) throws OperationException {
String activeFile = "";
if (state.hasKey("ACTIVE_EDITOR")) {
activeFile = state.getString("ACTIVE_EDITOR");
}
EditorPartPresenter activeEditorPart = null;
for (Map.Entry<EditorPartPresenter, EditorPartStack> entry : activeEditors.entrySet()) {
entry.getValue().setActivePart(entry.getKey());
if (activeFile.equals(entry.getKey().getEditorInput().getFile().getLocation().toString())) {
activeEditorPart = entry.getKey();
}
}
workspaceAgent.setActivePart(activeEditorPart);
}
});
}
}
use of elemental.json.JsonObject in project che by eclipse.
the class EditorAgentImpl method storeEditors.
private JsonArray storeEditors(EditorPartStack partStack) {
JsonArray result = Json.createArray();
int i = 0;
List<EditorPartPresenter> parts = partStack.getParts();
for (EditorPartPresenter part : parts) {
JsonObject file = Json.createObject();
file.put("PATH", part.getEditorInput().getFile().getLocation().toString());
file.put("EDITOR_PROVIDER", openedEditorsToProviders.get(part));
if (part instanceof TextEditor) {
file.put("CURSOR_OFFSET", ((TextEditor) part).getCursorOffset());
file.put("TOP_VISIBLE_LINE", ((TextEditor) part).getTopVisibleLine());
}
if (partStack.getActivePart().equals(part)) {
file.put("ACTIVE", true);
}
result.set(i++, file);
}
return result;
}
use of elemental.json.JsonObject in project che by eclipse.
the class EditorAgentImpl method getState.
@Override
public JsonObject getState() {
JsonObject state = Json.createObject();
EditorMultiPartStackState stacks = null;
try {
stacks = editorMultiPartStack.getState();
} catch (IllegalStateException ignore) {
}
if (stacks != null) {
state.put("FILES", storeEditors(stacks));
}
EditorPartPresenter activeEditor = getActiveEditor();
if (activeEditor != null) {
state.put("ACTIVE_EDITOR", activeEditor.getEditorInput().getFile().getLocation().toString());
}
return state;
}
use of elemental.json.JsonObject in project che by eclipse.
the class EditorAgentImpl method restore.
private List<Promise<Void>> restore(JsonObject files, EditorPartStack editorPartStack, Map<EditorPartPresenter, EditorPartStack> activeEditors) {
if (files.hasKey("FILES")) {
//plain
JsonArray filesArray = files.getArray("FILES");
List<Promise<Void>> promises = new ArrayList<>();
for (int i = 0; i < filesArray.length(); i++) {
JsonObject file = filesArray.getObject(i);
Promise<Void> openFile = openFile(file, editorPartStack, activeEditors);
promises.add(openFile);
}
return promises;
} else {
//split
return restoreSplit(files, editorPartStack, activeEditors);
}
}
Aggregations