Search in sources :

Example 41 with JsonObject

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;
}
Also used : JsonObject(elemental.json.JsonObject)

Example 42 with JsonObject

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);
            }
        });
    }
}
Also used : ArrayOf(elemental.util.ArrayOf) HashMap(java.util.HashMap) JsonObject(elemental.json.JsonObject) Operation(org.eclipse.che.api.promises.client.Operation) Promise(org.eclipse.che.api.promises.client.Promise) HasDataObject(org.eclipse.che.ide.api.data.HasDataObject) JsonObject(elemental.json.JsonObject) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) EditorPartStack(org.eclipse.che.ide.api.parts.EditorPartStack) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 43 with JsonObject

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;
}
Also used : JsonArray(elemental.json.JsonArray) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) JsonObject(elemental.json.JsonObject) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter)

Example 44 with JsonObject

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;
}
Also used : EditorMultiPartStackState(org.eclipse.che.ide.api.parts.EditorMultiPartStackState) JsonObject(elemental.json.JsonObject) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter)

Example 45 with JsonObject

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);
    }
}
Also used : JsonArray(elemental.json.JsonArray) Promise(org.eclipse.che.api.promises.client.Promise) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) JsonObject(elemental.json.JsonObject)

Aggregations

JsonObject (elemental.json.JsonObject)70 Test (org.junit.Test)49 JsonValue (elemental.json.JsonValue)19 JsonArray (elemental.json.JsonArray)14 JsonString (elemental.json.JsonString)5 PartPresenter (org.eclipse.che.ide.api.parts.PartPresenter)5 ArrayList (java.util.ArrayList)4 Matchers.anyString (org.mockito.Matchers.anyString)4 Promise (org.eclipse.che.api.promises.client.Promise)3 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)3 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 JsonException (elemental.json.JsonException)2 List (java.util.List)2 Map (java.util.Map)2 OperationException (org.eclipse.che.api.promises.client.OperationException)2 StateComponent (org.eclipse.che.ide.api.component.StateComponent)2 EditorPartStack (org.eclipse.che.ide.api.parts.EditorPartStack)2 Perspective (org.eclipse.che.ide.api.parts.Perspective)2 Before (org.junit.Before)2 ArrayOf (elemental.util.ArrayOf)1