Search in sources :

Example 1 with JsonObject

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

the class EditorAgentImpl method restoreSplit.

private List<Promise<Void>> restoreSplit(JsonObject files, EditorPartStack editorPartStack, Map<EditorPartPresenter, EditorPartStack> activeEditors) {
    JsonObject splitFirst = files.getObject("SPLIT_FIRST");
    String direction = files.getString("DIRECTION");
    double size = files.getNumber("SIZE");
    EditorPartStack split = editorMultiPartStack.split(editorPartStack, new Constraints(Direction.valueOf(direction), null), size);
    List<Promise<Void>> restoreFirst = restore(splitFirst, editorPartStack, activeEditors);
    JsonObject splitSecond = files.getObject("SPLIT_SECOND");
    List<Promise<Void>> restoreSecond = restore(splitSecond, split, activeEditors);
    List<Promise<Void>> result = new ArrayList<>();
    result.addAll(restoreFirst);
    result.addAll(restoreSecond);
    return result;
}
Also used : Promise(org.eclipse.che.api.promises.client.Promise) Constraints(org.eclipse.che.ide.api.constraints.Constraints) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) JsonObject(elemental.json.JsonObject) EditorPartStack(org.eclipse.che.ide.api.parts.EditorPartStack)

Example 2 with JsonObject

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

the class WorkspacePresenter method loadState.

@Override
public void loadState(JsonObject state) {
    if (state.hasKey("perspectives")) {
        JsonObject perspectives = state.getObject("perspectives");
        Map<String, Perspective> perspectiveMap = perspectiveManagerProvider.get().getPerspectives();
        for (String key : perspectives.keys()) {
            if (perspectiveMap.containsKey(key)) {
                perspectiveMap.get(key).loadState(perspectives.getObject(key));
            }
        }
    }
}
Also used : Perspective(org.eclipse.che.ide.api.parts.Perspective) JsonObject(elemental.json.JsonObject)

Example 3 with JsonObject

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

the class WorkspacePresenter method getState.

@Override
public JsonObject getState() {
    JsonObject state = Json.createObject();
    JsonObject perspectivesJs = Json.createObject();
    state.put("perspectives", perspectivesJs);
    Map<String, Perspective> perspectives = perspectiveManagerProvider.get().getPerspectives();
    for (Map.Entry<String, Perspective> entry : perspectives.entrySet()) {
        //store only default perspective
        if (entry.getKey().equals(defaultPerspectiveId)) {
            perspectivesJs.put(entry.getKey(), entry.getValue().getState());
        }
    }
    return state;
}
Also used : Perspective(org.eclipse.che.ide.api.parts.Perspective) JsonObject(elemental.json.JsonObject) Map(java.util.Map)

Example 4 with JsonObject

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

the class AppStateManagerTest method shouldSaveStateInFile.

@Test
public void shouldSaveStateInFile() throws Exception {
    JsonObject object = Json.createObject();
    object.put("key1", "value1");
    when(component1.getState()).thenReturn(object);
    appStateManager.persistWorkspaceState(WS_ID);
    verify(component1).getState();
    verify(preferencesManager).setValue(anyString(), jsonArgumentCaptor.capture());
    assertThat(jsonArgumentCaptor.getValue()).isNotNull().isNotEmpty();
    String value = jsonArgumentCaptor.getValue();
    JsonObject jsonObject = Json.parse(value).getObject(WS_ID);
    JsonObject workspace = jsonObject.getObject("workspace");
    assertThat(workspace).isNotNull();
    JsonObject jsonObject1 = workspace.getObject("component1");
    assertThat(jsonObject1.jsEquals(object)).isTrue();
}
Also used : JsonObject(elemental.json.JsonObject) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 5 with JsonObject

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

the class AppStateManagerTest method restoreShouldCallLoadState.

@Test
public void restoreShouldCallLoadState() throws Exception {
    JsonObject ws = Json.createObject();
    pref.put(WS_ID, ws);
    JsonObject workspace = Json.createObject();
    ws.put("workspace", workspace);
    JsonObject comp1 = Json.createObject();
    workspace.put("component1", comp1);
    comp1.put("key1", "value1");
    appStateManager.restoreWorkspaceState(WS_ID);
    ArgumentCaptor<JsonObject> stateCaptor = ArgumentCaptor.forClass(JsonObject.class);
    verify(component1).loadState(stateCaptor.capture());
    JsonObject jsonObject = stateCaptor.getValue();
    assertThat(jsonObject.hasKey("key1")).isTrue();
    assertThat(jsonObject.getString("key1")).isEqualTo("value1");
}
Also used : JsonObject(elemental.json.JsonObject) Test(org.junit.Test)

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