Search in sources :

Example 41 with JsonArray

use of elemental.json.JsonArray in project che by eclipse.

the class JsonRpcListTest method shouldToJsonArrayParsedBooleanArray.

@Test
public void shouldToJsonArrayParsedBooleanArray() throws Exception {
    Boolean expected = false;
    JsonArray array = jsonFactory.createArray();
    array.set(0, expected);
    String message = array.toJson();
    JsonRpcList jsonRpcList = new JsonRpcList(message, jsonFactory, dtoFactory);
    JsonArray actual = jsonRpcList.toJsonArray();
    assertTrue(array.jsEquals(actual));
}
Also used : JsonArray(elemental.json.JsonArray) Test(org.junit.Test)

Example 42 with JsonArray

use of elemental.json.JsonArray in project che by eclipse.

the class JsonRpcListTest method shouldToStringifiedListParsedBooleanArray.

@Test
public void shouldToStringifiedListParsedBooleanArray() throws Exception {
    Boolean expected = false;
    JsonArray array = jsonFactory.createArray();
    array.set(0, expected);
    String message = array.toJson();
    JsonRpcList jsonRpcList = new JsonRpcList(message, jsonFactory, dtoFactory);
    List<String> actual = jsonRpcList.toStringifiedList();
    assertEquals(expected, Boolean.valueOf(actual.iterator().next()));
}
Also used : JsonArray(elemental.json.JsonArray) Test(org.junit.Test)

Example 43 with JsonArray

use of elemental.json.JsonArray in project che by eclipse.

the class JsonRpcListTest method shouldToJsonArrayParsedNumberArray.

@Test
public void shouldToJsonArrayParsedNumberArray() throws Exception {
    Double expected = 0D;
    JsonArray array = jsonFactory.createArray();
    array.set(0, expected);
    String message = array.toJson();
    JsonRpcList jsonRpcList = new JsonRpcList(message, jsonFactory, dtoFactory);
    JsonArray actual = jsonRpcList.toJsonArray();
    assertTrue(array.jsEquals(actual));
}
Also used : JsonArray(elemental.json.JsonArray) Test(org.junit.Test)

Example 44 with JsonArray

use of elemental.json.JsonArray 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 45 with JsonArray

use of elemental.json.JsonArray 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

JsonArray (elemental.json.JsonArray)69 Test (org.junit.Test)62 JsonValue (elemental.json.JsonValue)23 JsonString (elemental.json.JsonString)19 JsonObject (elemental.json.JsonObject)14 Matchers.anyString (org.mockito.Matchers.anyString)10 JsonNumber (elemental.json.JsonNumber)5 PartPresenter (org.eclipse.che.ide.api.parts.PartPresenter)4 ArrayList (java.util.ArrayList)3 List (java.util.List)2 Node (org.eclipse.che.ide.api.data.tree.Node)2 ResourceNode (org.eclipse.che.ide.resources.tree.ResourceNode)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 Promise (org.eclipse.che.api.promises.client.Promise)1 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)1 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)1 Path (org.eclipse.che.ide.resource.Path)1 MessageLoader (org.eclipse.che.ide.ui.loaders.request.MessageLoader)1 Ignore (org.junit.Ignore)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1