Search in sources :

Example 46 with JsonObject

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

the class AppStateManager method restoreState.

private void restoreState(JsonObject settings) {
    try {
        if (settings.hasKey(WORKSPACE)) {
            JsonObject workspace = settings.getObject(WORKSPACE);
            for (String key : workspace.keys()) {
                if (persistenceComponents.containsKey(key)) {
                    StateComponent component = persistenceComponents.get(key);
                    component.loadState(workspace.getObject(key));
                }
            }
        }
    } catch (JsonException e) {
        Log.error(getClass(), e);
    }
}
Also used : JsonException(elemental.json.JsonException) JsonObject(elemental.json.JsonObject) StateComponent(org.eclipse.che.ide.api.component.StateComponent)

Example 47 with JsonObject

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

the class AppStateManager method persistWorkspaceState.

public Promise<Void> persistWorkspaceState(String wsId) {
    final JsonObject settings = Json.createObject();
    JsonObject workspace = Json.createObject();
    settings.put(WORKSPACE, workspace);
    for (Map.Entry<String, StateComponent> entry : persistenceComponents.entrySet()) {
        try {
            String key = entry.getKey();
            workspace.put(key, entry.getValue().getState());
        } catch (Exception e) {
            Log.error(getClass(), e);
        }
    }
    allWsState.put(wsId, settings);
    return writeStateToPreferences(allWsState);
}
Also used : JsonObject(elemental.json.JsonObject) Map(java.util.Map) StateComponent(org.eclipse.che.ide.api.component.StateComponent) OperationException(org.eclipse.che.api.promises.client.OperationException) JsonException(elemental.json.JsonException)

Example 48 with JsonObject

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

the class AbstractPerspective method loadState.

@Override
public void loadState(@NotNull JsonObject state) {
    if (state.hasKey("PART_STACKS")) {
        JsonObject part_stacks = state.getObject("PART_STACKS");
        for (String partStackType : part_stacks.keys()) {
            JsonObject partStack = part_stacks.getObject(partStackType);
            switch(PartStackType.valueOf(partStackType)) {
                case INFORMATION:
                    restorePartController(partStacks.get(INFORMATION), belowPartController, partStack);
                    break;
                case NAVIGATION:
                    restorePartController(partStacks.get(NAVIGATION), leftPartController, partStack);
                    break;
                case TOOLING:
                    restorePartController(partStacks.get(TOOLING), rightPartController, partStack);
                    break;
            }
        }
    }
    if (state.hasKey("ACTIVE_PART")) {
        String activePart = state.getString("ACTIVE_PART");
        Provider<PartPresenter> provider = dynaProvider.getProvider(activePart);
        if (provider != null) {
            setActivePart(provider.get());
        }
    }
}
Also used : JsonObject(elemental.json.JsonObject) PartPresenter(org.eclipse.che.ide.api.parts.PartPresenter)

Example 49 with JsonObject

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

the class JsonRpcResultTest method shouldToStringWhenParsingStringWithResultAsASingleVoid.

@Test
public void shouldToStringWhenParsingStringWithResultAsASingleVoid() throws Exception {
    JsonObject value = jsonFactory.createObject();
    String expected = value.toString();
    JsonRpcResult jsonRpcResult = new JsonRpcResult(value.toJson(), jsonFactory, dtoFactory);
    String actual = jsonRpcResult.toString();
    assertEquals(expected, actual);
}
Also used : JsonObject(elemental.json.JsonObject) JsonString(elemental.json.JsonString) Test(org.junit.Test)

Example 50 with JsonObject

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

the class JsonRpcResultTest method shouldToStringWhenPassingParametersWithResultAsASingleVoid.

@Test
public void shouldToStringWhenPassingParametersWithResultAsASingleVoid() throws Exception {
    JsonObject value = jsonFactory.createObject();
    String expected = value.toString();
    JsonRpcResult jsonRpcResult = new JsonRpcResult(null, dtoFactory, jsonFactory);
    String actual = jsonRpcResult.toString();
    assertEquals(expected, actual);
}
Also used : JsonObject(elemental.json.JsonObject) JsonString(elemental.json.JsonString) 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